How to flash factory image on any Nexus device to return to stock

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.

factory

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.

fastboot devices

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 -:

./fastboot devices

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.

fastboot_flas

If you are running Windows, copy-paste the following command in the command prompt window -:

flash-all.bat

On a Mac, copy-paste the following command -:

./flash-all.sh

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.

facory_image

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.

Like this post? Share it!

Categories: How To

  • Josh Sevigny

    I am trying to do a clean install of Android 4.4 on a 2013 nexus 7 wifi model. Is there not an easier way to do a “clean install”? I have tried seemingly everything. By the way I am using a Mac.

    When I run ./flash-all.sh It says something like line 18 fastboot command not found.

    I have tried troubleshooting this for hours

    Thanks in advance.

    • Rajesh

      Ah. The flash-all script fails to work sometimes. You will need to extract all the image files from the ZIP file in the factory image, and then flash manually. This will be a bit tedious though.

      Make sure fastboot file is inside the same folder as the factory image files. I will update the guide in a few hours and include the steps to manually flash each partition.

      • Josh Sevigny

        Wow that was a fast response! Thanks so much!

        • Antonio Giammalvo

          i’m having the same problem with my nexus 4… help!!!

          • Josh

            Rajesh updated the guide. I haven’t tried it yet, but it looks promising.

          • sunil

            I am having nexus 7 wifi model and stuck at the black screen with Google..How much I should wait…?

          • SHASHIDHAR GA

            Hi,
            I’ve updated my Nexus 7 (2013) to Kitkat 4.4.2. I noticed slow loading of webpages. So now I want to restore to my factory image of Jelly Bean 4.3. My Nexus is 2013 edition LTE unlocked. Shall I follow the above procedure. Is it necessary to relock the bootloader after flashing.

          • rash

            try editing the file and put ./ before each fastboot command in flash-all.sh for mac os. works for me

          • AlRegals

            That gave me No such file or directory

      • Josh

        That worked great!!! Clean start on KitKat!!!! I love learning new stuff like that.

        Thanks!

    • Rajesh

      Updated the guide. You can flash the factory image manually now.

      • Josh

        Great! Thank you! I will try again later this evening.

  • http://www.friv2friv3friv4.com/ friv 2 friv 3 friv 4

    Wow that was a fast response! Thanks so much!

  • p.menziesii

    It should be noted perhaps more strenuously: locking/unlocking the bootloader will wipe the sd card of the Nexus device. Additionally, flashing the userdata partition will aslo erase the sd card. It was mentioned in the article, but it’s a detail that could be quite easily missed by some folks. In the past, it has been entirely possible to flash back to stock without flashing the userdata partition, and if your device bootloader is already unlocked, there’s no real reason to re-lock it.

    • Rajesh

      If you want to go back to complete stock, like the way your device shipped from Google, re-locking the bootloader is neccessary. Also, for warranty claims.

  • matt

    Another thing to watch out for… depending on how you got into the situation, you may need to clear the cache before it will boot. In my case, [fastboot erase cache] was not good enough… had to boot into the stock recovery console and select from the menu. After that, first boot was successful after a minute or two. Previously, waited 10+ minutes (several times) with no successful boot.

    This was on a Nexus 4

    • Luis Paredes

      Mine is taking more than 15 minutes and doesn’t boot. Can you please be more specific on how to clear the cache?
      Thanks

    • Mara

      Hi Matt, I am having your same issue here. Keep loading and not boot. How did you ” boot into the stock recovery console and select from the menu” can you please guide me here, I am a newbie. Cheers

    • Matt

      Hi Mara and Luis,

      Once you have done the [fastboot flash recovery filename.img] you will have the stock recovery console, rather than something like TWRP (which you might have if you’ve ever rooted your phone.) To get to it, boot into the bootloader menu (as in Step 2 above,) and select the Recover Console. When it loads you will see an image that looks like a robot with its front cover over. You can open the menu from here with Power + Volume Up; there will be an option to clear the cache. Worked for me. Good luck!

      • patrissimo

        Note: I had the same problem, I cleared the cache w/ your instructins, and it didn’t help. I tried 4.4 and 4.3, only difference is whether the boot screen it gets stuck on is an X (4.3) or 4 colored balls (4.4).

        What worked was doing a factory data reset from the same menu as clearing the cache.

  • ProbablyHittingOnYou

    After trying to sideload forever, this worked. Thanks!!

  • Parvath

    Good one Rajesh. May be you can also add that USB debugging needs to be enabled.

  • JIns

    Manual flashing worked fine! Thx a lot man!

  • ChrisT

    I have a problem….bootloader image cannot be installed ….device product is mako, update requires tilapia ?! what should I do ?!

  • Ran Shalmir

    Thanks!! Manged to fix my Nexus 7 after the 4.4 updated failed and it would stay stuck on the boot screen :)

  • Akeel

    I’ve followed the steps to manually flash on my Nexus 5. All the factory images loaded completely. But i the phone will not load now. I keep getting the “4 circles spinning” sign. Do i need to load the cache file as well?

  • Edmund Palmer

    Follows ur instructions to the t and now my 32 GB shows up as 16 GB. Any ideas?

    • newbee

      i ‘ve read somewhere you need to “restore to factory default” in your settings…afterwards maybe everything is ok again?

  • http://aligh.pro/ Ali

    first of all thanks for guid
    but I got into some problems and I would be appreciated if you help me to solve theme
    I have nexus 10, so I downloaded “4.4.2 (KOT49H)” from google but I don’t have “radio” image file, and I don’t know what should I do for these comments
    “””fastboot flash radio filename.img”””
    is it ok?

    • psyck

      you dont need the radio image if your device is just a wland device and has no umts built.
      worked for me perfectly on my nexus7

      fastboot flash bootloader
      fastboot reboot-bootloader
      fastboot flash system
      fastboot flash boot
      fastboot flash userdata
      fastboot reboot

  • Derrick Crasta

    Excellent worked for me, Thanks a million

  • hilmi

    i tried all the step above on for nxs4 on Mac, but failed.
    i cannot manually flash the partition.
    all the partition

  • AQNRUIZ

    I downloaded the fastboot/adb and I do not have the flash-all.bat file in there help please. also my stock image is a .tgz file and i cannot see any files within to able to extract. there is no zip file. when i extracted it the file became a .tar file. What am I doing wrong?

    • Jeff Jacob

      A tar file is like a zip file but with no compression. Use 7zip to extract it.

  • Biggie

    finally ur method of using flash.bat works. my nexus 10 is fully working nw

  • Manuk

    THANK YOU SO MATCH!!!!!!!!!! It helps me Nexus 7 first generation.

  • HuShifang

    This procedure worked great for me. My Nexus 10 (unrooted, running stock 4.4.2) could only enter the bootloader – when I tried to get into recovery mode or boot regularly, it would get stuck on the “Google” screen. Using ADB and Fastboot 1.1 (downloaded from XDA) and following this procedure, I first flashed the cache partition; this got me to the “spotlight” boot screen, though not past it. When I used the flash-all.bat command, it worked like a charm, and my device was once again fully operational. (One thing not mentioned here – you can use ADB and Fastboot 1.1 to unlock your bootloader using the command “fastboot oem unlock”; ADB will actually prompt you to do this if you try flashing before unlocking.)

  • Christopher Ohlsen

    This worked for me. Flash-all did not work but individually flashing each partition manually did. Soft Bricked Nexus 10 on unroot (Wanted newest update 4.4.2) attempt with faulty cable. Got new cable, followed instructions, and Voila:) Thanks!

  • Adrian

    Managed to recover a friend’s Nexus 7 using this guide. Many thanks!

  • tomtom

    Sorry but your package download link gives me a dropbox warning. Do you have an alternate dl for me? Thanks

  • Bryan Vazquez

    If you are on a Mac, edit the flash-all.sh. Inside there will be some commands:

    fastboot flash bootloader bootloader-flo-flo-04.02.img

    fastboot reboot-bootloader

    sleep 5

    fastboot -w update image-razor-kot49h.zip

    Edit them, so they look like this.

    ./fastboot flash bootloader bootloader-flo-flo-04.02.img

    ./fastboot reboot-bootloader

    sleep 5

    ./fastboot -w update image-razor-kot49h.zip

    Now, on the command app, try the ./flash-all.sh

    It should be working!!!

  • reframmellator

    First “definitive” guide I found (and I tried more thanm 10) that got me around a balky USB handshake, showed me how to flash manually, and restored my soft bricked CM modded Nexus 7 2013 to pristine newness. Others leave stuff out. Yours is step-by-step, everything needed and nothing unnecessary. Many, many thanks!

    • http://www.symbian-guru.com khouryrt

      You’re welcome :D

  • SUNNY SOMYANI

    BEST EVER EXPLAINATION DUDE KEEP IT UP IT WAS SO EASY TO GET IT AND WAS VERY HELPFUL FLASHED MY GF NEXUS 4 ;) VERY EASILY ND WITHOUT ANY PROBLEM

    EVERYBUDY PLZ JUST BE CALM AND DO WHAT THIS EXPLAINATION SAYS YOU WILL SUCESSULLY FLASH IT WITHOUT ANY HESITAIONS

    KEEP IT UP BRO

    • John Mason

      Buddy, it does not work for everyone, the first time i tried to fix it, it took me 11 days and idk how many sites i went through. it is a great post but it might not work for everyone

  • John Mason

    For anyone who is having problems visit this site: http://www.googlenexusforum.com/forum/nexus-7-hacking-mods/747-how-manually-unbrick-restore-your-nexus-7-s-factory-state-windows.html

    I did not need that site because i did it before. Here’s what to do:

    – Downloaded the file N7_restore.zip file before, now the link doesn’t work so i’ll upload it somewhere soon and give the link.

    https://dl.google.com/dl/android/aosp/nakasi-jwr66v-factory-d341d356.tgz
    ^ Should be the replacment if not please inform me

    – Then extract the zip file you just downloaded and in that folder there is another zip called image-nakasi-jrn84d

    – Extract that zip and Copy all the files in the newly extracted folder to the N7_restore folder

    – in the N7_restore folder open a cmd by pressing shift and right clicking together and then clicking open command window here

    – Then type/copy without the quotes “fastboot flash bootloader bootloader-grouper-3.34.img”

    Do not go to the next step until it says the flashing is successful or it will be a waste of time.

    – Next type/copy without the quotes “fastboot flash boot boot.img”

    – Next type/copy without the quotes “fastboot flash recovery recovery.img”

    – Next type/copy without the quotes “fastboot flash userdata userdata.img”

    – Next type/copy without the quotes “fastboot flash system system.img”

    If you want to Lock the bootloader

    – type/copy without the quotes “fastboot oem lock”
    That’s it. It worked for me twice and should work for you

    P:S: The direct link to the image i put above is not the original but a substitute i will try to give you the original one asap.

  • Mikey

    This was awesome!! Just used it to install 4.4.3 on my Nexus 5!!

  • AlRegals

    the flash-all.sh didn’t work so I tried the next method and I’m stuck on the first step. Keeps telling me it can’t open the bootloader file and I don’t know why.

  • jay

    worked for me! refer to brian vazquez’s comment if you are using mac, that stuff is not in the guide

  • Ro0dman

    I download the 4.4.3 Factory Imag from the Google site and fully extract it however, I do not get the.img files that you have in this article

  • Corey

    Thank you so much for this! I could not figure out how to get it installed, and I realized (after reading your article) that I had to install each .img file one, by one. My Nexus 5 is booting up now. THANK YOU!

  • krash

    ried and got
    failed to allocate 699970328 bytes
    error : update package missing system.img

    • krash

      tried

  • BillyBalowski

    Thank you very much for this. I stupidly deleted my OS while attempting to flash a custom ROM before loading the new OS onto the internal SD card of my Nexus 10. I was almost certain I had killed my tablet. After a few hours of trying everything I could, this helped me get back up and running. Cheers to you!

  • benny

    I was totally desperate. Thanks for this easy free guide, top.