There will be instances when you would want to flash a factory image on your Pixel or Nexus device. This is either when you want a clean installation of your device’s software, or if you want to install the latest software for your device. Google has made it pretty easy for users to do this, but it will still take a bit of work. That said, when you really need to flash a factory image, it will be good for you to learn how to do it.

Just to remind all of you, we’re talking about flashing OTA and factory images for official Google devices. In particular, this can be applicable to the Nexus 6, Nexus 5X, Nexus 6P, the original Pixel and Pixel XL, and the new Pixel 2 and Pixel 2 XL.

Factory images will install stock software for these devices, which is useful if you come from using other custom ROMs. OTA images have the same effect as installing factory images, but they are useful if you are using stock software, because these will allow you to flash the software without the need for a data wipe, hence you won’t lose data on your device.

Requirements:

  • Any of the Google official devices – the Nexus 6, Nexus 5X, Nexus 6P, the original Pixel and Pixel XL, or the Pixel 2 and Pixel 2 XL.
  • Unlocked bootloader. Your device’s bootloader needs to be unlocked for you to flash a factory image or an OTA image. If your device’s bootloader is already unlocked and you are using stock software, you will be able to flash without losing your data. An unlocked bootloader means you will have to unlock it, and you will need to wipe your data, so make sure you back them up.
  • Installed ADB tools on your computer. We have a tutorial on how to install ADB on your computer. Check that out.
  • Download the correct factory image or OTA image for your device. Remember all the horrible things you would have to experience if you somehow flashed the wrong image for your device.

Unlocking the bootloader

If you know that your device’s bootloader is already unlocked, then you are free to skip this section. Otherwise, you will need to unlock your phone’s bootloader before you can flash a factory image.

Bootloader are locked by manufacturers and carriers for security. Unlocking the bootloader of a device will require your device to be completely wiped going from a “locked” state to an “unlocked” state. As you may have guessed, there is no way to keep your data if your bootloader is locked. Here’s how to unlock the bootloader.

  1. Go into the Settings app.
  2. Look for Developer Options. If you don’t see this section, go to the “About” page. Tap the Android build number several times, until it confirms “you are a developer”. The Developer Options section should now show up in the Settings main menu.
  3. Go into Developer Options. Put a check or toggle on OEM unlocking.
  4. Connect your phone to your PC via USB data cable. Run ADB.
  5. Type in the command adb reboot bootloader to reboot the device into the bootloader.
  6. Type in fastboot oem unlock. This will bring you some prompts to ask if you really want to unlock the bootloader. Take note that confirming here will delete all the data you have in your device, so make sure you have already backed up your data.
  7. Confirm the unlocking of the bootloader. Your device will now be completely wiped of data.

Flashing the factory or OTA image

Once you have downloaded the correct file from Google’s official developer site, you will need to prep it so you can flash it onto your device. You will have downloaded a ZIP archive file, which will look something like “walleye-opm2.171019.029-factory-41296266.zip”. Unzipping this file will give you a bootloader, OS image, vendor image, and a radio image file (depending on the device you have). Save these in a separate folder.

  1. Start your device in fastboot mode. Using the command terminal, you can initiate adb reboot bootloader, or you can reboot using the specific key combination for starting your device in fastboot mode.
  2. Connect your device to the PC sing your USB data cable.
  3. Navigate using the command prompt to you’re the folder where your files are.
  4. Execute the flash-all script. This script installs the necessary bootloader, baseband firmware(s), and operating system.

Once the script finishes the operation, you can reboot the device and see that you have a newly installed factory image.