Following the announcement that Android Lollipop will soon be distributed to Nexus devices as an over-the-air update, Google has gone ahead and posted factory images for the Nexus 5, 7 and 10 this afternoon. If you’re wondering how to install an Android Lollipop factory image on a Nexus device, it’s as simple as following a few step-by-step instructions.

And while most people just let Google handle restoring their data, you might want to keep things that Google doesn’t back up (like your SMS messages and the like). Fortunately, keeping your data intact while flashing a factory image is fairly easy. Read on for the full guide.

Note: This guide assumes you already have your phone’s bootloader unlocked and the ADB tools installed on your computer. If you don’t know how to do this, this guide probably isn’t for you. If you need the ADB tools, head over and download the Android SDK.

Download and prepare the factory image

If you haven’t already, grab the latest factory image from Google’s factory image page. Once you’ve downloaded the image zip file, extract it any way you’d like (with 7zip, the command line, your file browser, or some other method). Inside the extracted .tgz file there will be a .tar file, and after you extract that file, you’ll find the boot loader, OS image, a radio image (depending on your device), and a couple of scripts called “flash-all.bat” and “flash-all.sh”.

Modify the “flash-all” script to save your data

Note: You only need to follow these instructions if you want to keep your data, otherwise the flash will format your device and all data will be lost.

Note 2: If your bootloader is locked, your data will have to be wiped anyway. If you don’t want to lose your data, you need to back it up manually.

The “flash-all” script contains all of the commands necessary to flash the factory image onto your device. Before running it from the command line, we want to remove the flag that wipes your data.

In the file you extracted you’ll find two flash-all scripts as mentioned above. The flash-all script with the .bat extension works with the Windows command line while the .sh extension works with the Unix command line (OSX, Linux, etc). Open up the proper flash-all script with your favorite text editor and remove the “-w” from the file. “-w” is an ADB flag which wipes all of the user data (the stuff we want to keep).

Once you’ve made the change, save your file, and open up a command line program.

Run the script and install Lollipop

Before we run the script, we want to make sure that the device is visible to your computer. Type the command “adb devices”; if you see your device, you’re ready to go. If not, make sure your device has ADB debugging turned on.

If you don’t have debugging on, go to your device settings and check the USB debugging option in the “Developer options” section. If you don’t have “Developer options” in your settings, go to “About Phone” and repeatedly tap the build number until the “You are now a developer!” toast appears.

Next you need to boot into your bootloader. Run the command “adb reboot bootloader” to get there. Alternatively, you could hold the volume down and power keys simultaneously to boot into the bootloader.

Now point your command line to the file directory with the flash-all script. (Ex: cd /Users/<yourusername>/Downloads/hammerhead-lrx21o)

Once you’ve pointed to the correct directory, run your script.

On Unix, run “./flash-all.sh”

On Windows, run “flash-all.bat”

Now you should see the script running on-screen. It’ll take a little over five minutes for the image to install. Once the image is installed, the script will automatically reboot your phone. The first boot usually takes a while, so wait about 10 minutes before assuming you’ve entered a bootloop.

Note: Some users have had issues with the flash-all script not working on the Nexus 5 and 7, and if that’s the case with you, head over to the XDA-developers forum to read how to work around this.

After the phone boots, you should have Lollipop and, if you opted to modify the flash-all script, all of your data should be intact.

Stephen Hall contributed to this guide

FTC: We use income earning auto affiliate links. More.

Check out 9to5Google on YouTube for more news: