OTA update unroots the OnePlus 6

After an OTA update to the latest e-0.16-20210414110657 on my OP6 that had already been upgraded to Android 10, I was able to reboot successfully into the new updated version, but I discovered that my root privileges had been removed.

The operation was much longer than on another Samsung A3 device which preformed the update in the classic way through a TWRP recovery. On the OP6, though, there was a long preparation period with no sign of rebooting to recovery so I presume that the installation was on the inactive slot as this is an A/B device.

Unfortunately, on discovering that the OTA update had replaced my TWRP with the /e/ recovery I realised this would not work as it doesn’t have a flashing tool, apart from the update. So I decided to use fastboot to reflash the TWRP recovery and then flash Magisk. However, the result was a failure to reboot correctly. Luckily I was still able to reboot into the TWRP recovery, so at this point I decided that the safest option would be a complete reinstallation. I reflashed an Oxygen OS update for Q android on both slots and then by reflashing TWRP before a reboot I was able to finally reinstall the e-0.16xxx version.

However I was still faced with the problem of installing Magisk. It refused to install from the apk app and I ended up having to extract the boot image of /e/OS using the payload_dumper tool written in Python. This also required several further downloads on my Linux machine before I succeeded in getting the boot.img that Magisk has a procedure for re-patching. It was with this final repatched version that I was able to reflash using fastboot and get a working Magisk installation.

Magisk appears to have a TWRP A/B retention script module which I have not tried but will do so the next time there is an OTA update as it seems to promise a way a keeping the device rooted. If anyone has tried this module I would be interested to know if it works, as this would have saved me a lot of work!

Regain your privacy! Adopt /e/ the unGoogled mobile OS and online servicesphone

Hi @Grendel, I was experimenting on another OS which was mostly googled and Magisk was part of the experiment. Like you, I had to get a copy of boot.img for installing.

I used this guide to preserve Magisk when taking OTA’s. I didn’t have twrp, so don’t know about that. It worked for three consecutive OTA’s before I abandoned the OS, but the last one left the apps in a bit of disarray. Magisk was OK though. I had heavily mucked about with the OS, that may played a part.

Thanks @chrisrg for the heads-up. It has a helpful description of how OTA updates work on an A/B device, but it seems to refer to a normal update which in the case of a OnePlus device would be the OxygenOS and this is perhaps why they say that you have to reflash a stock image.

The only problem I can see here is how to preserve the /e/OS on the active slot. Reflashing to stock normally needs a complete wipe and factory reset. As I noticed that the e-0.16 update completed in two steps with the first being to copy to the inactive slot I imagine. Then the preparing “packages” message which announced the 2nd step may have been copying user data back to the inactive slot before rebooting, because I found my installation the way t was before with all my user apps, etc.

From what I read this is the normal procedure of switching slots during an OTA update as if something goes wrong with the new update, it goes back to the previous installation. In this way users are not supposed to be bothered by a mal-functioning update. That was Google’s reason for introducing this parallel system.

However, the way the /e/ programmers have modified this from what I can see the update ignores Google’s automatic updates policy evoked in the article you pointed to. This is understandable in that /e/ is designed not to refer to Google in any way, but it creates a problem for a rooted device.

Using the TWRP retention script before a reboot will keep its recovery and avoid its replacement with the e-recovery, but then you have to use Magisk to uniinstall itself (before the update according to the article) and then reinstall it to the inactive slot - which becomes the new system.

If you can follow my reasoning here (not simple I admit :slight_smile: then the problem is to interrupt the /e/ update procedure before a reboot to perform the above steps to retain root afterwards. This would correspond to the end of Step 3 in the article when they say Do Not Reboot, but I’m not sure we would have access to magisk at this point. Perhaps the developers could clarify this for us?

My brain goes into a bootloop thinking about it! :upside_down_face:

The article suggests that the twrp retention script can only be used where the initial magisk install was via flashing through twrp in the first place.

With magisk installed via patched boot.img method you can preserve magisk throughout the ota process (just skipping step 4 in the article).

OTA updating is a background process that doesn’t affect the current (active) slot so you can carry on doing other stuff on the phone at the same time; even while it is installing/verifying etc. The installation is being made to the other (inactive) slot. When it has finished there will be a prompt to reboot which you can ignore and go back to magisk to make the selections and reboot from there.

I know this doesn’t help with your question regarding preserving twrp as well, maybe someone else has experience of this. If I get bored I may give it a go myself.

Thanks for the information. Yes, I didn’t realise that during the update process you can go back to your current session. It makes sense as you say because that is the whole point of having an A/B device: the user isn’t bothered with reboot to recovery as all Samsung users have to do!

Are you using a OnePlus device? Presumably one with an A/B configuration. In which case did you have a very long second phase to the update before the reboot prompt?

I don’t have an OP6. I’ve got an Essential PH-1, two Xperia XA2’s and a Pixel 5. All A/B.
I’m not proud of it. :grimacing:

Downloading the OTA takes about 10-15 mins and installation is longer. Whole process about 40 mins I think. I’ve had another OS that always took over an hour, so it’s not too bad.

By the way, in the system updater you can select preferences (3 dots, top right) to prioritise updates which I have heard speeds up the process. Never tried it. Yet.

Yes, I can see you’ve a lot more experience with A/B devices than me. I started on an old Samsung Note 2 using other custom Roms before I discovered /e/, but then as I saw how good it was on older devices, I put it on an old Moto G for my partner who just wanted a small phone and is averse to complicated systems. After that I upgraded her to a Samsung A3 and also put /e/ on an A5 for a friend so I can see why most people - even on /e/ - seem to be using Samsung phones.

But I liked how OnePlus seemed to make things easier for custom Rom users and so started on a 5T before moving up to my present phone. I wonder what I’m going to do with all my old phones as well :thinking:

I was thinking, if you ‘flashed’ twrp (as opposed to just ‘booting’ it on device) you would not be able to reboot properly without taking other steps. The command fastboot boot twrp would boot twrp directy up onto the device without interfering with the bootloader.

I did, in fact, use this command with fastboot to boot the image file of twrp but I knew that this would not install it permanently on both slots so I flashed the installer app created by Mauronofrio for this purpose, but it must have broken something in the boot.img partition which prevented my device from rebooting correctly from the newly updated /e/OS. I now know better not to do it the next time. :unamused:

Well, curiosity got the better of me so I carried on investigating. Twrp and magisk can indeed be preserved throughout the OTA process as described in the guide linked to above.

I started with a clean slate: eOS 0.14q. Download and install OTA eOS 0.15q and reboot.
Install twrp to device by flashing the installer zip, reboot device. Check twrp recovery present ,ok.
Install Magisk with twrp, reboot and finish setup on device by touching Magisk app and following prompts.
(Note: Magisk v22.1 would not complete the on device set up. I uninstalled it and tried v22.0 which did work. Updated it in the app to 22.1)

This is where the experiment started and I followed the guide fairly closely. A bit of interpretation is needed because the screenshots aren’t exactly up to date, but the steps are the same.

Downloaded OTA eOS 0.16Q (settings in the updater set to ‘priority’ to test the speed) but don’t select ‘install’.
Step 2 of the guide: In Magisk select ‘uninstall magisk’, ‘restore images’. Do not reboot.
Step 3 : Back to system updater, install the OTA, do not reboot when the prompt arrives.
Step 4: Magisk again. In the modules window search for the twrp a/b retention script, install it, but don’t reboot when the prompt arrives.
Step 5: Go back to Magisk Home, select ‘install magisk’ and ‘install to inactive slot’ and ‘Let’s Go’ . After flashing has finished Reboot when prompted. That’s it. Everything is there as it should be; magisk and twrp on device.

Downloading OTA through to the last reboot into eOS took 30 mins; so the priority setting speeds things up.

2 Likes

That’s a priceless bit of research! I’m not sure I’d have had the courage - or energy - to go back to an older version of /e/ and then test the whole procedure of updating that you’ve done. I have copied all the steps for safe-keeping so that the next OTA update will save me a lot of time and worry. My OP6 as you know is my only A/B device which I use as my daily phone. Thanks again for a wonderful piece of work! :+1:

Salut Grendel!

Je suis utilisateur d’un OP6T et de ma petite expĂ©rience (je ne connais pas magisk) j’ai eu besoin d’utiliser la “recovery” proposĂ©e par /e/ pour que mon installation soit faite, par TWRP ca ne fonctionnait pas.

Si cela peut ĂȘtre utile


Salut @Samy, content d’accueillir un autre utilisateur OnePlus, et que tu as rĂ©ussi l’installation sans difficultĂ©s. Cet Ă©change concerne la MAJ vers e-0.16 et le problĂšme de rester rootĂȘ - que @chrisrg semble avoir rĂ©solu. Apparamment ce n’est pas ton cas. Si tu veux continuer la discussion il vaut mieux crĂ©er un autre poste dans le forum français.

Downloaded OTA eOS 0.16Q (settings in the updater set to ‘priority’ to test the speed) but don’t select ‘install’.
Step 2 of the guide: In Magisk select ‘uninstall magisk’, ‘restore images’. Do not reboot.
Step 3 : Back to system updater, install the OTA, do not reboot when the prompt arrives.
Step 4: Magisk again. In the modules window search for the twrp a/b retention script, install it, but don’t reboot when the prompt arrives.
Step 5: Go back to Magisk Home, select ‘install magisk’ and ‘install to inactive slot’ and ‘Let’s Go’ . After flashing has finished Reboot when prompted. That’s it. Everything is there as it should be; magisk and twrp on device.

This is exactly what I found here:
https://www.droidwin.com/install-ota-rooted-android/

But I found out that I don’t need step 2 in your description on my Fairphone 3. I simply install the OTA, then the TWRP retention script, then Magisk into the inactive slot, then reboot. AFAIK this is because /e/ OTA does not check the integrity of the boot partition but simply overwrites it.

Be careful: Don’t update Magisk after the OTA when you open Magisk and find that there is a new version. After updating Magisk you must reboot the device and cannot install Magisk into the inactive slot. I made that mistake and had some trouble to get the process accomplished correctly.

A further note to the continuing difficulties created by an OTA update to eOS on a OnepLus 6. Though the update appears to be carried out normally as one would expect on an A/B device, the procedure still creates considerable complications if a user wants to keep root privileges.

I decided to go ahead with what appears to be a minor update to an 0.16 Q dev version dated 20210424 from the previous one of 20210414 using the well-researched instructions of @chrisrg to be seen above in this post.

  1. Launched the update after download and the “install” procedure took just a few minutes with setting speed priority but the 2nd phase “finalising package installation” took well over 10 minutes.

  2. Refused the “Install” invite in order to go back to uninstall Magisk, then “restore images” without rebooting.

  3. Then downloaded the TWRP a/b/retention script and tried to install but failed with message “twrp ramdisk not found”. I decided to ignore this and continue with @chrisrg’s instructions.

  4. Back with Magisk to install it to inactive slot, and after flashing on reboot I ended up with my normal system and root privilege maintained.

However the problem I disovered was that the update had once again replaced my TWRP recovery with the eOS version. As I knew that this recovery would not allow me to flash anything other than eOS updates, I decided to try again to reflash TWRP, which is done in two steps: first by using fastboot to boot an image file of twrp, then on entering twrp recovery to reflash the mauronofrio installer version which reinstalls to the boot image on both slots.

However, the installer warned me that it would remove magisk! So I spent a long time trying to reflash a new boot image using the patched version made with Magisk. However after some research I discovered that the usual command 


./fastboot flash boot magisk_patched-xxx.img


 no longer worked. After many reboots to fastboot mode and vain attempts that gave me at times the strange error “device does not support slots” when I tried to specify one, I finally hunted for a solution to another error message “cannot get boot partition size” and learned that a special fastboot command is needed:
./fastboot flash:raw boot_b magisk_patched-xxx.img

This command succeeded and had to be repeated with the “boot_a” parameter to have the rooted boot image on both slots. After another ultimate reboot to system, I finally returned to my updated and rooted eOS.
Obviously this long drawn-out OTA update was complicated by the failure of the retention script supposed to keep my twrp recovery on both slots. So this is why I found the ‘e’ recovery instead, and I had to go through the whole procedure of reflashing the patched image.
Why the retention script failed I have no idea and can only speculate that it may have been modules I had installed with Magisk that should have been uninstalled beforehand. I saw on one site a mention to this effect which was advised before uninstalling Magisk (v. step 2).

What is my conclusion after the various struggles I have had with the OP6 because of its A/B configuration? Much as I like this device and appreciate its rapidity and good battery life, I have to ask myself if its worth all this effort just to have a simple update. I’m sure others may be tempted to switch to a simpler device, but my preference to keep the advantages of a rooted device is in part due to the lack of a simple backup procedure that would permit a user to keep his choice of apps with all their configurations. I know that the idea of incorporating such a feature has been talked about, but strangely it seems not to be mentioned in the recent roadmap for 2021. I hope this is just an oversight since the subject keeps cropping up in various posts on this forum.

The other wish (that may be coming) is to have a better e-recovery that would allow flashing of other tools and keeping a rooted device if the user so wishes. I realise that this increases the risk of being hacked, but if precautions are taken and unrooting made simple then it is up to the user to decide if the advantages outweigh the risk.

1 Like

My 2 cents :

Last year, I used TWRP to update and root /e/. Then I switched to official updater inside /e/. It installed /e/ recovery.

For months now, I do the OTA-update through /e/. I loose root every time, which is normal.
Then, I manually extract boot.img from the update package with a python script found somewhere. Then I patch it through Magisk Manager.
Then, I execute fastboot flash boot /path/to/magisk_patched.img as stated on https://topjohnwu.github.io/Magisk/install.html

I gain root again and I can install my adblock tools, which is my primary concern.

Hi @kikoulol4485, your method works for you as you take the trouble to extract the payload binary from the update image and then use the python script “payload_dumper” to get the boot image which Magisk uses to create the patched image. Finally you re-flashed this to get a rooted OS.

However, after another OTA update to the eOS 0.17Q using the steps that @chrisrg first described in this topic (see April 22 above) you don’t need to use a PC and take the trouble preparing and flashing the new boot image. The longest part of the operation is the actual “finalising package installation” phase which takes nearly 30 minutes. But using Magisk to restore its image before rebooting, then finishing with its install to active slot allows you to reboot into the updated OS while keeping root.

The drawback for me is a problem with the TWRP a/b retention script which fails for a reason I have yet to discover. However, for the moment I’ll stick wiith the e-recovery as reinstalling TWRP means going through a similar process as you decribe and using a separate PC.

1 Like

You may want to try this: https://github.com/programminghoch10/Lygisk