Android - OTA Update on a rooted Nexus5 with Custom Recovery and Kernel

I think your best bet is to unroot your device and restore it to stock. This means stock ROM, recovery and kernel, and you will be unrooted. This is often referred to as "flashing a factory image", sometimes incorrectly. But that's what we're going to do!

Note: This process will wipe your phone completely. Backup your storage before you continue. I am also not responsible if anything goes wrong. Ensure you verify this is the correct device and code name (hammerhead) before you proceed.

From this excellent XDA thread:

For this process, you will need to:

Install adb and fastboot drivers. To do this, use this simple program

For MAC users *Note: MAC users will have to write ./ before every command in this thread. For example : ./fastboot flash recovery recovery.img

Linux users should know their stuff

Download the latest factory images from here

Extract the archive you downloaded (Use WinRAR). It should look like this: enter image description here

Unlock your bootloader (In case you haven't already) Link here

Flashing the factory images

  • Power off your phone.

  • Boot it in fastboot by pressing and holding Power Button + Volume Down at the same time.

  • Connect your phone to your PC through your USB cable.

  • Execute the flash-all.bat script (for Windows) or flash-all.sh(for MAC and LINUX) in the folder where you extracted the factory images. !! For MAC: You'll have to edit the flash-all.sh, and add "./" before every fastboot command.

  • Wait for everything to flash.

  • After everything finished, select "Recovery" using the volume buttons.

  • When a small dead Android appears, press Power Button + Volume UP.

  • Select "Wipe data/factory data reset"

  • Reboot. Your phone should be stock.

Note: The XDA Thread has further detail on re-locking the device and resetting the tamper flag should you need to claim warranty. It's a bit outside the scope of this answer, but it might be of use!

Note 2: Some Nexus devices will show as having 16 Gb after this on the 32 Gb model. The below is a fix via cmd:

fastboot erase boot
fastboot erase cache
fastboot erase recovery
fastboot erase system
fastboot erase userdata

fastboot flash bootloader C:/image-hammerhead-krt16m/bootloader.img
fastboot reboot-bootloader
fastboot flash radio C:/image-hammerhead-krt16m/radio.img
fastboot reboot-bootloader
fastboot flash system C:/image-hammerhead-krt16m/system.img
fastboot flash userdata C:/image-hammerhead-krt16m/userdata.img 
(Note: this command will wipe your device (including /sdcard), EVEN if your bootloader is already unlocked.)

fastboot flash boot C:/image-hammerhead-krt16m/boot.img
fastboot flash recovery C:/image-hammerhead-krt16m/recovery.img

Another option, without wiping any data, is to

  • when an OTA update is available, get the direct link and download the zip file to your PC,
  • download the latest image version of your custom recovery (eg TWRP) and the latest SuperSU zip to your PC
  • connect your device to your PC and reboot into bootloader mode
  • then dirty flash the stock boot, recovery & system partitions of your current Android version,
  • in stock recovery mode, install the OTA zip via adb sideload update.zip,
  • reboot into bootloader mode
  • flash back your custom recovery image
  • (alternatively) flash your custom kernel
  • reboot into recovery mode
  • in the custom recovery mode, root the device via adb sideload UPDATE-SuperSU-vX.X.zip
  • now clear cache and dalvik-cache and reboot the system

Done. OTA applied and you can just pick up from where you left.

This is not the only method, of course, and is not recommended for major version updates. But for minor version updates, this is, IMHO, preferable to dirty flashing the new system and to any method that require a data wipe.

A very detailed step-by-step version of this solution can be found here: https://gist.github.com/eyecatchup/ec0a852428c19705380e