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

Search This thread

appuserprime

Member
Jul 6, 2013
6
1
In theory the flash-all.bat should work and reset the phone to a fully functional state. It didn't give any errors, did it? Can you access the stock recovery? Do a factory reset from the recovery, then try to boot again.

You can also try flashing older versions as well (of 6.0.1) or even older versions of Android if nothing else works.

I realize that flashing the wrong bootloader is not common for an experienced user, but I assure you that I am unable to turn the device on. That means no button combos, no fastboot, no recovery, no google logo. The phone was originally hard bricked after I manually flashed and restarted the correct bootloader.

Then I started troubleshooting..

After I started troubleshooting, there were only 2 exceptions where I was able to get to Fastboot with button combos. The first time, I used the opportunity to flash-all on top of my erased boot, cache, system, etc.

That did not fix it so I got lucky a 2nd time and got to fastboot but this time it crashed out of fastboot never to turn on again!

And now that I am trying to use an ODIN like software to do factory flashes my device is not showing up in device manager at all.
 
Last edited:

AndroidNewDeveloper

New member
Jan 18, 2017
4
0
HELP ME

See..
i am having problem in installing Gapps
i tried every way it didn't worked out
plz guide me step by step so i can increase system space
I CANNOT DO IT
 

DiamondJohn

Recognized Contributor
Aug 31, 2013
6,658
6,687
Sydney
I realize that flashing the wrong bootloader is not common for an experienced user, but I assure you that I am unable to turn the device on. That means no button combos, no fastboot, no recovery, no google logo. The phone was originally hard bricked after I manually flashed and restarted the correct bootloader.

Then I started troubleshooting..

After I started troubleshooting, there were only 2 exceptions where I was able to get to Fastboot with button combos. The first time, I used the opportunity to flash-all on top of my erased boot, cache, system, etc.

That did not fix it so I got lucky a 2nd time and got to fastboot but this time it crashed out of fastboot never to turn on again!

And now that I am trying to use an ODIN like software to do factory flashes my device is not showing up in device manager at all.
The Nexus 5 is notorious for having a faulty power button. Normally it gets stuck in the ON position. But maybe yours fails to switch on.
 

sekiradrug

New member
Jan 20, 2017
1
0
Hello everyone

I've been having no sim card issue on my Nexus 5 6.0.1. After it spent 20 days at local phone service, the guy told me its software problem, hardware is fine.

After some googling and help of a friend, I ended up returning my n5 to 5.0.1 but it didnt solve my problem. After that I took it 4.4.4. but problem is still there.

Any thoughts?

thanks
 

ruabell

Senior Member
Sep 4, 2010
89
20
mpls/st paul
how far "back to stock" do I need to go to restore the ability to use Android Pay without any issues?
can I remain rooted?
just the bootloader?
super hide is a super pain in the arse and rarely works
have a grateful weekend[emoji41]

Sent from my Pixel using Tapatalk
 

Guatiao

Senior Member
Feb 22, 2012
521
55
Many moons later this guide has proven really easy and helpful for my aging Nexus 5, which came out of retirement when my Galaxy S6 Edge Plus decided to kill my data connection. Waiting for a replacement at the moment, and enjoying my "new" nexus 5, thanks!!!!!
 

Facebooook

Senior Member
Dec 24, 2009
276
25
Katni
I am on full stock rom but suddenly my phone shutdown .Now when I on it it's stuck on boot animation and doesn't start.
Then I tried to factory reset with recovery but it's doesn't go in recovery say no command.
But it's go on fastboot mode....
Then I tried to flash stock rom via ADB but when I unlock bootloader it's automatically locked and when I flash something it's say remote write failure.
Then I tried to use lgflash tool but driver doesn't install.something like hold vol up and connect cable to PC....It's doesn't install any driver. Only show MTP in device manager.[/QUOTE]
 

bigcelo75

Senior Member
Oct 22, 2012
221
110
Rio de Janeiro
I am on full stock rom but suddenly my phone shutdown .Now when I on it it's stuck on boot animation and doesn't start.
Then I tried to factory reset with recovery but it's doesn't go in recovery say no command.
But it's go on fastboot mode....
Then I tried to flash stock rom via ADB but when I unlock bootloader it's automatically locked and when I flash something it's say remote write failure.
Then I tried to use lgflash tool but driver doesn't install.something like hold vol up and connect cable to PC....It's doesn't install any driver. Only show MTP in device manager.
[/QUOTE]
Try holding the power button and tapping the volume up button when it says no command. That should take you to stock recovery. Hope that helps!

Sent from my Nexus 6P using XDA-Developers Legacy app
 

Mc.YomiCo

Member
Jul 11, 2016
11
0
Um on 7.1.2 AOSP Rom...if i can do this to get official android on my nexus 5...plz guide...best regards

---------- Post added at 08:10 AM ---------- Previous post was at 08:03 AM ----------

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:

★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)

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

******************************************************************************

Hello abaaaabbbb63

I have the same problem on my Nexus 5
Try two methods

Try method 1, result:

C:\Windows\system32>fastboot devices
039f8bc8437cbcc8 fastboot

C:\Windows\system32>cd..

C:\Windows>cd..

C:\>cd hammerhead-m4b30x

C:\hammerhead-m4b30x>flash-all.bat
sending 'bootloader' (3124 KB)...
OKAY [ 0.297s]
writing 'bootloader'...
OKAY [ 0.443s]
finished. total time: 0.740s
rebooting into bootloader...
OKAY [ 0.047s]
finished. total time: 0.063s
"ping" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
< waiting for device >
target reported max download size of 1073741824 bytes
sending 'radio' (45489 KB)...
OKAY [ 1.584s]
writing 'radio'...
FAILED (remote: flash write failure)
finished. total time: 2.820s
rebooting into bootloader...
OKAY [ 0.031s]
finished. total time: 0.047s
"ping" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.
< waiting for device >
target reported max download size of 1073741824 bytes
archive does not contain 'boot.sig'
archive does not contain 'recovery.sig'
archive does not contain 'system.sig'
archive does not contain 'vendor.img'
Creating filesystem with parameters:
Size: 29236371456
Block size: 4096
Blocks per group: 32768
Inodes per group: 8192
Inode size: 256
Journal blocks: 32768
Label:
Blocks: 7137786
Block groups: 218
Reserved block group size: 1024
Created filesystem with 11/1785856 inodes and 156120/7137786 blocks
Creating filesystem with parameters:
Size: 734003200
Block size: 4096
Blocks per group: 32768
Inodes per group: 7472
Inode size: 256
Journal blocks: 2800
Label:
Blocks: 179200
Block groups: 6
Reserved block group size: 47
Created filesystem with 11/44832 inodes and 5813/179200 blocks
--------------------------------------------
Bootloader Version...: HHZ20h
Baseband Version.....: M8974A-2.0.50.2.30
Serial Number........: 039f8bc8437cbcc8
--------------------------------------------
checking product...
OKAY [ 0.005s]
checking version-bootloader...
OKAY [ 0.008s]
checking version-baseband...
OKAY [ 0.097s]
sending 'boot' (9154 KB)...
OKAY [ 0.518s]
writing 'boot'...
OKAY [ 0.761s]
sending 'recovery' (10012 KB)...
OKAY [ 0.449s]
writing 'recovery'...
FAILED (remote: flash write failure)
finished. total time: 2.901s
Press any key to exit...

Try method 2, result:

Microsoft Windows [Versión 6.3.9600]
(c) 2013 Microsoft Corporation. Todos los derechos reservados.

C:\Windows\system32>cd..

C:\Windows>cd..

C:\>fastboot devices
039f8bc8437cbcc8 fastboot

C:\>fastboot erase boot
erasing 'boot'...
OKAY [ 0.205s]
finished. total time: 0.205s

C:\>fastboot erase cache
******** Did you mean to fastboot format this partition?
erasing 'cache'...
OKAY [ 0.191s]
finished. total time: 0.206s

C:\>fastboot erase recovery
erasing 'recovery'...
OKAY [ 0.215s]
finished. total time: 0.218s

C:\>fastboot erase system
******** Did you mean to fastboot format this partition?
erasing 'system'...
OKAY [ 0.221s]
finished. total time: 0.221s

C:\>fastboot erase userdata
******** Did you mean to fastboot format this partition?
erasing 'userdata'...
OKAY [ 0.449s]
finished. total time: 0.451s

C:\>cd hammerhead-m4b30x

C:\hammerhead-m4b30x>fastboot flash bootloader bootloader.img
target reported max download size of 1073741824 bytes
sending 'bootloader' (3124 KB)...
OKAY [ 0.292s]
writing 'bootloader'...
FAILED (remote: flash write failure)
finished. total time: 0.516s

C:\hammerhead-m4b30x>

Can you help me please, I have a LG Nexus 5 D820H

Thanks

I have something similar on my Nexus 5 and i send my phone to service and they change my motherboard in phone because it whose broken.[/QUOTE]
Hay is this work for mee.... I'm on 7.1.2 AOSP Rom i need to get back on official android plz help
 

SSyar

Senior Member
Apr 27, 2011
501
52
41
How to flash a factory image | Return to stock | Unroot your Nexus 5​

I am on M4B30Z, i tried kingroot for the root it did root my phone but end up in battery percentage issue of 3000%. Internet suggests me to flash factory image ., but i want data(pic/videos etc) intact., so what if i just extract and flash *system.img* from M4B30Z factory image will it work for me to fix that 3000% issue ?
 

BearOfXDA

Senior Member
Apr 14, 2017
179
14
Muscatine
How would this be done with TWRP only?

I have no access to a PC, so how would flashing the stock image be done on TWRP? You can flash images by themselves, so would you just flash them in the same order? Or is there something I'm missing?
 

r0bis

New member
Aug 17, 2017
4
2
Why not use commands from flash-all.sh

Thanks very much for this guide. I have seen a few similar ones. They say to flash the images in sequence as above (more or less same sequence) with fastboot reboot-bootloader in between some.

My question - why not use
Code:
fastboot -w update ./image-bullhead-XXXX.zip
as the last command in flash-all.sh

That seems to do everything (after it verifies that correct bootloader and radio have been flashed beforehand used) and the only thing to do after this finishes is to fastboot flashing lock.

Then fastboot oem device-info gives:
[[email protected] bullhead-n4f26i]$ fastboot oem device-info
...
(bootloader) Device tampered: false
(bootloader) Device unlocked: false
(bootloader) off-mode-charge: true
(bootloader) Display panel:
OKAY [ 0.060s]
finished. total time: 0.060s


The difference seems to be only in sequence. Using the flash-all.sh you get
* bootloader.img
* reboot to booloader
* radio.img
* reboot to booloader
* then flashed in sequence: boot - recovery - system - vendor - userdata - cache
* then all I do is to lock the bootloader

I your sequence after flashing bootloader and radio with corresponding reboots you do:
* flash in sequence system - userdata - boot - recovery - cache
with erasing cache prior to writing it
and also in my case vendor.img gets written (I acknowledge it parhaps is not present in all image zips)
 
Last edited:
  • Like
Reactions: Spyhopping

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://forum.xda-developers.com/showthread.php?t=2588979

    For MAC users:
    http://forum.xda-developers.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://forum.xda-developers.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://forum.xda-developers.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://forum.xda-developers.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://forum.xda-developers.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.