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

r0bis

New member
Aug 17, 2017
4
2
0
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

r0bis

New member
Aug 17, 2017
4
2
0
For some reason for me the flash all never worked so I followed the manual part and never had any problems.
May not work for several reasons, but most commonly where path is not found, i'd think. I was just curious as to why there is `update` command to fastboot which apparently flashes images from the zip file (http://manpages.ubuntu.com/manpages/zesty/man1/fastboot.1.html) - so there is no need to unzip it into its component parts, but maybe there is something else to update? I was also thinking if it was necessary to reboot the device between flashing some partitions or not. Also it seems clear that flashing radio and bootloader first and then rebooting is important before flashing all other partitions; I was just curious why.it is so?
 

ALASTOR1111

Member
Jan 20, 2016
22
1
0
Belgrade
I got Nexus 5 with Ubuntu on it from my friend, how to go back to Android? Can i use this guide to flash android back from fastboot? I don't have Linux on my PC, its Win10. Please give me step by step guide. Thanks in advance.
 

theburrus1

Member
Apr 5, 2011
48
3
8
Need help with flashing stock rom via fastboot on Linux

Hi, so I have a question here. I'm not sure why my stock rom file contains the files the way it does but here (please see attachment):

file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/adspso.bin
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/boot.img
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/bootloader.img
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/flashfile.xml
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/fsg.mbn
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/gpt.bin
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/logo.bin
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/NON-HLOS.bin
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/oem.img_sparsechunk.0
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/oem.img_sparsechunk.1
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.info.txt
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/recovery.img
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/regulatory_info_default.png
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/servicefile.xml
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/slcf_rev_d_default_v1.0.nvm
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/system.img_sparsechunk.0
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/system.img_sparsechunk.1
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/system.img_sparsechunk.2
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/system.img_sparsechunk.3
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/system.img_sparsechunk.4
file:///home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/system.img_sparsechunk.5




If you notice, first it contains no radio.img file, nor is there a userdata.img nor cache.img. Furthermore the system.img is broken into sparse chunk images. So am I supposed to make one .img file first then flash the system? Although I'm doubting it would be successful as some hash or key would be bad. Lastly, using fastboot flashall to flash the flashfile .xml I get the error
Code:
linux-ki4n:/home/kevin # fastboot flashall /home/kevin/OWENS_SPRINT_NCR26.58-26_cid50_subsidy-DEFAULT_regulatory-DEFAULT_CFC.xml/flashfile.xml
error: neither -p product specified nor ANDROID_PRODUCT_OUT set
So I am not sure what product or PRODUCT_OUT fastboot is looking for?

Any help doing all this successfully is appreciated.
 
Last edited:

Soren11112

New member
Feb 20, 2018
4
0
0
Randomly stopped and hard-bricked phone

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.




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




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:


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








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:



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





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


As I said, it randomly stopped then hard bricked the phone
 

iiPostMaster

Senior Member
Jan 9, 2017
58
0
6
21
I had a bootloop happening from what I believe was either TWRP's fault or accidentally installing SuperSU twice. I flashed all the stock stuff for my device except for cache.img, as the file repeatedly told me it was corrupted after 5 attempts. Upon booting into recovery, the device displayed an android on its back with a red triangle that had a black exclamation point inside. I held volume down and power, but no menu opened to wipe my device. It began booting automatically when I pressed the specified button combo and now it's bootlooping again. Is my phone done for?
 

Max_H

Member
May 3, 2018
7
0
1
GodZone
I Hope I'm Not Too late 2 get Help on this 5 year old Ph that I Bought last week that I've Stuffed!

it's a Refurbished 32 GB Version, Supposedly w/ a New Battery... I got with the intention of Running Maru OS or Ubuntu Touch (ie. UbPorts ), so that I could Mitigate or Distance Myself from Android ( Google Really! )

So after Sucksessfully installing UbPorts on it ( & that was a Challenge Believe Me! ) & Migrating Most of My Files Over I was getting Notifications that I had Only 2% Storage space left & I hadn't even installed Any Apps Yet! :( I Calculated that the OS alone was Using an 8 GB Footprint! & then I was Horrified 2 Discover that the Battery was Down 2 about 30% after Only a few hOurs & having Begun w/ a Fully Charged Battery & I'd Hardly done anything on it, No Services Running etc, So that's rather Unsatisfactory! So I Tried Uninstalling UbPorts & Returning it 2 Stock...

Now it's Hung Stuck on Google Splash Screen w/ an Unlocked Padlock icon, I can However get it 2 the UbPorts Recovery Mode which has Reboot system now or Ubuntu actions or Android actions or Reboot 2 Bootloader or Power down or View Recovery logs. Of I've Tried Both Ubuntu & Android actions, But No Joy w/ either!

it'd be Great if I could get TWRP or CWM Recovery installed or otherwise even stock Android is better than Nuthing! ;)
I've got MacOS 10.13.4 & Linux Mint 18.3 & M$ Virus Bait 7

Please Help!

:confused:
 
Last edited:

mukul2108

New member
May 14, 2017
1
0
0
anyone has solution to this? I'm having the same problem...

What does it mean? :( Please. Trying to flash L.

sending 'bootloader' (2508 KB)...
OKAY [ 0.299s]
writing 'bootloader'...
OKAY [ 0.487s]
finished. total time: 0.788s
rebooting into bootloader...
OKAY [ 0.110s]
finished. total time: 0.111s
sending 'radio' (45505 KB)...
FAILED (data transfer failure (Too many links))
finished. total time: 1.165s
rebooting into bootloader...
FAILED (command write failed (Unknown error))
finished. total time: 0.803s
archive does not contain 'boot.sig'
archive does not contain 'recovery.sig'
archive does not contain 'system.sig'
archive does not contain 'tos.img'
Creating filesystem with parameters:
Size: 13725835264
Block size: 4096
Blocks per group: 32768
Inodes per group: 8144
Inode size: 256
Journal blocks: 32768
Label:
Blocks: 3351034
Block groups: 103
Reserved block group size: 823
Created filesystem with 11/838832 inodes and 93654/3351034 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...: HHZ11k
Baseband Version.....: M8974A-2.0.50.1.16
Serial Number........: 05dd383a0aca8370
--------------------------------------------
checking product...
OKAY [ 0.100s]
checking version-bootloader...
OKAY [ 0.099s]
checking version-baseband...
FAILED

Device version-baseband is 'M8974A-2.0.50.1.16'.
Update requires 'M8974A-2.0.50.2.08'.

finished. total time: 0.658s
Press any key to exit...
thanks in advance
 

Ph4

Member
Jun 26, 2016
40
3
8
Still 16GB

Hello,
I tried everything that is written here, from OP and other users, many times, but my phone still 16GB while the seller says it is 32 GB,
What other can I do?