[TUTORIAL] How to flash a factory image | Return to stock | Unroot/SAVE your Nexus 5

Search This thread

abaaaabbbb63

Senior Member
Nov 19, 2011
3,895
3,426
Somewhere Over The Rainbow
Yeah, there is, and I still have this problem that is not addressed by the rooting thread. I walked through the tutorial, but it does not account for phones with this error, only phones that are functioning in recovery mode.

That's not an error. That's the stock recovery.

Unlock the bootloader (if not unlocked) , and use fastboot to flash a custom recovery image through fastboot using this command:
fastboot flash recovery recovery.img
 

leoncheong

Member
Jan 11, 2013
21
0
I think for method 2, after
Code:
fastboot erase cache

you need

Code:
fastboot flash cache cache.img

Is there a way to do factory reset without wipping SDcard?
 

Seadra

Senior Member
Aug 18, 2013
1,074
209
32
Ok followed your guide and everything went soo smoothly. Thanks soooo much dude.

2 Things I am not able to understand. But it's kinda a long story (not so long)

Started with chainfire's root/unlock boodloader. Then I flashed CM 11. Then I flashed Franko's Kernal. And main purpose for that was to change the screen's colors and I did. I loved it all. I installed the aviate launcher as well and kept a wallpaper. Have fun. Now I thought, let's see if I can manage to get everything back to where it was. Followed your guide very carefully and with no problems at all, everything went smoothly. Now when I started using the phone , I noticed 2 things like I mentioned above , 1st aviate was installed (I didn't install anything) and 2nd My wallpaper was set up the same which I had when I installed the franko's kernal. How is that possible? I did flash the stock images you provided(the google's links). Am I missing anything? I did recheck to see if tamper flag thing was right or not and it was flase, so I guess I did everything right. How come I had the same wallpaper and avaite installed already?

sorry, if I am kinda being confused here.

edit: one more app found which was already installed: whatsapp. wow.
 
Last edited:

jd1639

Inactive Recognized Contributor
Sep 21, 2012
16,833
5,404
Minnesota
Ok followed your guide and everything went soo smoothly. Thanks soooo much dude.

2 Things I am not able to understand. But it's kinda a long story (not so long)

Started with chainfire's root/unlock boodloader. Then I flashed CM 11. Then I flashed Franko's Kernal. And main purpose for that was to change the screen's colors and I did. I loved it all. I installed the aviate launcher as well and kept a wallpaper. Have fun. Now I thought, let's see if I can manage to get everything back to where it was. Followed your guide very carefully and with no problems at all, everything went smoothly. Now when I started using the phone , I noticed 2 things like I mentioned above , 1st aviate was installed (I didn't install anything) and 2nd My wallpaper was set up the same which I had when I installed the franko's kernal. How is that possible? I did flash the stock images you provided(the google's links). Am I missing anything? I did recheck to see if tamper flag thing was right or not and it was flase, so I guess I did everything right. How come I had the same wallpaper and avaite installed already?

sorry, if I am kinda being confused here.

edit: one more app found which was already installed: whatsapp. wow.

You probably had your phone backed up to Google and when you set up your Google account it restored those.
 

Oneireus

Member
Jan 18, 2014
19
1
Whenever I run flash-all.bat, it hangs on erasing Userdata. Like a good 5 to 10 minutes and nothing happens. Any idea how to proceed?
 

samersh72

Senior Member
Nov 26, 2012
3,572
7,472
51
GB
meettomy.site
I did it, and Writing System began to hang.

erase system, recovery, cache, userdata, boot before flashing
Code:
fastboot erase boot
fastboot erase cache
fastboot erase recovery
fastboot erase system
fastboot erase userdata
fastboot reboot-bootloader
then re-flash all stock images (method 2)
i suggest also to change usb port, cable
 

Oneireus

Member
Jan 18, 2014
19
1
erase system, recovery, cache, userdata, boot before flashing
Code:
fastboot erase boot
fastboot erase cache
fastboot erase recovery
fastboot erase system
fastboot erase userdata
fastboot reboot-bootloader
then re-flash all stock images (method 2)
i suggest also to change usb port, cable

erasing hangs on system. Everything else flashed and erased fine. This is a newer cable that detects the device. My other didn't. I am not sure how else to make that better.

EDIT - I changed the port. System erased, and now userdata hangs. This is frustrating.
EDIT 2 - Got the parts to erase. Still hangs on writing.
EDIT 3 - Changing ports got it to work. Thanks for the tip. Back to stock.
EDIT 4 - New issue: On reboot, it goes to the "Welcome" screen. When if I press the next arrow, it changes screens, then freezes and reboots. If I press nothing, it just freezes and reboots. Any ideas? I did a data and cache wipe, and that didn't help the problem.
 
Last edited:

samersh72

Senior Member
Nov 26, 2012
3,572
7,472
51
GB
meettomy.site
erasing hangs on system. Everything else flashed and erased fine. This is a newer cable that detects the device. My other didn't. I am not sure how else to make that better.

EDIT - I changed the port. System erased, and now userdata hangs. This is frustrating.
EDIT 2 - Got the parts to erase. Still hangs on writing.
device is fine
im pretty sure that the problem is with usb cable or pc
 

Oneireus

Member
Jan 18, 2014
19
1
device is fine
im pretty sure that the problem is with usb cable or pc

Added in two more edits. Here they are:

EDIT 3 - Changing ports got it to work. Thanks for the tip. Back to stock.
EDIT 4 - New issue: On reboot, it goes to the "Welcome" screen. When if I press the next arrow, it changes screens, then freezes and reboots. If I press nothing, it just freezes and reboots. Any ideas? I did a data and cache wipe, and that didn't help the problem.

I am stuck on Edit 4. Phone is off for now, but I get to the "Just wait a sec" loading screen, then reboot.
 

samersh72

Senior Member
Nov 26, 2012
3,572
7,472
51
GB
meettomy.site
Added in two more edits. Here they are:

EDIT 3 - Changing ports got it to work. Thanks for the tip. Back to stock.
EDIT 4 - New issue: On reboot, it goes to the "Welcome" screen. When if I press the next arrow, it changes screens, then freezes and reboots. If I press nothing, it just freezes and reboots. Any ideas? I did a data and cache wipe, and that didn't help the problem.

I am stuck on Edit 4. Phone is off for now, but I get to the "Just wait a sec" loading screen, then reboot.

hmmmm... try to reflash stock.
flash all stock images including "fastboot flash cache cache.img"
after finishing, boot directly from fastboot to recovery and wipe data and cache, reboot.
if not, i guess it is a hardware failure
 

Oneireus

Member
Jan 18, 2014
19
1
hmmmm... try to reflash stock.
flash all stock images including "fastboot flash cache cache.img"
after finishing, boot directly from fastboot to recovery and wipe data and cache, reboot.
if not, i guess it is a hardware failure

This did it. Thanks. Fully back to working stock. Unfortunately, that didn't fix my SIM card issue as T-Mobile suggested. Oh well.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 455
    How to flash a factory image | Return to stock | Unroot your Nexus 5​




    Hello Nexus 5 Users!

    I see many users that don't know how to restore their Nexus 5 to stock. It may come in handy, either when you want to RMA your phone, or you want to fix your mistakes.

    This process consists of wiping and flashing every partition on your phone.



    Post-Divider-LG.jpg

    WARNING!!!

    This process will wipe your phone completely. Backup your storage before you continue.
    I am also not responsible if anything goes wrong.
    You can backup apps and data using this app before you unlock the bootloader. No root required.
    https://play.google.com/store/apps/details?id=com.koushikdutta.backup

    DO NOT USE TOOLKITS!!!
    They have a high probability of something going wrong if you don't know how to use them (which, if you managed to ruin your phone, probably is true).
    I don't mean to offend toolkit creators. They did a great job. But don't risk bricking your phone just because you're lazy.

    FOLLOW EVERY SINGLE STEP
    or you will end up in a bootloop, or with a bricked phone, and we don't want that

    Let's get started!!



    Post-Divider-LG.jpg

    Setting up



    For this process, you will need to:

    Install adb and fastboot drivers. To do this, use this simple program:
    http://xdaforums.com/showthread.php?t=2588979

    For MAC users:
    http://xdaforums.com/showthread.php?t=1917237
    *Note: MAC users will have to write "./" before every command in this thread. For example : "./fastboot flash recovery recovery.img"

    Linux users should know their stuff :D
    http://xdaforums.com/showthread.php?t=921169

    Download the latest factory images from here:
    https://developers.google.com/android/nexus/images#hammerhead

    ★Extract the archive you downloaded (Use WinRAR). It should look like this:
    Untitled.png


    ★Unlock your bootloader (In case you haven't already)
    http://xdaforums.com/showthread.php?t=2507905







    Post-Divider-LG.jpg

    Flashing the factory images



    There is more than one way to flash these images. Each give the same results, but the first is for lazy users :D

    Method 1. Easy method.

    ★Power off your phone.

    ★Boot it in fastboot by pressing and holding Power Button + Volume Down at the same time.

    ★Connect your phone to your PC through your USB cable.

    ★Execute the flash-all.bat script (for Windows) or flash-all.sh(for MAC and LINUX) in the folder where you extracted the factory images.
    **!!** For MAC: You'll have to edit the flash-all.sh, and add "./" before every fastboot command.

    ★Wait for everything to flash.

    ★After everything finished, select "Recovery" using the volume buttons.

    ★When a small dead Android appears, press Power Button + Volume UP.

    ★Select "Wipe data/factory data reset"

    ★Reboot. Your phone should be stock. :good:


    Method 2. Long method (Same thing actually, but I'll mention it, just in case)

    ★Extract the image-hammerhead-krt16m.zip somewhere easy to access (On C:\image-hammerhead-krt16m for example). You will have the following files:

    Untitled2.png


    ★In the same folder, from the original archive, extract "bootloader-hammerhead-XXXXXX.img" (rename it to bootloader.img) and "radio-hammerhead-XXXXXX.img" (rename it to radio.img)

    ★Power off your phone.

    ★Boot it in fastboot by pressing and holding Power Button + Volume Down at the same time.

    ★Connect your phone to your PC through your USB cable.

    ★Open a CMD window.

    ★Type the following commands, in this order (If you have a different folder, change the path)
    Code:
    fastboot flash bootloader C:\image-hammerhead-krt16m\bootloader.img
    fastboot reboot-bootloader
    fastboot flash radio C:\image-hammerhead-krt16m\radio.img
    fastboot reboot-bootloader
    fastboot flash system C:\image-hammerhead-krt16m\system.img
    fastboot flash userdata C:\image-hammerhead-krt16m\userdata.img 
    [B](Note: this command will wipe your device (including \sdcard), EVEN if your bootloader is already unlocked.)[/B]
    
    fastboot flash boot C:\image-hammerhead-krt16m\boot.img
    fastboot flash recovery C:\image-hammerhead-krt16m\recovery.img
    fastboot erase cache
    fastboot flash cache C:\androidimage\cache.img
    ★After everything finished, select "Recovery" using the volume buttons.

    ★When a small Android appears, press Power Button + Volume UP.

    ★Select "Wipe data/factory data reset"

    ★Reboot. Your phone should be stock. :good:

    For both methods:
    Optional, but necessary for warranty purposes - Locking your bootloader+ Resetting the tamper flag


    The Nexus 5 has a thing implemented in the bootloader called a tamper flag. This shows if the bootloader was ever unlocked, kind of like the flash counter with Samsung devices. You can check it out by using this command
    Code:
    fastboot oem device-info
    . If the tamper flag value is "true", then you'll have to reset it. The following steps will reset this flag, and lock your bootloader.

    •So, first, go here: http://xdaforums.com/showthread.php?t=2239421 (Thanks @osm0sis for the wonderful script)
    Under "Flashable Zips", you will find the Nexus BootUnlocker script. Download it.

    •Put the zip on your internal storage.

    •Download the latest TWRP recovery image for the Nexus 5 from here: http://techerrata.com/browse/twrp2/hammerhead. Rename it to TWRP.img.
    Now boot it. You do this by booting your phone in fastboot, and typing the following command:
    Code:
    fastboot boot path\to\TWRP.img
    *Replace path\to\TWRP.img with the path to where you placed the TWRP.img. For example: C:\Users\X\Desktop\TWRP.img
    TWRP recovery should boot.

    •When TWRP finished booting, select "Install", then navigate to the Nexus Bootunlocker zip, select and install it. After it finished, use the back arrow at the bottom of the screen to go back, and reboot.

    Now your bootloader should be locked, and your tamper flag should show "false".





    And now you have a brand new Nexus 5 (software wise, at least)




    Post-Divider-LG.jpg

    Video Guides

    Thanks @techfanatic9.


    For Windows:



    For Mac:



    Another easy and fast tutorial made by @iTzGavin96



    These don't contain the tamper flag reset step. Follow the steps above to reset your tamper flag value to "False" for warranty purposes.






    If you now have 12 GB of storage instead of 28 GB, go to post #2
    112
    Post-Divider-LG.jpg

    32 GB phone now shows 16GB?





    This is a common problem with Nexus devices. Minor error, don't panic. Here is how to fix it

    ★Boot into STOCK RECOVERY (If you are running a custom recovery you must flash to stock)
    ★Clear cache
    ★Factory reset

    If that didn't work, proceed with doing this:

    Open a CMD window, boot your phone is fastboot, and write the following commands, in this order (Considering that you have extracted the images in C:\image-hammerhead-krt16m\)
    Code:
    fastboot erase boot
    fastboot erase cache
    fastboot erase recovery
    fastboot erase system
    fastboot erase userdata
    
    fastboot flash bootloader C:\image-hammerhead-krt16m\bootloader.img
    fastboot reboot-bootloader
    fastboot flash radio C:\image-hammerhead-krt16m\radio.img
    fastboot reboot-bootloader
    fastboot flash system C:\image-hammerhead-krt16m\system.img
    fastboot flash userdata C:\image-hammerhead-krt16m\userdata.img 
    (Note: this command will wipe your device (including \sdcard), EVEN if your bootloader is already unlocked.)
    
    fastboot flash boot C:\image-hammerhead-krt16m\boot.img
    fastboot flash recovery C:\image-hammerhead-krt16m\recovery.img
    49
    Post-Divider-LG.jpg

    Credits and Thanks:

    @efrant
    For his thread in the N4 section (http://xdaforums.com/showthread.php?t=2010312)

    @osm0sis
    For contributing a lot with the tamper flag part

    @dombera
    For inspiring me to make this guide

    @Chromium_
    For not replying to my Hangouts messages

    @jd1639
    For helping me out with this thread.

    @Prodeje79
    For pointing problems out.


    7
    OMG! DUDE THANK YOU!! im so noob at this lol:p valuable lesson learned READ INSTRUCTION!

    Your welcome! Have a nice day :D
    6
    Because I don't know better, why do you consider method 2 safer?

    Well, safer in the sense that you are more in control, and can only flash certain images, not all. I'll delete de safe part.





    Is there an easier "hide root" or any way to unroot where AirwatchMDM or other MDM corporate software control crap is hidden?

    I'm wanting to try register on airwatch then lock down airwatch and see if I could still use touchdown.

    If you have root through the "SuperSU" app, it has an unroot option.