Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,772,636 Members 52,760 Now Online
XDA Developers Android and Mobile Development Forum

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

Tip us?
 
abaaaabbbb63
Old
(Last edited by abaaaabbbb63; 23rd July 2014 at 08:55 AM.)
#1  
abaaaabbbb63's Avatar
Recognized Contributor - OP
Thanks Meter 2942
Posts: 3,733
Join Date: Nov 2011
Location: Somewhere Over The Rainbow
Default [TUTORIAL] How to flash a factory image | Return to stock | Unroot/SAVE your Nexus 5

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/d...ikdutta.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/show....php?t=2588979

For MAC users:
http://forum.xda-developers.com/show....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
http://forum.xda-developers.com/showthread.php?t=921169

Download the latest factory images from here:
https://developers.google.com/androi...ges#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/show....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

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 Android appears, press Power Button + Volume UP.

★Select "Wipe data/factory data reset"

★Reboot. Your phone should be stock.


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 
(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
fastboot erase cache
★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.

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/show....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
The Following 295 Users Say Thank You to abaaaabbbb63 For This Useful Post: [ Click to Expand ]
 
abaaaabbbb63
Old
(Last edited by abaaaabbbb63; 7th November 2013 at 07:19 AM.)
#2  
abaaaabbbb63's Avatar
Recognized Contributor - OP
Thanks Meter 2942
Posts: 3,733
Join Date: Nov 2011
Location: Somewhere Over The Rainbow

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
The Following 65 Users Say Thank You to abaaaabbbb63 For This Useful Post: [ Click to Expand ]
 
abaaaabbbb63
Old
(Last edited by abaaaabbbb63; 13th December 2013 at 10:33 PM.)
#3  
abaaaabbbb63's Avatar
Recognized Contributor - OP
Thanks Meter 2942
Posts: 3,733
Join Date: Nov 2011
Location: Somewhere Over The Rainbow

Credits and Thanks:

@efrant
For his thread in the N4 section (http://forum.xda-developers.com/show....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.


The Following 34 Users Say Thank You to abaaaabbbb63 For This Useful Post: [ Click to Expand ]
 
Chromium
Old
#4  
Chromium's Avatar
Recognized Contributor
Thanks Meter 5861
Posts: 4,383
Join Date: Oct 2012
Location: Toronto

 
DONATE TO ME
Quote:
Originally Posted by abaaaabbbb63 View Post
Chromium_
For not replying to my Hangouts messages
I do my best

Jk, my school has WiFi jammers in some of the classes.

Sent using xda-developers app
The Following 2 Users Say Thank You to Chromium For This Useful Post: [ Click to Expand ]
 
abaaaabbbb63
Old
#5  
abaaaabbbb63's Avatar
Recognized Contributor - OP
Thanks Meter 2942
Posts: 3,733
Join Date: Nov 2011
Location: Somewhere Over The Rainbow
Quote:
Originally Posted by Chromium_ View Post
I do my best

Jk, my school has WiFi jammers in some of the classes.

Sent using xda-developers app
Really? That's..... evil!!
The Following 2 Users Say Thank You to abaaaabbbb63 For This Useful Post: [ Click to Expand ]
 
Chromium
Old
#6  
Chromium's Avatar
Recognized Contributor
Thanks Meter 5861
Posts: 4,383
Join Date: Oct 2012
Location: Toronto

 
DONATE TO ME
Quote:
Originally Posted by abaaaabbbb63 View Post
Really? That's..... evil!!
Evil...more like illegal.
The Following User Says Thank You to Chromium For This Useful Post: [ Click to Expand ]
 
abaaaabbbb63
Old
#7  
abaaaabbbb63's Avatar
Recognized Contributor - OP
Thanks Meter 2942
Posts: 3,733
Join Date: Nov 2011
Location: Somewhere Over The Rainbow
Bleah.. The Dotted divider looks horrible on Tapatalk....

Meh
The Following 3 Users Say Thank You to abaaaabbbb63 For This Useful Post: [ Click to Expand ]
 
jd1639
Old
#8  
jd1639's Avatar
Recognized Contributor
Thanks Meter 3175
Posts: 9,387
Join Date: Sep 2012
Location: Minnetonka, MN
Because I don't know better, why do you consider method 2 safer?
 
fintheman
Old
#9  
Member
Thanks Meter 4
Posts: 41
Join Date: Aug 2010
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.
The Following User Says Thank You to fintheman For This Useful Post: [ Click to Expand ]
 
abaaaabbbb63
Old
(Last edited by abaaaabbbb63; 6th November 2013 at 05:38 AM.)
#10  
abaaaabbbb63's Avatar
Recognized Contributor - OP
Thanks Meter 2942
Posts: 3,733
Join Date: Nov 2011
Location: Somewhere Over The Rainbow
Quote:
Originally Posted by jd1639 View Post
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.





Quote:
Originally Posted by fintheman View Post
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.

The Following 4 Users Say Thank You to abaaaabbbb63 For This Useful Post: [ Click to Expand ]
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes