Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

[GUIDE] How to flash the Google Nexus factory images

  • 24-11-2013 4:32pm
    #1
    Registered Users, Registered Users 2 Posts: 3,242 ✭✭✭


    How to flash the Google Nexus factory images

    Level of difficulty: Medium
    Time: 10 minutes
    Device(s): Nexus phones and tablets

    Warning:
    Backup your SD card and if you're rooted you can backup your apps and data using something like Titanium Backup. You will lose it all during the flashing process otherwise. This is essentially a complete factory reset. However, there is a way to keep your apps, data, and SD card and I will cover that also. But it's still good practice to back everything that you need up in advance, especially if you need to unlock your Bootloader, which also performs a full wipe.


    You're in a situation where an OTA update has been rolled out for your phone and because they're rolled out in phases, you could be unlucky in being selected to receive it quickly. You can choose to try and force the update to come through using another guide that I wrote, but if you'd rather flash a factory image, then this is the guide for you.

    Or maybe you just want to return to the stock firmware after your device has been flashed around like a whore. Whatever the reason you have for wanting to flash to the stock firmware, read ahead for detailed instructions.

    Let's get started.

    Prerequisites
    1. Download the correct factory image for your device here. Be 100% certain that you obtain the correct image.

    2. Download Fastboot and ADB here (applies to Windows only - see [Note 1] for Linux and Mac solutions).

    3. Get the Google USB drivers here (applies to Windows only).

    Flashing Instructions
    1. Extract the factory image .tgz archive into a folder of your choosing.

    2. Extract the Fastboot/ADB zip into the same folder as used for the factory image (again, applies to Windows only - see [Note 1] for Linux and Mac solutions).

    3. Extract the USB drivers from Google for Windows, then right-click android_winusb.inf in the context menu and click on Install. If you're using Windows 8, you'll have to disable Driving Signing (temporarily) before installing. Skip this step if you're using Linux or Mac OS X.

    4. On your Nexus device, go to Settings > Developer options and enable USB debugging. [Note 2]

    5. Turn off the Nexus device and boot into the Bootloader (hold Vol- and then press Power). Alternatively use the command: adb reboot bootloader when the device is in Android.

    6. Unlock the Bootloader using Fastboot and then boot into Android as normal and re-enable USB debugging. [Note 3]

    7. While in the Bootloader, you will want to now begin flashing the images. Open up a Command Prompt/Terminal and go to the folder where you put the factory image. Do only one of the following:

      • Run flash-all.bat (Windows) or flash-all.sh (Linux and Mac OS X).

      • Type in and run the following commands:
        fastboot flash bootloader <bootloader img file>
        fastboot reboot-bootloader
        fastboot flash radio <radio img file> (for GSM/3G/HSPA devices only)
        fastboot reboot-bootloader
        fastboot -w update <image zip file>
        

      • If you want to keep your data partition, type in and run the following commands:
        fastboot erase cache
        fastboot flash bootloader <bootloader img file>
        fastboot reboot-bootloader
        fastboot flash radio <radio img file> (for GSM/3G/HSPA devices only)
        fastboot reboot-bootloader
        fastboot update <image zip file>
        

        In this case, userdata.img would not be flashed and your data partition, apps, and SD card would all remain intact.

      Thanks to Kavrocks for some corrections to tighten up this step.

      See [Note 4] for some quick troubleshooting regarding Fastboot and ADB.

    You should be all set at this point and can attempt to boot into your newly-flashed flashed firmware.

    If you're keen on rooting, you should check out the guide I wrote concerning manually rooting the Nexus 4. It's generic enough that it can apply to other Nexus devices. I won't cover rooting here, this is just about flashing the factory image, so please post any rooting questions you have into my other guide.



    Notes

    1. If you're not using Windows, then you can go here for an easy method of obtaining Fastboot and ADB for Linux or Mac OS X.

      You may need to prefix all commands with sudo. You need to prefix all commands also with ./ when they're in the current directory.

      I have not personally tested these out as I don't have Linux or Mac OS X installed.

      On Linux, if you're missing libraries with the following error: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory, run this:
      sudo apt-get install ia32-libs
      

      Thanks to murphaph for the tips given to me in this post from another thread. Thanks also to Kavrocks for some clarification with regards to Unix command syntax. Any other tips or corrections involving Linux or Mac OS X are more than welcome.


    2. To enable visibility of the Developer options you'll have to to into Settings > About phone and tap the Build number seven times. It'll be visible as a menu above About phone thereafter.


    3. Check that the Bootloader isn't already unlocked. At the Bootloader, look for LOCK STATE at the bottom and if it says unlocked then you can skip this step. Otherwise or for first-timers, please continue...

      Remember:
      Unlocking your Bootloader will wipe your entire Nexus device, including the SD card. See the bottom of this post for SD card backup instructions.


      To unlock the Bootloader, type in and run the following command:
      fastboot oem unlock
      

      When you're prompted with a warning, use the volume keys to bring up Yes and then hit the power button to select it.


    4. If you're unable to connect to your device using Fastboot, try running:
      fastboot devices
      

      NOTE: Fastboot can only be run when in the Bootloader.

      If you're unable to connect to your device using ADB, try running:
      adb devices
      

      NOTE: You should be in Android ordinarily when running ADB.

      If you're getting nothing from those, verify that everything is connected and that you're in the Bootloader (for Fastboot) or in Android (for ADB).

      In Windows: Go to the Device Manager, look for the menu Android Device and in it something like Android Bootloader Interface (while in the Bootloader for Fastboot) and Android Composite ADB Interface (while in Android for ADB).



    Backup Instructions

    To backup your SD card, you can do it one of two ways. You will first need to enable USB debugging (see step 4, above). Then hook your phone up to the computer with your USB cable. Your Nexus device should ask for authorization to whitelist the computer, if you haven't previously done so. Therefore, be on the lookout for a pop-up.
    • Copy all the files from the SD card into a folder of your choice on your computer. If this gives you trouble, see the next option.

    • Use ADB to pull the files to an existing folder on your computer while the Nexus device is booted into Android.

    ADB Pull syntax and examples:
    adb pull <remote/phone folder> <local/computer folder>
    
    Example (Windows):
    adb pull /sdcard/ C:\Nexus4SDCard
    
    Example (Mac OS X/Linux):
    adb pull /sdcard/ /folder/on/your/computer/
    

    Note:
    If you're concerned about losing your apps, I'm afraid that your phone needs to be rooted to backup apps and their respective data, so unfortunately, at this point, the best you'll be able to do is to make a note what apps you have installed. There's an app for that! It uses the SD card to save a list and it'll assist you on re-installing all the apps on the list once you're back up and running. But as I said, it won't be able to backup or restore the data associated with your apps. You can also backup your SMS messages using this app, which also uses the SD card. So if you're using the suggested apps, wait until after you're finished before backing up your SD card.

    WhatsApp, if you're using it, saves all messages to the SD card every morning at 4am. You can also save them on-demand by going into the app and heading to Settings > Chat settings > Backup conversations.


Comments

  • Registered Users, Registered Users 2 Posts: 2,345 ✭✭✭Kavrocks


    You'll probably think me a pain in the ass but all those commands to flash the factory image are unnecessary. It can be done in one using the script supplied.
    ./flash-all.sh
    
    Your subcommands to save user data are also all unnecessary. You only need to remove 3 characters from your last command ( -w), this can be applied to the flash-all script for both Unix/Windows.


  • Registered Users, Registered Users 2 Posts: 3,242 ✭✭✭DECEiFER


    Kavrocks wrote: »
    You'll probably think me a pain in the ass but all those commands to flash the factory image are unnecessary. It can be done in one using the script supplied.
    ./flash-all.sh
    
    Not at all. I don't mind constructive criticism. :)

    The reason I didn't bring up the flash-all script or batch file is because in Windows it would involve editing the path inside for Fastboot to be executed. I have Fastboot and ADB defined in the path environment variable for Windows so I can access it no matter what folder I am at in the Command Prompt but there's no use in adding all that to the guide when it's easier to copy and paste a few extra commands instead. For beginners it's better to outline it in steps, so giving out the individual commands would probably be easier than even asking people to edit the batch file (I'm sure most people using Linux would be fine with making any necessary modifications to the script file, though). As you've probably gathered, I'm not a Linux buff and I wouldn't touch OS X unless I absolutely had to; I used it enough when I was in college, unfortunately. So in writing this guide I did place an emphasis on Windows. I started using computers during the latter part of the MS-DOS era of the early '90s so my knowledge of the Linux terminal commandlines is also limited by comparison to my knowledge of DOS commands.
    Kavrocks wrote: »
    Your subcommands to save user data are also all unnecessary. You only need to remove 3 characters from your last command ( -w), this can be applied to the flash-all script for both Unix/Windows.
    Are you certain that if I leave out the -w switch that it will omit flashing userdata.img? If so, that's a good find and I'll definitely amend my post.


  • Registered Users, Registered Users 2 Posts: 2,345 ✭✭✭Kavrocks


    DECEiFER wrote: »
    Not at all. I don't mind constructive criticism. :)

    The reason I didn't bring up the flash-all script or batch file is because in Windows it would involve editing the path inside for Fastboot to be executed. I have Fastboot and ADB defined in the path environment variable for Windows so I can access it no matter what folder I am at in the Command Prompt. For beginners it's better to outline it in steps, so giving out the individual commands would probably be easier. As you've probably gathered, I'm not a Linux buff and I wouldn't touch OS X unless I absolutely had to, I used it enough when I was in college, unfortunately. So in writing this guide I did place an an emphasis on Windows. I started using computers during the latter part of the MS-DOS era of the early '90s so my knowledge of the Linux terminal commandlines is also limited by comparison to my knowledge of DOS commands
    Never quite understand why people have that attitude towards OS X. I take your point on the windows path.
    DECEiFER wrote: »
    Are you certain that if I leave out the -w switch that it will omit flashing userdata.img? If so, that's a good find and I'll definitely amend my post.
    Yes. Including it also means your erasing of the cache is a redundant command.


  • Registered Users, Registered Users 2 Posts: 3,242 ✭✭✭DECEiFER


    Kavrocks wrote: »
    Never quite understand why people have that attitude towards OS X. I take your point on the windows path.
    Apologies, the PATH variable in the batch file doesn't override anything so it would use the fastboot.exe file if it's in the same folder regardless of how it's set. Still, getting beginners to edit the batch file (while it would seem piss-easy to any experienced user), it might still be easier just to list the individual commands.

    In addition to removing -w from the batch file, you'd have to add "fastboot erase cache" to it. Again, for anyone who's never heard of a batch file before, I feel that it'd just overcomplicating things for them.

    The reason I don't like OS X is because I find the interface clumsy. Being bred on DOS and then Windows since 1992, it'd do that to you. One of the reasons I haven't bothered much with Linux is because it lacks support for many apps that I'd need to use, and Wine etc. wouldn't be an optimal compromise. But when I need to do type of partitioning or resizing on my disks, I head right into Ubuntu to use GParted because it's much superior to the Windows Disk Management. But I do like the Ubuntu interface, it has some elements of Windows so it's not as clumsy for me. Just thought I'd better explain myself rather than just lashing out about how much I don't like such and such without anything to back it up. :)
    Kavrocks wrote: »
    Yes. Including it also means your erasing of the cache is a redundant command.
    It is indeed, I saw that when I did "fastboot help" just now and I will be amending the post in a moment to reflect this learning experience.

    Thanks again. If you have any insight into when sudo and ./ is required in Linux as my piece about it in Note 1 is quite sketchy, I'd appreciate it, as I'm sure your fellow Linux users would.


  • Registered Users, Registered Users 2 Posts: 2,345 ✭✭✭Kavrocks


    DECEiFER wrote: »
    Apologies, the PATH variable in the batch file doesn't override anything so it would use the fastboot.exe file if it's in the same folder regardless of how it's set. Still, getting beginners to edit the batch file (while it would seem piss-easy to any experienced user), it might still be easier just to list the individual commands.

    In addition to removing -w from the batch file, you'd have to add "fastboot erase cache" to it. Again, for anyone who's never heard of a batch file before, I feel that it'd just overcomplicating things for them.

    The reason I don't like OS X is because I find the interface clumsy. Being bred on DOS and then Windows since 1992, it'd do that to you. One of the reasons I haven't bothered much with Linux is because it lacks support for many apps that I'd need to use, and Wine etc. wouldn't be an optimal compromise. But when I need to do type of partitioning or resizing on my disks, I head right into Ubuntu to use GParted because it's much superior to the Windows Disk Management. But I do like the Ubuntu interface, it has some elements of Windows so it's not as clumsy for me. Just thought I'd better explain myself rather than just lashing out about how much I don't like such and such without anything to back it up. :)
    You wouldn't have to add 'fastboot erase cache'. It isn't needed but doesn't hurt either which is why I neglected it earlier.

    I totally understand the software front. Quite a lot of the software I need isn't available or doesn't fully work natively on unix systems and so I have to go back to Windows but for everyday things OS X is far easier for me. I guess I just love the fact that it's made for people who aren't very technical minded and then I've the terminal too. Sort of like the best of both worlds.
    DECEiFER wrote: »
    It is indeed, I saw that when I did "fastboot help" just now and I will be amending the post in a moment to reflect this learning experience.

    Thanks again. If you have any insight into when sudo and ./ is required in Linux as my piece about it in Note 1 is quite sketchy, I'd appreciate it, as I'm sure your fellow Linux users would.
    Installing on Mac/Linux is as simple as acquiring the correct fastboot and adb binaries and using the command
    sudo mv /path/to/file /usr/bin/{adb|fastboot}
    
    sudo will prompt for the administrators password. ./ is only used to refer to the current directory.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 3,242 ✭✭✭DECEiFER


    Kavrocks wrote: »
    You wouldn't have to add 'fastboot erase cache'. It isn't needed but doesn't hurt either which is why I neglected it earlier.
    Wiping the cache is never a bad idea so it's better to include it. I've often not done it myself out of forgetfulness but later on when inside a custom recovery, I sometimes do give it an aul' wipe.
    Kavrocks wrote: »
    I totally understand the software front. Quite a lot of the software I need isn't available or doesn't fully work natively on unix systems and so I have to go back to Windows but for everyday things OS X is far easier for me. I guess I just love the fact that it's made for people who aren't very technical minded and then I've the terminal too. Sort of like the best of both worlds.
    Android is similar in that you could either give it to your grandma or you could geek out on it at a level beyond what the average user would care for. It's one-size-fits-all. The People's OS! It's funny because iOS is the antithesis of it, whereas Mac OS X...
    Kavrocks wrote: »
    Installing on Mac/Linux is as simple as acquiring the correct fastboot and adb binaries and using the command
    sudo mv /path/to/file /usr/bin/{adb|fastboot}
    
    sudo will prompt for the administrators password. ./ is only used to refer to the current directory.
    The link I provided has install scripts for Fastboot and ADB and IIRC when I looked, a move command was included to /usr/bin/. When I previously gave out that link, someone posted to say that sudo was needed to run Fastboot and ADB or else it'd be stuck looking for the device and I wasn't sure what he'd done to install the binaries, whether he used the scripts provided in that link or something else.

    Also, in HTML when referring to paths, I've often used ./ when referring to the current level directory. I wasn't sure if in Linux it was the same but it feels like common sense at this point! Thanks for clearing it up.


  • Registered Users, Registered Users 2 Posts: 3,242 ✭✭✭DECEiFER


    Right, so the modifications to the guide are complete. Thanks again, Kavrocks.


  • Registered Users, Registered Users 2 Posts: 2,345 ✭✭✭Kavrocks


    DECEiFER wrote: »
    Android is similar in that you could either give it to your grandma or you could geek out on it at a level beyond what the average user would care for. It's one-size-fits-all. The People's OS! It's funny because iOS is the antithesis of it, whereas Mac OS X...
    Ubuntu (desktop version) appears to be heading down the Android root too, I hope they succeed.
    DECEiFER wrote: »
    The link I provided has install scripts for Fastboot and ADB and IIRC when I looked, a move command was included to /usr/bin/. When I previously gave out that link, someone posted to say that sudo was needed to run Fastboot and ADB or else it'd be stuck looking for the device and I wasn't sure what he'd done to install the binaries, whether he used the scripts provided in that link or something else.
    They effectively just do the command I posted earlier. The linux one does a bit extra which isn't needed for this case. I've never needed sudo, although my adb and fastboot are located elsewhere but that shouldn't matter though.
    DECEiFER wrote: »
    Also, in HTML when referring to paths, I've often used ./ when referring to the current level directory. I wasn't sure if in Linux it was the same but it feels like common sense at this point! Thanks for clearing it up.
    No bother.


  • Registered Users, Registered Users 2 Posts: 44,035 ✭✭✭✭Basq


    Hmmm.. I seem to be stuck on the 4 coloured bubbles / infinite loop! :(

    Restoring to stock might be only bet.


  • Registered Users, Registered Users 2 Posts: 44,035 ✭✭✭✭Basq


    After various toying about, seems to be OK now.

    Clicked "wipe data/factory reset" and "wipe cache partition" in recovery mode and did a reboot. And voila!

    Bizarre!


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,345 ✭✭✭Kavrocks


    Basq wrote: »
    After various toying about, seems to be OK now.

    Clicked "wipe data/factory reset" and "wipe cache partition" in recovery mode and did a reboot. And voila!

    Bizarre!
    Issue could have been related to the Dalvik Cache.


Advertisement