[GUIDE] How to Unlock the Bootloader, Flash a Factory Image, and Return to Stock

Search This thread

jd1639

Inactive Recognized Contributor
Sep 21, 2012
16,832
5,401
Minnesota
This guide will help you unlock your bootloader, flash a factory image, and return you to a stock device. It is wriiten assuming you have a windows PC (MAC users, see post 2). This can be helpful if you need to RMA your device or if you are getting erratic behavior or messed something up.

Tools and Files You’ll Need
  1. If you don’t have adb and fastboot installed on your PC go here for a quick install of the necessary files, thanks to @Snoop05, http://forum.xda-developers.com/showthread.php?t=2588979
    For MAC users go here. http://forum.xda-developers.com/showthread.php?p=32305619
    For Linux users, http://forum.xda-developers.com/showthread.php?p=10746225
  2. For the factory image go here, https://developers.google.com/android/nexus/images You’ll download a .tgz file. Use winrar or 7-zip to extract the file to its own directory and remember where that directory is. Inside is another zip file, extract that too. You’ll need those image files if you use the long method to install the factory image. It’s also good to know where they are as they come in handy as you get more familiar with fastboot and what you can do with it.

How To Unlock the Bootloader

  1. If you don’t have developer options enabled on your device go to settings, about device and tap on the build number 7 times.
  2. In settings, developer options enable oem unlock
  3. Now you get to use fastboot! Boot you device into the bootloader, vol up + power with your device shut off. Once booted into the bootloader connect it to your PC with the usb cable and open a command window on your PC. Once connected type the following command in the cmd window:
fastboot devices (Your device serial number should show up and this will ensure fastboot is working properly)


Then type:


fastboot oem unlock (This will unlock the bootloader and you’re now good to go)​

NOTE, UNLOCKING THE BOOTLOADER DOES WIPE YOUR DEVICE SO BACKUP OFF YOUR DEVICE FIRST

How To Flash the Factory Image, SHORT METHOD

  1. Open a command window on your PC in the same directory as you extracted the factory image. In that directory shift, right click in an open area and use “Open a command window here”
  2. Boot your device into the bootloader and connect it to your PC. Then simply double click on the flash-all batch file. Note that there are batch files in there that will work for Windows as well as Linux machines
  3. Let the batch file run and when it’s done you’ll be back to stock.
  4. NOTE THAT FLASHING BY THIS METHOD DOES WIPE YOUR DEVICE SO MAKE SURE YOU BACKUP OFF YOUR DEVICE FIRST.

How To Flash the Factory Image, LONG METHOD

In this method each factory image is flashed separately. This should be used if you have problems with the short method and as you get more familiar with fastboot you’ll be able to flash only the images that you need for your specific requirement. For instance, you might want to only flash the stock recovery if you’re trying to take an ota and you’ve installed a custom recovery. The order that you flash the images is not important.

In the folder you extracted the factory image it’s easiest if you re-name the bootloader image file to simply bootloader and radio. Then open a Windows command window in that folder and use the fastboot commands:

fastboot flash bootloader bootloader.img
fastboot reboot-bootloader

fastboot –w (NOTE, this command does wipe your device. It’s possible to flash the factory image without this command but if you’re going from different revision numbers of android it’s highly recommend to wipe the device)


Now open a Windows command window in the same folder that you extracted the zip file in, the one where you find recovery, system, etc. Then run the fastboot commands:

fastboot flash boot boot.img
fastboot flash cache cache.img
fastboot flash recovery recovery.img
fastboot flash system system.img [Note, flashing system takes a long time, so let it do it's thing]
fastboot flash vendor vendor.img

Congratulations, you’ve now flashed a factory image and learned how to use fastboot!
 
Last edited:

jd1639

Inactive Recognized Contributor
Sep 21, 2012
16,832
5,401
Minnesota
This should be made a 'sticky'...

An excellent well written tutorial... succinct, clear and to the point.

Far better to use fastboot instead of a toolkit... Everything is more transparent, and you actually gain a better understanding of your device as a result.

Rgrds,
Ged.

Thanks @GedBlake. I would have responded sooner but I had to get home and check my tablet. Actually both work, vol up + power and vol down + power.

Sent from my Nexus 9 using XDA Free mobile app
 
  • Like
Reactions: GedBlake
D

Darth

Guest
But.... Toolkit so easy? ;)

(agreed... Toolkits not the best choice)

Thread stuck. Great guide @jd1639!

If we get enough guides, tutorials, how to's and other great info threads.... I would suggest a "sticky roll up" thread, so too many stickies aren't created.

Food for thought. :)

Edit : That ^^^^ was a hint to other members to get your guides, tutorials, info threads, FAQ... Etc... Going..... This is a Nexus section after all. :silly:
 
Last edited:

jd1639

Inactive Recognized Contributor
Sep 21, 2012
16,832
5,401
Minnesota
But.... Toolkit so easy? ?

(agreed... Toolkits not the best choice)

Thread stuck. Great guide @jd1639! ?

If we get enough guides, tutorials, how to's and other great info threads.... I would suggest a "sticky roll up" thread, so too many stickies aren't created.

Food for thought. ?

I'll keep an eye it and do a roll up when the need arises

Sent from my Nexus 9 using XDA Free mobile app
 

nyasha1935

Member
Apr 5, 2014
39
3
Johannesburg
cant flash system.img

I Xubuntu 14.04 I can't seem to flash the system.img I get the following error

sending 'system' (1108544 KB)...
FAILED (remote: data length is too large)
finished. total time: 0.032s
 

cam30era

Inactive Recognized Contributor
Nov 20, 2010
5,092
1,792
Columbus, Indiana
I Xubuntu 14.04 I can't seem to flash the system.img I get the following error

sending 'system' (1108544 KB)...
FAILED (remote: data length is too large)
finished. total time: 0.032s

It's possible that you need to update your Android SDK to the latest. There was a recent change (within last 6 months) to fastboot to allow flashing these large .img files.
 

iamroddo

Member
Oct 18, 2010
43
2
Heidelberg

Leoncino

Member
May 26, 2015
48
9
OnePlus 6T
Hi, I'm Italian so i'm sorry if my english is bad xD what happens if i flash a different kernel? Will i lose my warranty?
If yes, if i flash the factory image, will i have my warranty again?
And, again, sorry for my bad english :p
 

cam30era

Inactive Recognized Contributor
Nov 20, 2010
5,092
1,792
Columbus, Indiana
Hi, I'm Italian so i'm sorry if my english is bad xD what happens if i flash a different kernel? Will i lose my warranty?
If yes, if i flash the factory image, will i have my warranty again?
And, again, sorry for my bad english :p

No need top apologize. You're English if fine.

There's a lot of discussion and lack of agreement about what affects the warranty on the Nexus 9. HTC says that even unlocking the bootloader "may void the warranty".

My advice would be to do what you want to it, but make sure you understand what you are doing. Ask a lot of questions before you do something you're unsure of.

Unlock your bootloader (if you haven't already). Do not relock bootloader if something goes wrong (this does not solve anything). With an unlocked bootloader, you can recover from almost any problem.

And you can flash the Google factory images anytime you want to return to stock.

I'm sorry there's not a clear answer to your question.
 
  • Like
Reactions: Leoncino

cam30era

Inactive Recognized Contributor
Nov 20, 2010
5,092
1,792
Columbus, Indiana
Thanks :)
So it's like Samsung knox, we don't know what happens to our device.
An other little question? Is the same if i root my device? Need to unlock bootloader?

Bootloader has to be unlocked to root, install custom recovery (TWRP). And note that when you unlock bootloader, it will wipe the contents of your SDcard. If you have anything important there, back it up on your PC.
 
  • Like
Reactions: Leoncino

Top Liked Posts

  • There are no posts matching your filters.
  • 23
    This guide will help you unlock your bootloader, flash a factory image, and return you to a stock device. It is wriiten assuming you have a windows PC (MAC users, see post 2). This can be helpful if you need to RMA your device or if you are getting erratic behavior or messed something up.

    Tools and Files You’ll Need
    1. If you don’t have adb and fastboot installed on your PC go here for a quick install of the necessary files, thanks to @Snoop05, http://forum.xda-developers.com/showthread.php?t=2588979
      For MAC users go here. http://forum.xda-developers.com/showthread.php?p=32305619
      For Linux users, http://forum.xda-developers.com/showthread.php?p=10746225
    2. For the factory image go here, https://developers.google.com/android/nexus/images You’ll download a .tgz file. Use winrar or 7-zip to extract the file to its own directory and remember where that directory is. Inside is another zip file, extract that too. You’ll need those image files if you use the long method to install the factory image. It’s also good to know where they are as they come in handy as you get more familiar with fastboot and what you can do with it.

    How To Unlock the Bootloader

    1. If you don’t have developer options enabled on your device go to settings, about device and tap on the build number 7 times.
    2. In settings, developer options enable oem unlock
    3. Now you get to use fastboot! Boot you device into the bootloader, vol up + power with your device shut off. Once booted into the bootloader connect it to your PC with the usb cable and open a command window on your PC. Once connected type the following command in the cmd window:
    fastboot devices (Your device serial number should show up and this will ensure fastboot is working properly)


    Then type:


    fastboot oem unlock (This will unlock the bootloader and you’re now good to go)​

    NOTE, UNLOCKING THE BOOTLOADER DOES WIPE YOUR DEVICE SO BACKUP OFF YOUR DEVICE FIRST

    How To Flash the Factory Image, SHORT METHOD

    1. Open a command window on your PC in the same directory as you extracted the factory image. In that directory shift, right click in an open area and use “Open a command window here”
    2. Boot your device into the bootloader and connect it to your PC. Then simply double click on the flash-all batch file. Note that there are batch files in there that will work for Windows as well as Linux machines
    3. Let the batch file run and when it’s done you’ll be back to stock.
    4. NOTE THAT FLASHING BY THIS METHOD DOES WIPE YOUR DEVICE SO MAKE SURE YOU BACKUP OFF YOUR DEVICE FIRST.

    How To Flash the Factory Image, LONG METHOD

    In this method each factory image is flashed separately. This should be used if you have problems with the short method and as you get more familiar with fastboot you’ll be able to flash only the images that you need for your specific requirement. For instance, you might want to only flash the stock recovery if you’re trying to take an ota and you’ve installed a custom recovery. The order that you flash the images is not important.

    In the folder you extracted the factory image it’s easiest if you re-name the bootloader image file to simply bootloader and radio. Then open a Windows command window in that folder and use the fastboot commands:

    fastboot flash bootloader bootloader.img
    fastboot reboot-bootloader

    fastboot –w (NOTE, this command does wipe your device. It’s possible to flash the factory image without this command but if you’re going from different revision numbers of android it’s highly recommend to wipe the device)


    Now open a Windows command window in the same folder that you extracted the zip file in, the one where you find recovery, system, etc. Then run the fastboot commands:

    fastboot flash boot boot.img
    fastboot flash cache cache.img
    fastboot flash recovery recovery.img
    fastboot flash system system.img [Note, flashing system takes a long time, so let it do it's thing]
    fastboot flash vendor vendor.img

    Congratulations, you’ve now flashed a factory image and learned how to use fastboot!
    3
    This should be made a 'sticky'...

    An excellent well written tutorial... succinct, clear and to the point.

    Far better to use fastboot instead of a toolkit... Everything is more transparent, and you actually gain a better understanding of your device as a result.

    Rgrds,
    Ged.
    2
    For MAC users, proceed each fastboot command with a ./ e.g. ./fastboot flash boot boot.img
    1
    This should be made a 'sticky'...

    An excellent well written tutorial... succinct, clear and to the point.

    Far better to use fastboot instead of a toolkit... Everything is more transparent, and you actually gain a better understanding of your device as a result.

    Rgrds,
    Ged.

    Thanks @GedBlake. I would have responded sooner but I had to get home and check my tablet. Actually both work, vol up + power and vol down + power.

    Sent from my Nexus 9 using XDA Free mobile app
    1
    Hi, I'm Italian so i'm sorry if my english is bad xD what happens if i flash a different kernel? Will i lose my warranty?
    If yes, if i flash the factory image, will i have my warranty again?
    And, again, sorry for my bad english :p

    No need top apologize. You're English if fine.

    There's a lot of discussion and lack of agreement about what affects the warranty on the Nexus 9. HTC says that even unlocking the bootloader "may void the warranty".

    My advice would be to do what you want to it, but make sure you understand what you are doing. Ask a lot of questions before you do something you're unsure of.

    Unlock your bootloader (if you haven't already). Do not relock bootloader if something goes wrong (this does not solve anything). With an unlocked bootloader, you can recover from almost any problem.

    And you can flash the Google factory images anytime you want to return to stock.

    I'm sorry there's not a clear answer to your question.