The first time you root a Nexus 5, you must wipe the device in order to unlock the boot loader. And once a device is rooted, OTA software updates won’t install because the modified boot loader is detected. However, it’s still possible to get software updates for your rooted Nexus 5, and no additional wiping is necessary.
1. Phone must have unlocked bootloader (use BootUnlocker to avoid having to wipe your phone).
2. USB debugging must be turned on
3. Turn off phone and make sure power is disconnected. Then, start up phone into the fastboot bootloader by holding VOL-DOWN and POWER at the same time. Finally, connect the USB cable between the phone and your computer.
4. Download firmware from https://developers.google.com/android/nexus/images
i.e. 5.1.1 (LMY47B) for Nexus 5
5. Unpack the archive:
~/ $ tar -zxvf hammerhead-lmy48b-factory-596bb9c1.tgz
6. Unzip the image archive:
~/ $ cd hammerhead-lmy48b/
~/hammerhead-lmy48b $ unzip image-hammerhead-lmy48b.zip
7. Flash the baseband radio firmware:
~/hammerhead-lmy48b $ fastboot flash radio ./radio-hammerhead-m8974a-2.0.50.2.26.img
target reported max download size of 1073741824 bytes
sending 'radio' (45425 KB)...
OKAY [ 1.889s]
writing 'radio'...
OKAY [ 3.132s]
finished. total time: 5.021s
8. Reboot into fastboot bootloader:
~/hammerhead-lmy48b $ fastboot reboot-bootloader
9. Update the recovery image
~/hammerhead-lmy48b $ fastboot flash recovery ./recovery.img
target reported max download size of 1073741824 bytes
sending 'recovery' (9696 KB)...
OKAY [ 0.552s]
writing 'recovery'...
OKAY [ 0.821s]
finished. total time: 1.373s
10. Update the boot image:
~/hammerhead-lmy48b $ fastboot flash boot ./boot.img
target reported max download size of 1073741824 bytes
sending 'boot' (8980 KB)...
OKAY [ 0.561s]
writing 'boot'...
OKAY [ 0.776s]
finished. total time: 1.337s
11. Update the system image:
~/hammerhead-lmy48b $ fastboot flash system ./system.img
target reported max download size of 1073741824 bytes
erasing 'system'...
OKAY [ 1.067s]
sending 'system' (1021744 KB)...
OKAY [ 40.235s]
writing 'system'...
OKAY [ 69.108s]
finished. total time: 110.411s
12. Reboot into the newly upgraded software:
~/hammerhead-lmy48b $ fastboot reboot
(note: you should see “Android is upgrading…” as it boots into the new software for the very first time)
At this point, your phone is now upgraded. However, you still need to re-root it:
With USB debugging still enabled (for now), download the CF-Auto-Root for your device (i.e. Nexus 5 link)
A. Unzip the CF-Auto-Root archive
~/ $ mkdir autoroot
~/ $ cd autoroot
~/autoroot $ unzip ../CF-Auto-Root-hammerhead-hammerhead-nexus5.zip
B. Power off your phone again, and with USB cable unplugged, enter fastboot bootloader (VOL-DOWN and POWER)
C. Connect the USB cable again
D. Ignoring the scripts and copies of fastboot bundled with CF-Auto-Root, use your normal fastboot installation to temporarily boot once into into the the custom boot firmware
~/autoroot $ fastboot boot image/CF-Auto-Root-hammerhead-hammerhead-nexus5.img
E. Phone should boot into a red android screen as SuperSU installation is performed (this boot image is not being installed, rather, your phone is booted into it one time so that it can perform operations on your boot loader). Phone will automatically reboot when you are done.
F. You are now booted into your upgraded firmware, which has also been rooted.
At this point, verify that you indeed have root.
G. Run BootUnlocker to re-lock your boot loader (and optionally reset the Tamper flag). This protects your device against unauthorized access.
H. Turn off USB debugging as well for security. (USB debugging should ONLY be enabled when you are performing fastboot/adb commands — it should be disabled during normal operation).