This is a simple step-by-step guide for flashing a minor update (e.g., monthly security update) and re-rooting for Nexus devices.
This is meant to be more of a reminder checklist for those who do this semi-regularly; if you haven't done this before or don't know much about adb
and fastboot
, you should probably find a more detailed guide (see here for the Nexus 5X or here for the Nexus 6P).
The easiest way to update your nexus device manually is through the OTA downloads provided by Google.
-
Download the OTA Zip for your phone.
-
Reboot into Recovery
adb reboot recovery
-
Put your device into sideload mode. For TWRP, choose "Advanced" > "ADB Sideload," and swipe to prepare for sideload.
-
Sideload the OTA!
adb sideload path/to/ota.zip
-
You're done! Unfortunately, you will most likely need to reboot before sideloading SuperSU (see below).
If you wish to "dirty" flash the old-fashioned way, you can download the full factory images and flash them without wiping user data.
-
Download the latest image for your phone from Google Nexus Factory Images page
-
Extract zip and edit
flash-all.sh
to remove-w
from theupdate
command:$ sed -i -e 's/ -w//g' flash-all.sh
-
Reboot to the bootloader
$ adb reboot bootloader
-
Run the update script:
$ ./flash-all.sh
Once the phone reboots, the update should be installed.
Alternatively, the below script will run the above in one command:
#!/bin/bash
#
# A convenience script for flashing a minor update for a Nexus device. Only use this for minor updates
# (e.g., monthly security updates). Download the latest image for your phone from:
# https://developers.google.com/android/nexus/images
#
# Usage: ./flash-android.sh path/to/image.zip
set -e # exit on failure
zipfile=$1
(
mkdir -p tmp-android-flash
echo "Extracting $zipfile..."
tar xzf $zipfile -C tmp-android-flash/ # extract tar!
cd tmp-android-flash
cd $(ls -d */) # cd to the only folder that was extracted
echo "Removing -w option from flash-all script..."
sed -i -e 's/ -w//g' flash-all.sh # remove the -w from the `fastboot update` command
sed -i -e 's/ -w//g' flash-all.bat # might as well do the same for Windows
echo ""
read -p 'Ready to flash. Is the device connected and ready to go? [y/n] ' answer
if [[ $answer == 'n' ]] || [[ $answer == 'no' ]]; then
exit 1
fi
echo "Rebooting to bootloader..."
adb reboot bootloader
sleep 10
echo "Flashing.................."
./flash-all.sh
echo ""
echo "Done flashing; cleaning up."
cd ../../
rm -rf tmp-android-flash;
)
To (re-)root your device:
-
Download TWRP Recovery for your phone model.
-
Reboot to bootloader
$ adb reboot bootloader
-
Install TWRP Recovery and reboot bootloader.
$ fastboot flash recovery path/to/TRWPRecovery.img $ fastboot reboot bootloader
-
Use the volume and power keys to select "Recovery." If TWRP asks for a password or says it can't decrypt, press cancel and continue. Select "Advanced," then "ADB Sideload." If/when asked, accept to whipe cache and dalvik.
-
Once ADB Sideloading is turned on, run the following and then reboot system:
$ adb sideload path/to/superSU.zip
Note: If TWRP asks to root device, do not accept. As of this writing, it is incompatible with Systemless Root and might break something.
-
To ensure SafetyNet passes on systemless root,
adb shell
and run the following (per these instructions):su # will need to accept SuperSU permission on device chmod 751 /su/bin rm /su/xbin_bind echo SYSTEMLESS=true > /data/.supersu # if not done already echo BINDSYSTEMXBIN=false >> /data/.supersu # if not done already
Note: This may no longer be necessary with the lastest SuperSU
-
Download a hosts file and save it to your phone
curl https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts > hosts # Optional - remove any blocked hosts you want to allow, if any sed -i '/heapanalytics/d' hosts adb push -p hosts /sdcard/Download/ rm hosts
-
Update the phone's hosts file with this one:
adb shell su # become root (accept confirmation on device) mount -o remount,rw /system # remount system as writeable cd /system/etc/ cp hosts hosts.bkp # make a backup, just in case chmod a+r hosts.bkp # bkp file should have same permissions # Perform the udpate! Append everything in our new hosts file to our existing cat /sdcard/Download/hosts >> hosts mount -o remount,ro /system # remount as normal exit # unroot exit # good bye
Maybe want to change step 2 for Super SU for this link:
http://forum.xda-developers.com/apps/supersu/2014-09-02-supersu-v2-05-t2868133
Bugfixes and the like since 2.60
Also in the removal of /su/xbin_bind: