Back on Halloween, Google promised that proprietary binaries and factory images for the Nexus 4, Nexus 7, and Nexus 10 would arrive shortly after devices received their OTA updates. Even though some OTAs haven't even rolled out yet, as of a few minutes ago, all modern Nexus devices now have Android 4.4 KRT16O factory images and drivers available for download.
This means you can flash stock Android 4.4 onto any supported device, even if an OTA either wasn't available yet or wouldn't work for some reason. The availability of binaries/drivers, on the other hand, is great news for custom ROMs.
Note #1: If your bootloader is locked, your data will be wiped for security reasons - there's no way around that. You will want to back up what you want manually.
Note #2: If your bootloader is already unlocked, you have the option of skipping the data wipe during the factory image flashing procedure. In some situations, not wiping user data may prevent the device from booting, in which case you'd probably need to go ahead with the wipe, but for simple OS upgrades from one version of stock Android to another one higher, wiping data should not be necessary.
Prerequisites
In order to complete the steps below, you need to have the Android SDK installed. The SDK contains the latest version of adb and fastboot, which you will need for flashing files and issuing commands. You will also need a MicroUSB cable to execute adb sideload, fastboot flash, and other commands. You also need to unlock your bootloader - a process that wipes your data.
Enable Developer options by going to the Settings -> About screen and tapping Build number until the OS unlocks the hidden Developer options menu. Now go to Developer options and make sure you have USB debugging turned on. For security purposes, you can turn it off after we're done.
To unlock the bootloader, if you haven't already done so:
- Reboot into the bootloader by issuing an adb reboot bootloader command on your computer or using the correct combination of buttons applicable to your device.
- Warning: This will wipe your data. Type in fastboot oem unlock on your computer. Agree to the unlock by selecting Yes on your device (VolUp, then Power).
- You have now unlocked your bootloader (and the data partition was wiped clean). Verify by rebooting to the bootloader again and looking at Lock State.
Instructions
- Download the full factory image corresponding to your exact model (for example, 2013 Nexus 7 Wi-Fi is razor), which includes the full system, bootloader, recovery, kernel (boot.img), and radio (radio not included for Wi-Fi-only variants). It's a clean slate for these components - they'll flash cleanly over anything you have now.
- Unpack the tgz (tar/gz) archive into its own directory. I use Total Commander, but you can use any tool that reads gz and tar, like 7-Zip.
- Proceed with this step if you want to keep your data intact. If you skip this step, your data will be wiped. With your favorite text editor, edit (be careful not to run it by accident instead of editing) flash-all.bat (if you're on Windows) or flash-all.sh (Mac, Linux) and:a) remove "-w" from the fastboot update command. For example, if the line reads fastboot -w update image-razor-jss15j.zip, it should now read fastboot update image-razor-jss15j.zip. The -w option instructs fastboot to wipe data.b) remove any mentions of fastboot erase userdata if you see any. Oddly, some factory image scripts, like the one for nakasi, wipe each partition manually first. You don't want to lose userdata.
- Reboot into the bootloader and run the appropriate flash-all script.
That's it, you're done.
Note: The above procedure restored the factory recovery, so if you want a custom one, you can flash one now (see below).
For better security, you can relock the bootloader by issuing fastboot oem lock while booted to the bootloader. This will, however, mean that if you ever want to do anything that requires an unlocked bootloader, you will lose your data in the unlock process.
Rooting
Rooting your Nexus device is very easy. It requires an unlocked bootloader and a custom recovery. I recommend using TWRP.
- Flash TWRP from here (Reboot into the bootloader as before and then fastboot flash recovery FILENAME.img).
- Reboot into recovery (adb reboot recovery).
- Flash SuperSU. To do that, download the zip, then put the recovery into adb sideload mode (in TWRP, it's under Advanced), and then do adb sideload FILENAME.zip.
- You should be rooted.
- Reboot, head to the Play Store, and update SuperSU.