This guide can be easily adapted to other Nexus devices.
NOTE: You must have your bootloader unlocked. If you’ve never unlocked your bootloader, I don’t know there’s any way to do this without wiping your data.
WARNING: If you’re moving between ROMs, you generally should do a complete reset, including wiping data. Many users have reported problems going from Kitkat to Lollipop without wiping data and recommend a factory reset anyway. If you’re okay with wiping everything, you can simply use Google’s included flash-all scripts, or flash the userdata.img file yourself.
STEP 1: Install fastboot and related software
Fastboot is Google’s utility for flashing factory images. You can also use it to flash custom recoveries like TWRP and CWM. The standard way to get is is through Google’s Android SDK, but that’s a bit heavy-duty, so you can also download just the most important tools (fastboot and adb) separately, packaged by users. Here are some links:
Official Google Android SDK (cross-platform): http://developer.android.com/sdk/index.html#Other
Unofficial for Windows: http://developer.android.com/sdk/index.html#Other
Unofficial Mac/Linux: http://code.google.com/p/adb-fastboot-install/
Windows users might also need to install drivers: http://developer.android.com/sdk/win-usb.html (can any Windows users confirm whether it’s necessary?)
To check if the adb is detecting the device, just plug the USB to the computer and write the command inside a terminal:
$adb devices -l
You must see your device listed
Custom recoveries are extremely useful for rooting your phone, installing system tweaks, creating backups, and troubleshooting problems. There are two main options: TWRP and CWM. These are the instructions for the one I use:
- Download the latest TWRP image from:
- Unzip the image file inside the same folder
STEP 2: Prepare factory image
- Download the latest Nexus 5 factory image at https://developers.google.com/android/nexus/images#hammerhead
- Unzip it and open the resulting folder
- Unzip the “image-hammerhead-*.zip” file in the same folder
STEP 3: Flash the new image
- Connect your phone to your computer via USB, and enter the bootloader. You can enter the bootloader in two ways:
- by holding down the power and volume-down buttons to boot. Once you see the bootloader, you can release the buttons.
- Running the command:
$adb reboot bootloader
- The following syntax might be slightly different on Windows than on Mac or Linux, but basically the same. Anything you see in <> you need to replace, e.g. with the actual path to your factory image folder. The rest you should be able to copy and paste. (Tip: you can easily enter a folder path into your terminal/command prompt by simply dragging the folder onto your terminal window. This works on Mac, Windows, and the vast majority of Linux GUIs.) Enter these commands:
cd </path/to/downloaded files>
$fastboot flash bootloader bootloader-hammerhead-*.img
$fastboot flash radio radio-hammerhead-*.img
$fastboot flash boot boot.img
$fastboot flash cache cache.img
$fastboot flash system system.img
- If you DO NOT use a custom recovery (like TWRP or CWM), then also:
$fastboot flash recovery recovery.img
Don’t worry if you see messages like “target reported max download size of 1073741824 bytes”. Just wait and let it finish.
- If you want to use a custom recovery, see STEP 4.
- Reboot your phone and enjoy. It’s normal for the first boot to take a while, several minutes in case a a large update (from Kitkat to Lollipop up to 20 minutes).
BONUS STEP 4: Install custom recovery, root and custom kernel
- Boot your phone into the bootloader (see below)
- From the command line:
$fastboot flash recovery twrp-*-hammerhead.img
- Boot into recovery (use the volume up/down buttons to select recovery from the bootloader, then the power button to select)
- In TWRP, go to “mount”, then check “system”
- Optional: go back to the main TWRP screen, then click through Advanced > File Manager > system > recovery-from-boot.p > Rename File. Rename it to something like recovery-from-boot.p.bak (this is necessary to ensure that Android doesn’t overwrite your custom recovery with the stock recovery on startup)
- In TWRP, select “Install”, then navigate to wherever you saved the TWRP zip (probably in /sdcard/Download)
- Swipe to confirm flash
- In case you want to install a custom kernel (recommended), go to the next paragraph
- Reboot your phone
WARNING: Installing a custom kernel can broke the system. If you get strange behaviours, like infinite boot looping, repeat the procedures from STEP 2, and try to not install the custom kernel (or try a different one).
- Download a custom kernel on your phone. ElementalX and Franco Kernel are quite popular and can be downloaded from their websites. I am using ElementalX.
- In TWRP, select “Install”, then navigate to wherever you saved the kernel zip (probably in /sdcard/Download)
- Swipe to confirm flash.
- System reboot. In case you choose ElementalX, don’t let twrp fix root when it prompts!