Android Upgrades, Custom ROMs (LineageOS), & Kernels

From Stock to Secure: Using ADB Sideload to Revert to Factory Images and Lock Your Bootloader

Google AdSense Native Placement - Horizontal Top-Post banner

Introduction: The Path Back to Stock

Restoring an Android device to its factory state, often referred to as ‘returning to stock,’ is a crucial skill for enthusiasts, developers, and even regular users. Whether you’re selling your device, sending it in for warranty service, troubleshooting persistent software issues, or simply want to undo customizations like custom ROMs and root, reverting to a pristine factory image is the solution. This process typically involves flashing official firmware and, critically, re-locking the bootloader to restore security and integrity.

While many associate factory image flashing with fastboot commands, this guide will primarily focus on leveraging ADB sideload for returning to a factory-like state using official OTA packages, and then comprehensively cover the essential step of re-locking your bootloader.

Essential Prerequisites for a Smooth Reversion

Before embarking on the reversion journey, ensure you have the following:

  • ADB and Fastboot Tools: Download and set up the latest Platform-Tools from the Android SDK on your computer. Add them to your system’s PATH for easy access.
  • Device Drivers: Install the correct USB drivers for your specific Android device model on your computer. Google USB Driver is a good starting point for Pixel/Nexus devices.
  • OEM Unlocking Enabled: If your bootloader is currently unlocked, ensure that ‘OEM unlocking’ is still enabled in Developer Options. This is a safeguard against accidental re-locking on a non-stock ROM, which can brick your device.
  • Official Factory Image or Full OTA Package: Obtain the correct factory image or full OTA package for your exact device model from an official source (e.g., Google Developers for Pixel/Nexus devices).
  • Backup Your Data: This process will wipe ALL data on your device. Back up everything important (photos, contacts, apps, messages) before proceeding.
  • Charged Device: Ensure your device has at least 80% battery to prevent power loss during the flashing process.
  • USB Cable: Use a high-quality USB cable to connect your device to your computer.

Understanding Factory Images and OTA Packages

It’s important to differentiate between Google’s ‘Factory Images’ and ‘Full OTA Packages,’ as they are used differently for reversion:

  • Factory Images: These typically include all partitions (bootloader, radio, system, vendor, etc.) and are usually flashed via fastboot using a provided script (flash-all.sh or flash-all.bat). This is the most comprehensive way to return to stock.
  • Full OTA Packages: These are official over-the-air updates, but unlike incremental OTAs, ‘Full OTAs’ contain the complete system image for a specific version. They can be ‘sideloaded’ from the stock recovery, effectively returning your device to that stock version. This method is often preferred when the primary goal is to revert to a clean, official stock OS without necessarily touching low-level partitions like the bootloader or radio unless they are part of the OTA.

This guide will focus on the ADB sideload method primarily using a Full OTA package, then briefly cover the fastboot method for comprehensive factory image flashing.

Step-by-Step: Reverting to Stock via ADB Sideload

Step 1: Prepare Your Device and Workspace

  1. Enable USB Debugging: If possible, navigate to Settings > About Phone and tap ‘Build number’ seven times to unlock Developer Options. Go to Settings > System > Developer options and enable ‘USB debugging.’
  2. Reboot to Recovery Mode: You can do this by either:
    • Connecting your device to your computer and using the command:
      adb reboot recovery

    • Or, power off your device. Then, hold down the Volume Down + Power buttons simultaneously until the Fastboot/Bootloader screen appears. Use the Volume keys to navigate to ‘Recovery mode’ and press the Power button to select it.
  3. Enter Sideload Mode: Once in stock recovery, you’ll likely see an Android robot with an exclamation mark or a menu. If it’s the robot, hold Power and press Volume Up once. From the recovery menu, select ‘Apply update from ADB’ (or ‘Apply update from computer’). Your device will now wait for a sideload command.

Step 2: Download and Verify Your Stock Image

  1. Download the Full OTA Package: Visit the official Google Developers website (or your device manufacturer’s equivalent) and download the Full OTA image (a .zip file) for your specific device model and the desired Android version.
  2. Place the ZIP File: Move the downloaded .zip file into the same directory where your ADB and Fastboot tools are located on your computer for easy access.

Step 3: Initiate the Sideload Process

  1. Open Command Prompt/Terminal: Navigate to the directory containing your ADB tools and the OTA .zip file.
  2. Execute the Sideload Command: With your device in sideload mode, run the following command, replacing filename.zip with the actual name of your downloaded OTA package:
    adb sideload filename.zip

  3. Monitor Progress: The sideload process will begin. You will see progress indicators on both your computer’s terminal and your device’s screen. This can take several minutes. Do not disconnect your device or interrupt the process.
  4. Reboot System: Once the sideload is complete, the recovery menu will reappear. Select ‘Reboot system now.’

Step 4: Post-Sideload Verification

Your device should now boot into the freshly installed stock Android operating system. Go through the initial setup. Once complete, navigate to Settings > About Phone to verify the build number matches the OTA package you sideloaded.

The Fastboot Method: An Alternative for Comprehensive Reversion

For a complete factory image flash that touches all partitions (bootloader, radio, vendor, etc.), the fastboot method with Google’s Factory Images is often preferred. This typically uses the flash-all.sh (Linux/macOS) or flash-all.bat (Windows) script included in the downloaded factory image archive.

Step 1: Extract the Factory Image

  1. Download the factory image (usually a .tgz archive for Google devices).
  2. Extract the archive. You’ll find several .img files and the flash-all script.

Step 2: Boot into Fastboot Mode

  1. Connect your device to your computer.
  2. Reboot into fastboot mode using:
    adb reboot bootloader

    (or the button combination: Power off, then hold Volume Down + Power).

Step 3: Execute the Flashing Script

  1. Navigate to the extracted factory image directory in your terminal/command prompt.
  2. Run the appropriate script:
    • Linux/macOS:
      ./flash-all.sh

    • Windows:
      flash-all.bat

This script will automatically flash all necessary partitions, typically including a full data wipe. Once complete, your device will reboot into a completely fresh stock OS.

Locking Your Bootloader for Enhanced Security

After successfully reverting to a verifiable stock ROM, the final and critical step is to re-lock your bootloader. This restores the device’s security chain, preventing unauthorized software from loading and enabling features like verified boot. WARNING: Only relock your bootloader if your device is running a 100% official, untouched stock ROM. Attempting to relock on a custom ROM, custom recovery, or rooted system will likely hard-brick your device!

Important Considerations Before Locking

  • Data Wipe: Locking the bootloader will perform another factory reset, wiping all user data.
  • No Customization: Ensure no custom recovery (like TWRP), custom kernel, or root solution is present.

The Locking Procedure

  1. Boot into Fastboot Mode: Reboot your device into fastboot mode (adb reboot bootloader or button combo).
  2. Execute the Lock Command: In your terminal/command prompt, execute:
    fastboot flashing lock

    For some older devices, the command might be:

    fastboot oem lock

  3. Confirm on Device: Your device’s screen will display a warning message about locking the bootloader and wiping data. Use the Volume keys to select ‘Lock the bootloader’ (or ‘Yes’) and press the Power button to confirm.
  4. Reboot: The device will perform a data wipe and reboot. It may display a locked bootloader warning message briefly on subsequent startups.

Troubleshooting Common Issues

  • ADB/Fastboot Not Recognized: Check if Platform-Tools are in your PATH. Reinstall device drivers. Try a different USB port or cable.
  • Sideload Errors (e.g., ‘signature verification failed’): Ensure you downloaded the correct OTA package for your exact device model and region. The file might be corrupted; redownload it.
  • Bootloop After Flashing: This usually indicates an incorrect or corrupted image was flashed. Re-flash the correct factory image using the fastboot flash-all.sh method for a full clean slate.
  • ‘fastboot flashing lock’ Fails: Ensure ‘OEM unlocking’ is disabled in Developer Options (if it was enabled after the flash). Verify you are on a completely stock ROM.

Conclusion: Restoring Device Integrity

Reverting your Android device to a factory image via ADB sideload or fastboot, and subsequently re-locking the bootloader, is a comprehensive process that restores both software integrity and security. Whether you’re preparing a device for resale, resolving complex software issues, or simply returning to a trusted state, following these steps ensures your device operates as intended by the manufacturer, protected by verified boot and a secure boot chain. Always proceed with caution and double-check your device model and image compatibility to avoid unexpected issues.

Android Mobile Specs & Compare Directory

Are you researching mobile hardware properties, processor SoCs, GPU chipsets, or RAM configurations? Access our complete specs catalog to compare up to 5 devices side-by-side!

Compare Devices Specs →
Google AdSense Inline Placement - Content Footer banner