Skip to content

Instantly share code, notes, and snippets.

@eyecatchup
Last active November 1, 2023 08:35
  • Star 55 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save eyecatchup/ec0a852428c19705380e to your computer and use it in GitHub Desktop.
A step-by-step guide how to manually flash the Android 5.0.1 (LRX22C) OTA-Update on a Nexus 5 with modified system (custom recovery/kernel, rooted, modified framework etc.)..

Update: For those interested, here's the version for updating from Android 5.1.0 (LMY47D/LMY47I) to Android 5.1.1 (LMY48B):
https://gist.github.com/eyecatchup/dab5cf7977008e504213


  UPDATE `NEXUS 5` 
     SET `VERSION`='5.0.1', `BUILD`='LRX22C', `RECOVERY`='CUSTOM', `ROOTED`=1 
   WHERE `VERSION`='5.0' && `BUILD`='LRX21O' && `RECOVERY`='CUSTOM' && `ROOTED`=1 
         && `WANNA_KEEP_USERDATA`=1;

A manual OTA for rooted hammerheads, quasi.

When you tampered with the Android system, you can't install OTAs; installation fails. Sometimes it's enough to flash the stock recovery to use adb sideload update.zip, but often, especially when you tampered a lot, this also fails.

Even after unrooting and flashing stock boot, recovery and cache it can fail. So one might ask whether the only way is to do a clean install using the latest factory image instead. For those who ask themselves this question: Before you do so, take a minute and read on.


This document describes how I successfully updated my Nexus 5 from stock Android 5.0 (LRX21O) with TWRP 2.8.1.0 and rooted with SuperSU to Android 5.0.1 (LRX22C) with TWRP 2.8.2.0 and rooted with SuperSU - without loosing user data.

NOTE: The steps outlined in this document assume the Android SDK to be installed on your PC and the adb, fastboot and android.[bat|sh] to be in your PATH variable! Oh, and if it burns down your house, it's not my fault. Proceed at own risk.

Download & prepare files

  • Download OTA zip from Google's servers to your PC.
    http://goo.gl/dx2JoM - signed-hammerhead-LRX22C-from-LRX21O.785a2f7a.zip

  • Rename the downloaded zip to 'update.zip' (without the quotes (and if you're on windows and known file extension are hidden, make sure you not end up with update.zip.zip)).

  • To the same folder, download the latest SuperSU flashable zip.
    http://goo.gl/XRK49m - UPDATE-SuperSU-v2.40.zip

  • To the same folder, download the latest TWRP recovery image for hammerhead.
    http://goo.gl/9GrBPl - openrecovery-twrp-2.8.4.0-hammerhead.img

  • To the same folder, download the 5.0 factory image tgz archive from Google's servers.
    http://goo.gl/Z8ITiM - hammerhead-lrx21o-factory-01315e08.tgz

  • From the 5.0 tgz archive extract the recovery.img, boot.img and system.img files to the same directory where your downloads are located.
    (Tip: With 7zip, for example, you can 'internally' open the archives within the archive and extract just the files you need. The same is possible with command line tools, of course.)

The directory structure should look like this now:

..
boot.img
openrecovery-twrp-2.8.4.0-hammerhead.img
recovery.img
system.img
update.zip
UPDATE-SuperSU-v2.40.zip

Time for the command line..

Open a terminal on your PC and cd into the directory where your downloaded files are located. Now go on by running the commands in the terminal as follows (type only those lines prefixed with '> ', but without actually typing the '> '!).

Update platform tools
# On Windows:
> android.bat update sdk -u -t platform-tools,tools
# On Linux/Mac:
> android.sh update sdk -u -t platform-tools,tools

You may need to accept a license agreement. Type 'y' and hit enter.

Do you accept the license 'android-sdk-license-5be876d5' [y/n]: y
Installing Archives:
  Preparing to install archives
  Downloading Android SDK Tools, revision 24.0.2
  Installing Android SDK Tools, revision 24.0.2
    Installed Android SDK Tools, revision 24.0.299%)
    Done. 1 package installed.</code>
Update adb
# On Windows:
> android.bat update adb
# On Linux/Mac:
> android.sh update adb

If adb was updated, command line will ask you to restart it. Do so.

adb has been updated. You must restart adb with the following commands
      adb kill-server
      adb start-server

--

Now, we're finally ready to go..

Time for flashing..

Connect your device (USB debugging enabled, of course) to your PC.

Back at your terminal, go on by running the commands as follows (type only those lines prefixed with '> ', but without actually typing the '> '!).

# Make sure the device is recognized
> adb devices

# Boot into bootloader mode
> adb reboot bootloader

# In bootloader mode, make again sure the device is recognized
> fastboot devices

# Flash stock LRX21O recovery image
> fastboot flash recovery recovery.img

# Flash stock LRX21O system image
> fastboot flash system system.img

# Flash stock LRX21O boot image
> fastboot flash boot boot.img

When the last flash is confirmed, use the volume rockers to choose 'Recovery mode' and confirm with the power button.

When you see the little Android lying with the red triangle warning sign on it, hold the power then press the volume up button to get to the recovery options.

When you got to the recovery options, select 'apply update from ADB' using the volume rockers again and press the power button to choose it. When the device says it's awaiting commands, type from the PC's command line:

adb sideload update.zip

When OTA update successfully installed, select 'reboot bootloader' from the recovery options again using the volume rockers and press the power button.

Back in bootloader mode, type from the PC's command line:

fastboot flash recovery openrecovery-twrp-2.8.4.0-hammerhead.img

When the flash is confirmed, use the volume rockers to choose 'Recovery mode' and confirm with the power button.

Now in the TWRP recovery menu, choose 'Advanced' > 'adb sideload'. Check both option, clear 'Dalvik-Cache' and 'Clear Cache' and swipe the bar to start sideload mode. When the device says it's awaiting commands, type from the PC's command line:

adb sideload UPDATE-SuperSU-v2.40.zip

When done, confirm to reboot system. Finished. Mission completed.

You're now on 5.0.1 with your custom recovery, rooted and can pick up from where you left.

PS: First boot, as always, will take some minutes.

@DIGINEX-zz
Copy link

My ADB issue is solved at last, Please fix the TWRP version to 2.8.1.0 from 2.8.2.0, as it may not push out of the curtains for most of the users. I panicked at very similar point and end up spending a few hours figuring up this!

@nathantsoi
Copy link

thx @eyecatchup, worked great. I put the whole thing in a bash script if anyone else needs to do this: https://gist.github.com/nathantsoi/e36c5a2f2e94ce5ebb85

@eyecatchup
Copy link
Author

seems useful to me, @nathantsoi. ty

@consultant1027
Copy link

Can someone confirm what (if anything) should be changed in the instructions to go from 4.4.4 to 5.0.1?

@djhworld
Copy link

@consultant1027

I just did exactly this but I played it safe by upgrading to 5.0 first, my setup was as follows

  • Nexus 5 running 4.4.4
  • TWRP 2.6 installed.

Disclaimer: please be careful, this worked for me but might not work for others!

Upgrading to 5.0.0

Follow the instructions here, these are a fork of the instructions above, the difference is you are downloading the 5.0.0 OTA update and 4.4.4 factory image instead of the 5.0.1 OTA update and 5.0 factory image

Upgrading to 5.0.1

Once I was on 5.0.0, I performed everything above "as is" and it worked great!

Thanks @eyecatchup !!

@Karmac
Copy link

Karmac commented Feb 7, 2015

Awesome working perfectly! thanks!

@minj2me
Copy link

minj2me commented Feb 16, 2015

UPDATE-SuperSU-v2.40.zip was working perfectly, thank you!

@davidramos-om
Copy link

Thanks a lot, I was thinking my nexus died cause I deleted all data trying to root in last week (Sistem, Recovery,etc.)

Now it works.

@leewc
Copy link

leewc commented Feb 28, 2015

This was great, thank you! Also note to some people who might get stuck on this part:

"When you see the little Android lying with the red triangle warning sign on it, hold the power then press the volume up button to get to the recovery options."

Notice that the tutorial mentions HOLD the power THEN press the volume up, if you hold power AND volume up you'll just do a force reboot. (at that time just do adb reboot bootloader again)

EDIT: also, if you happen to receive an error about not having permissions when in stock recovery:

adb sideload update.zip
loading: 'update.zip'
error: insufficient permissions for device

Just do 'adb kill-server' then 'sudo adb start-server' which if it says adb command not found then manually point to the absolute path of adb, for example mine was in /Development/android/android-sdk-linux/platform-tools/adb

good luck!

@ev0rtex
Copy link

ev0rtex commented Mar 12, 2015

FYI, this is actually a pretty generic process and the same process will work with future updates and even on the Nexus 6 (except that download links will vary obviously). I just installed the 5.1 update (LMY47D) on my Nexus 6 using the same procedure. The only catch is that I had to unplug/replug my USB cable whenever I entered sideload mode so that adb would detect it.

@Leomosantos
Copy link

My Nexus 5 is running Android 5.0.1, with TWRP, Xposed and ElementalX kernel. Will I be able to update to 5.1 following these steps?

@jacobsin
Copy link

jacobsin commented Apr 2, 2015

Thanks! Works for updating from 5.0.1 to 5.1.

@apporc
Copy link

apporc commented Apr 9, 2015

I have just found that, the radio is needed to be rolled back too.

@singles
Copy link

singles commented Apr 23, 2015

Thanks you for this tutorial. Just used it (with minor changes) to update Nexus 4 from 5.0.1 to 5.1.0. 🍻

@mcampbell
Copy link

This worked fantastically well. I was stuck with a "release-keys" not matching issue trying to sideload 5.1.1 over 5.1 (a problem I've had since 4.4), and finally found this page and was able to get past it.

Thanks so much for putting this out in such a straightforward manner.

@anthonybaldwin
Copy link

Found this searching how to sideload the 5.1.1 OTA update to my rooted Nexus 6. Worked perfectly. Thank you!

@yuvilio
Copy link

yuvilio commented Jun 4, 2015

Seems like twrp dropped the 'openrecovery' prefix. For my my 5.1.1 update on Nexus 5, the latest file was 'twrp-2.8.6.1-hammerhead.img' . The sideload command works fine. Thanks for this.

@eyecatchup
Copy link
Author

For those interested, here's the version for updating to Android 5.1.1 (LMY48B): https://gist.github.com/eyecatchup/dab5cf7977008e504213

@eyecatchup
Copy link
Author

If you run into the following error message:

target reported max download size of 1073741824 bytes
error: cannot load 'system.img'

Just use: fastboot flash -S 512M system system.img

(via)

@albinsuresh
Copy link

Can someone tell me where you get the OTA update links from? People have posted links for specific versions. But is there any generic URL or something where I can find OTA zips for different versions or rather the most recent version?

@hackel
Copy link

hackel commented Aug 24, 2015

Just keep in mind this will still erase any customizations you may have made... build.prop, Xposed, busybox, init.d, etc. The Android update system really is crap.

@INFINITEKIFF
Copy link

My Nexus 5 is running Android 6.0.1, with TWRP, Xposed and ElementalX kernel. Will I be able to update to the 2016-10 security patches following these steps? sick of getting the notifcations which obviously dont go away until you apply the patch. obviously being a noob I discovered I cant apply these patches without first losing root since ota replaces twrp custom recovery right? or am I getting confised, theres so many steps?! I know last time I managed to do it from lollipop to MM but that wasnt a security patch update, so somehow updating the OS seemed easier, this whole security patch thing seems confusing and daunting?? what about if I have Flashfire installed, sint that supposed to retain Root? someone out there with a good idea about how to proceed safely? thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment