§ (Skip to the Process section for just the tl;dr or full instructions)
Like many people with Android phones, I keep my Google Pixel 4a rooted to gain greater control over the device. Though some reasons to root (e.g. ad blocking, YouTube Vanced) have developed more viable non-root alternatives over time, I still find that I enjoy:
- automatic updates for F-Droid apps through the privileged extension
- charge limiting via the Advanced Charging Controller Magisk module
- thorough (system app and special) backups using oandbackup/oandbackupx
- less limitations on programmatic access through Tasker (for example, I previously used this ability to automatically turn location on/off in a custom anti-theft solution, though I have since stopped maintaining this method)
However, rooting can make the update process more complex, so I am sharing the process I use to update. I describe two methods: a faster method which I have been using without issue and a "safer" method I previously used which involves temporarily unrooting your phone (where "safer" means "with minimal chance of bootlooping/bricking"). Note that this article assumes you have an unlocked bootloader and are already rooted with Magisk. Some other devices do not allow bootloader unlocking and thus require exploits to gain root. The commands specified on the computer side are for a Linux system, but the process should be the same for a Windows computer with exceptions for using an Administrator account instead of sudo
, executing flash-all.bat
instead of flash-all.sh
, and running different tools to replace the boot.img in the image-$MODEL-$BUILD_NUMBER.zip. Also note: at least on Arch Linux, you can avoid running the adb
commands with sudo
by adding your user to the adbusers
group if you wish.
§ Disclaimer
These instructions were written for a Pixel 4a and have worked for me for the past several months. While I have researched this topic to the best of my ability and these directions should work for other Pixel 4a or Boot Method C devices (terminology explained in the next section), I make no guarantees for any device and take no responsibility for any issues you may encounter.
§ Rooting Background
Rooting involves modifying parts of the Android boot chain so as to gain superuser access. Because rooting modifies critical files and the methods used are not officially supported by vendors, rooting (and by the same token custom ROMs) can interfere with updates and sometimes cause bootloops, bricking, or other instability. Thus, having a clear set of update steps to follow can be helpful in avoiding any issues.
Modern root methods are "systemless" and avoid modifying the system partition because not having to reflash system makes it easier to update. Since the linked post was written, Magisk has become the go-to rooting tool (read The Magisk Story from the creator). Additionally, the Android boot process has changed quite a bit. A good place to learn about these changes as they apply to rooting is the Android Booting Shenanigans page in the Magisk documentation.
As described in the linked Magisk documentation, almost all old devices used Boot Method A, Boot Method B was introduced with the first A/B devices, and modern A/B devices use Boot Method C. The standard root method for Boot Method A devices was to replace the stock recovery with a custom recovery (such as TWRP) and flash a zip file which would perform the necessary modifications to install Magisk. This method is how I rooted my previous phone, the Motorola Moto G5+. Since stock updates required a stock recovery, you had to uninstall Magisk and flash stock recovery (and likely other partitions depending upon the exact phone), install the OTA (Over-The-Air) update, reinstall a custom recovery, then re-root in order to update your device.
Boot Method B devices can get complex (and make up the majority of the caveats on the Installation page in the Magisk documentation), but for the purposes of this article we are mostly interested in Boot Method C devices which includes the Pixel 4a.
Since Boot Method C devices are A/B devices, updates are applied to the inactive slot. It used to be possible to restore the original boot images for both slots in Magisk Manager, take the update, patch the updated boot partition in the inactive slot, and then reboot to the updated build number with Magisk installed, making rooted updates a 1-reboot process. However, as noted on the OTA Upgrade Guides page in the Magisk documentation, Google has since changed the OTA process which makes installing Magisk to the inactive slot impossible. "Safer" updates now require 3 reboots similar to the Boot Method A process, but are simpler in that only the boot partition needs flashed and no interaction with a recovery image is needed. There is also currently a faster method which only needs 1 reboot. The full process for both methods of updating Boot Method C devices such as the Pixel 4a is covered in the next section.
§ Process
§ tl;dr
-
§ Faster Way
- download and patch factory image for new build number
- flash PATCHED factory image for new build number
-
§ Safer Way
- flash stock boot.img for CURRENT Android build number
- update (OTA or sideload)
- download, patch, flash boot.img for NEW build number
Magisk documentation or XDA for questions.
§ Detailed Steps
-
§ Faster Way
Flash a new patched factory image over the existing one. I and many others online have successfully used this method. However, Google only recommends that you flash a factory image while also wiping userdata as part of a factory reset. The method described here explicitly avoids wiping userdata by modifying a script. Even though it works fine for most people, I have yet to find a thorough analysis of the repercussions of this guideline-breaking modification, hence why I consider the other method to be "safer".
-
download and extract STOCK factory image for new build number
- on computer, get stock factory image (use the Download Link for the zip file, not Flash) for latest build number for your device on google's factory images page
- extract the downloaded $MODEL-$BUILD_NUMBER-factory-$COMMIT_HASH.zip and navigate to the resulting folder
- run
unzip image-$MODEL-$BUILD_NUMBER.zip boot.img
to extract only the stock boot image
-
patch boot.img for new build number
- plug in phone, make sure USB mode is set to file sharing on the phone, that USB debugging is enabled and the current computer is approved, and that
sudo adb devices
on the computer returns the phone's serial # (NOTE: notice the sudo) - run
sudo adb push ./boot.img /sdcard/Download/
- on the phone, ensure boot.img shows up under the Download folder in the Files app
- open magisk manager app, check for app updates. if the app updates, reboot (NOTE: if the patching process or ensuing reboot fails, check the Pixel 4a rooting thread on XDA to see if you need to change to a specific update channel and return to this step to get boot.img patching to work)
- in magisk manager select "Install", select "Select and Patch a File", select the boot.img under the Download folder, select "LET'S GO", let it run until it says "All done!", then close magisk manager
- on the computer, run
sudo adb pull /sdcard/Download/magisk_patched.img ./
- plug in phone, make sure USB mode is set to file sharing on the phone, that USB debugging is enabled and the current computer is approved, and that
-
patch factory image for new build number with patched boot.img
- copy the stock boot image somewhere else if you wish to keep it
- rename the patched boot image to the original filename by running
mv magisk_patched.img boot.img
- run
zip image-$MODEL-$BUILD_NUMBER.zip boot.img
to replace the stock boot image with the patched boot image in the factory image
-
flash PATCHED factory image for new build number
- edit
flash-all.sh
to remove the-w
(wipe) from thefastboot -w update
command - run
sudo adb reboot bootloader
- let phone boot to bootloader, then verify that
sudo fastboot devices
lists the phone's serial # - run
sudo ./flash-all.sh
- run
sudo fastboot reboot
, then let the phone boot normally
- edit
-
§ Safer Way
Take the update while unrooted and via the officially supported methods.
-
(optional) if using MagiskHide Props Config to change the device fingerprint (an older method to force BASIC key attestation and thus pass the ctsProfile check of SafetyNet, since replaced by the Universal SafetyNet Fix module), follow these steps to temporarily reset props and prevent Android from potentially downloading an incorrect OTA update:
- open terminal on the phone, run
su -c props
- select the
r
(reset) option - reboot when prompted
- open terminal on the phone, run
-
flash stock boot.img for CURRENT Android build number
- plug in phone, make sure USB mode is set to file sharing on the phone, that USB debugging is enabled and the current computer is approved, and that
sudo adb devices
on the computer returns the phone's serial # (NOTE: notice the sudo) - on computer, open terminal and navigate to directory with boot images for the CURRENT build number (for me, under
~/Documents/tech/devices/phone/pixel4a/$BUILD_NUMBER
) (NOTE: if you do not have these files available, follow steps 3.1 through 3.5 but for the CURRENT build number) - run
sudo adb reboot bootloader
- let phone boot to bootloader, then verify that
sudo fastboot devices
lists the phone's serial # - run
sudo fastboot flash boot boot.img
- run
sudo fastboot reboot
, then let the phone boot normally
- plug in phone, make sure USB mode is set to file sharing on the phone, that USB debugging is enabled and the current computer is approved, and that
-
update
two options for this step, pick one. I previously used this method with the OTA update option
-
OTA update
- on the phone, go to settings -> system -> advanced, select and install system update, reboot when prompted
-
sideload update
- follow the official sideload update instructions
-
-
download stock boot.img for NEW build number
- go to phone settings, note NEW build number
- on computer, get stock image (use the Download Link for the zip file, not Flash) for NEW build number on google's factory images page
- extract the downloaded $MODEL-$BUILD_NUMBER-factory-$COMMIT_HASH.zip
- in the folder extracted from the downloaded $MODEL-$BUILD_NUMBER-factory-$COMMIT_HASH.zip, ignore the bootloader-$MODEL-$VERSION.img and radio-$MODEL-$VERSION.img files and extract the image-$MODEL-$BUILD_NUMBER.zip
- navigate to the folder extracted from the image-$MODEL-$BUILD_NUMBER.zip
-
patch boot.img for NEW build number
- run
sudo adb push ./boot.img /sdcard/Download/
- on the phone, ensure boot.img shows up under the Download folder in the Files app
- open magisk manager app, check for app updates. if the app updates, reboot (NOTE: if the patching process or ensuing reboot fails, check the Pixel 4a rooting thread on XDA to see if you need to change to a specific update channel and return to this step to get boot.img patching to work)
- in magisk manager select "Install", select "Select and Patch a File", select the boot.img under the Download folder, select "LET'S GO", let it run until it says "All done!", then close magisk manager
- on the computer, run
sudo adb pull /sdcard/Download/magisk_patched.img ./
- run
-
flash patched boot.img for NEW build number
- run
sudo adb reboot bootloader
- let phone boot to bootloader, then verify that
sudo fastboot devices
lists the phone's serial # - run
sudo fastboot flash boot magisk_patched.img
- run
sudo fastboot reboot
, then let the phone boot normally - on phone, open settings and verify new build number
- open magisk manager, verify that the "Installed" property listed under "Magisk" gives a version number as opposed to "N/A"
- run
-
(optional) if you disabled MagiskHide Props Config and wish to re-enable:
- check to make sure you still have to do this by opening magisk manager on phone and selecting "Check SafetyNet" to see current status. if fails:
- re-enable by opening terminal on phone, running
su -c props
and selecting desired options, then rebooting when prompted - verify that SafetyNet now passes
- re-enable by opening terminal on phone, running
- check to make sure you still have to do this by opening magisk manager on phone and selecting "Check SafetyNet" to see current status. if fails:
§ After
You can now unplug your phone, which should be updated to the latest version and still rooted. I recommend that you keep the stock and patched boot.img for the next round of updates, but you can get rid of the other files from the factory image.