A couple of days ago, Google released the Android 4.4 KitKat factory images for the Nexus 4, 7 (2012/2013) and the Nexus 10. The factory images were already available for download on the day the device went up for sale on the Play Store. Factory images are a great way of completely resetting your Nexus device and putting them back to stock.
If you have rooted, flashed a custom ROM on your Nexus device but now want to go back to complete stock, simply follow the steps below. Do note that the below steps will completely wipe your Nexus of any data, so make backups. Also, you will need to have an unlocked bootloader to flash the factory image.
Step 1: Download the ADB/Fastboot files and the USB drivers for Windows based PC first. The the latest factory image for your Nexus device can be downloaded directly from Google’s website.
Extract the contents of the ADB/Fastboot ZIP file inside a new folder called ‘google’ on your desktop. Extract and transfer the contents of the factory image inside this folder as well. The list of files will include a ZIP file containing the codename of your Android device, two files with “flash-all” names, and a bootloader image file. All the extracted contents of the factory image should be inside the same folder as the ADB and Fastboot file, otherwise you will get a file not found error.
Make sure to install the ADB drivers as well if you are running a Windows based PC.
Step 2: Now, reboot your Nexus device in bootloader mode. This is usually done by switching off the device, and pressing the Volume down + Volume Up + Power button simultaneously. If that does not work, try the Volume down + Power button combination.
After the device has booted into bootloader mode, connect it to your PC.
Step 3: Open a new Terminal or Command Prompt window, and navigate to the ‘google’ folder that you created in Step 1. Before we start flashing the factory image, we need to make sure that your Nexus device is being detected by the PC.
If you are using a Mac, then you need to prefix a “./” before every Fastboot command. So, the above command will look something like this on a Mac -:
The above command should confirm if your device is indeed being detected by your PC or not. If it is, then proceed to the steps below. If not, repeat the steps above again. Make sure that you have properly installed the drivers and are inside the correct folder.
If you are running Windows, copy-paste the following command in the command prompt window -:
On a Mac, copy-paste the following command -:
The script will then automatically flash the full factory image on your Nexus device. Once the factory image has been flashed, your device will automatically reboot. Keep in mind that the first boot might take some time so please be patient.
If the flash-all.sh script gives you a fastboot not found error on your Mac, open up the file in Text Edit and add a “./” before every fastboot command.
The flash-all script included in the factory image might not work for all. It has always been pretty unreliable and has only worked once for me in the last 2 years. If you are in the same boat as me, you will have to flash each partition manually on your device. This is slightly cumbersome though.
The command to manually flash a partition via fastboot is “fastboot flash partition filename.img”. In the factory image that you extracted in Step 1, you will notice there is another ZIP file. Extract the contents of that ZIP file inside the ‘google’ folder.
Now, its time to manually flash the partitions to your Nexus device. We will first begin with the bootloader.
fastboot flash bootloader filename.img
Then, we will flash all other partitions. They don’t necessarily need to be in the same order as I have listed them below. The names of the image files in the factory image will clearly indicate the partition they are intended for as well.
fastboot flash boot filename.img
fastboot flash radio filename.img
fastboot flash recovery filename.img
fastboot flash userdata filename.img
fastboot flash system filename.img
If you want to relock the bootloader of your device after flashing the device, put the device back in fastboot mode. Then type in the following command in the Terminal or Command Window you had opened earlier -:
fastboot oem lock
This will re-lock the bootloader of your Nexus device, restoring your warranty and putting the device back to complete stock.
Update: You can find the steps to flash the Android 6.0 Marshmallow factory image on your Nexus 5, Nexus 6, Nexus 7, and Nexus 9 here.