[Nexus 5 General] RunasSudo:
Preamble

As the title suggests, I had a Nexus 5 running stock Android 5.0, with root and TWRP, and wanted to update to Android 5.0.1 (without losing all my data, of course). I couldn't find any guides for my particular circumstances, so after working out how to do it myself, I thought I'd share my method.

Note: This guide is not for the uninitiated. Be prepared to Google something for yourself if you don't understand it.

Prerequisites

Before starting this guide, you should have:

A Nexus 5 that running stock Android. The presence of root/Xposed/custom recovery (maybe custom kernels?) shouldn't be relevant, but I can't vouch for the efficacy of this guide if you've done something obscure to your install.

Android SDK tools, specifically the ADB and fastboot binaries. Additional USB drivers may be required on Windows.

The factory image for the Android version you are currently running.

1. Uninstall root and other /system modifications

If you have rooted your Android, and/or installed BusyBox, Xposed or other modifications to /system, you will need to uninstall these modifications. Failing to do so will cause the OTA to complain that there's something funky going on in your /system partition.

You may be able to manually uninstall each of these modifications, but this was not enough for my install – doing a ‘Full unroot’ in SuperSU still left behind files in /system. The easiest way to uninstall all /system modifications is to reflash the /system partition.

Extract the Nexus 5 factory image (e.g. hammerhead-lrx21o-factory-01315e08.tgz), yielding a directory with files such as flash-all.bat and image-hammerhead-XXXXXX.zip. Do not use the flash-all script, as this will unnecessarily wipe all data on the device.

Extract the image-hammerhead-XXXXXX.zip file, specifically the system.img file.

Open a command prompt/terminal window.

Connect the phone to the computer with a USB cable.

Boot the phone into the bootloader.

Method 1: Power down the phone, then hold VolUp + VolDn + Power until the phone boots into the bootloader.

Method 2: From the terminal, run adb reboot bootloader while the phone is still powered on.

From the terminal, run fastboot flash system /path/to/system.img.

2. Uninstall any custom recovery

Custom recoveries don't seem to support OTA updates, making it necessary to uninstall the custom recovery by reflashing the stock recovery.

Extract the recovery.img file from the factory image, as in Part 1.

Open a command prompt/terminal window, connect the phone to the computer, and boot into the bootloader, as in Part 1.

From the terminal, run fastboot flash recovery /path/to/recovery.img.

Optional: Reflash boot.img and/or cache.img

Some users have reported that reflashing system.img was not sufficient, and that reflashing boot.img and/or cache.img was also necessary. I did not have this problem, but if you do:

Extract the boot.img and/or cache.img files from the factory image, as in Part 1.

Open a command prompt/terminal window, connect the phone to the computer, and boot into the bootloader, as in Part 1.

From the terminal, run fastboot flash boot /path/to/boot.img.

From the terminal, run fastboot flash cache /path/to/cache.img.

3. Apply the OTA update

The simple part. In the bootloader, use the VolUp/VolDn buttons to select ‘Start’, then press the Power button, to reboot into Android. Follow the system update instructions to install the OTA update.

4. Reflash the custom recovery and re-root

Also self-explanatory.