FORUMS
Remove All Ads from XDA

[GUIDE] The Noob's Guide to A/B Partitions and Other OP6 Idiosyncrasies

4,980 posts
Thanks Meter: 2,746
 
By iElvis, Senior Member on 13th July 2018, 11:07 PM
Post Reply Email Thread
If you've just arrived on the phone modding scene, or are coming from another phone that uses traditional approaches to flashing, you've likely come across people talking about the "A/B partitions." If you don't have any experience with this arrangement, it can be intimidating, because it fundamentally changes a lot of things related to flashing and updates.

What is a Partition?

Let's start with the basics. A partition is a discrete, contiguous, but non-overlapping section within the phone's storage where data is stored. There are partitions for bootloaders, various firmware, user data, OS files, and so on. For the most part, these files live in their own partitions, and you can wipe, format, and edit them without affecting files on other partitions.

There are 72 different partitions on the OP6. If you've worked with partitions on previous phones, you're probably thinking, "That's a lot," and it is. But there's a reason why there are so many: Many of them are duplicated, and that brings us to A/B partitions. Google moved to A/B partitioning for a specific reason: It allows for what are known as "seamless" updates. The following is from Google's explainer for devs, but it's fairly straightforward:

Quote:

A/B system updates use two sets of partitions referred to as slots (normally slot A and slot B). The system runs from the current slot while the partitions in the unused slot are not accessed by the running system during normal operation. This approach makes updates fault resistant by keeping the unused slot as a fallback: If an error occurs during or immediately after an update, the system can rollback to the old slot and continue to have a working system. To achieve this goal, no partition used by the current slot should be updated as part of the OTA update (including partitions for which there is only one copy).

Each slot has a bootable attribute that states whether the slot contains a correct system from which the device can boot. The current slot is bootable when the system is running, but the other slot may have an old (still correct) version of the system, a newer version, or invalid data. Regardless of what the current slot is, there is one slot that is the active slot (the one the bootloader will boot form on the next boot) or the preferred slot.

Each slot also has a successful attribute set by the user space, which is relevant only if the slot is also bootable. A successful slot should be able to boot, run, and update itself. A bootable slot that was not marked as successful (after several attempts were made to boot from it) should be marked as unbootable by the bootloader, including changing the active slot to another bootable slot (normally to the slot running immediately before the attempt to boot into the new, active one).

What does all this mean? Well, one thing (the main thing, really) that it allows you to do is take an OTA while you are booted up and using your phone. (Even if you're rooted? Yes, but more on that in a moment.) The system update engine will download and install the update to the inactive slot in the background, then ask you to reboot. When you reboot, you'll be fully updated without the need to boot to bootloader and wait for it to install. This approach makes updating a lot safer: If the update breaks something, the system won't boot to that slot. It will return to the old slot and let you know the update failed. The days of having an OTA bork your phone out of the blue are mostly over. That's good!

But What About My Data?

Though there are two versions of many partitions (boot_a, boot_b, system_a, system_b, and so on) there's only one userdata partition. So your data isn't affected by the update.

You may need to log back into certain apps as if using them for the first time, but your data and settings will all still be where they were before the OTA.

What A/B Means for Rooting

The wrinkles, however, start coming when you unlock and root your phone. To understand why, we need to talk about something called the kernel. The kernel is a key part of any computer operating system. It is the tool that applications use to talk to the hardware and vice versa, and it governs how the CPU operates, how memory is used, and on smartphones how things like the screen, radio, speakers, and so on function. Without the kernel, or with a broken kernel, applications have no way to function. If you've heard the term "kernel panic," it's a situation in which the kernel stops the system either because of a hardware fault or a software problem that's taken the system into a state that the kernel can't get it out of.

Non-A/B Android phones actually had two kernel images. One lived in the recovery partition, while the other lived in the boot partition. This allowed the phone to boot into recovery and make major changes to the rest of the system. But the A/B approach gets rid of the separate recovery partition and integrates it into the boot partition. Why? Probably because on stock phones, the recovery is only used for system updates, and with the A/B arrangement, it's no longer necessary to have a separate dedicated recovery since updates happen directly to the inactive partition.

This creates a challenge for phone modding, however. Without a separate recovery partition, the stock recovery has to be replaced with a custom recovery, inside the boot partition where the kernel lives. But on Android, you cannot modify partitions through fastboot – you can only flash over them. So installing a custom recovery like twrp for the first time requires you to fastboot boot into twrp from your computer, then flash an installer once you are booted. .

There's another problem: Rooting via magisk makes modifications to the boot sector. So does flashing xposed or (obviously) a custom kernel. With recovery and these other custom mods now all living together in the same partition, it is possible for one of them to overwrite files used by another mod. This is why you may need to reflash magisk after updating a custom kernel or custom recovery, and why not doing so can result in a bootloop. You've overwritten files magisks uses for root, so your phone can no longer boot (this isn't the case with all mods; many are now coded to avoid this problem).

Updates on a Rooted OP6 with A/B Partitions

If you've been following along so far, you're probably now seeing another issue: Isn't a seamless update going to overwrite all of my mods? The answer is yes, it will (more accurately, it won't copy them over to the new slot). If you're cringing now, have faith. This isn't as big a deal as it sounds, and it's actually a good thing once you see how it all works.

Here's what happens when your OP6 gets an update notification. The update engine detects root and downloads the full update instead of the incremental update. This is very important and you should not try to frustrate or block it from doing so (unless you want to update manually via twrp, see below). Taking the incremental update on a rooted phone could result in a brick, or more likely, an unbootable slot. Like it says in that Google quote above, the updater installs the new version in the inactive slot. The key thing here is that it installs a fresh, fully stock version. Your data gets pulled over, but none of your mods go with it. To get them back, you have to install them all again. There are various ways of doing this, and this isn't the place to repeat the guides that are already posted on how. Just understand that you have to do it to keep root, twrp, and your other mods.

It works more or less the same way if you download the full update manually and flash in twrp. You'll get a fully stock installation on the other slot, and you'll boot into it unrooted unless you reinstall your mods first. You also should note that this makes for an easy way to go back to stock if that's what you want, and I recommend keeping a zip of the stock OS on your phone just in case you need to do it.

Note that you can manually switch the active slot in twrp, but I don't recommend doing so until you know what you're doing. After a couple of updates and flashes, what remains on the inactive slot is not necessarily going to be bootable, or it may boot with things like wifi broken. And if you've never updated at all, there may be nothing on the inactive slot, which means your phone will reboot into the void of a black screen. (But don't worry – there's a tool to fix this here.)

Here are a couple of guides that I recommend for further reading on the specifics:

[RECOVERY] HOW TO INSTALL OFFICIAL TWRP & MAGISK OOS 5.1.5 to 5.1.8
[OFFICIAL] OxygenOS 5.1.8 OTA for the OnePlus 6

If all this seems like some extra work, it is. But remember it ensures you're getting a clean and fully functional updated system. Once you get the hang of doing it this way, you'll appreciate the advantages.

Some Other Things to Be Aware of

In addition to the other changes, the cache partition has been removed. It now resides in the data partition and is no longer used for anything related to updates. One result is that wiping cache in twrp no longer does anything. If you want to clear cached data go into Settings>Storage & memory, then tap Cached data at the bottom and then tap OK.

Otherwise, you don't need to worry much about it. (Why did Google do this? Apparently to save space that was taken up by having to duplicate many other partitions. They also halved the system partitions by playing some clever games with app odexing, but that's beyond the scope of this guide – the only user effect is a slower first boot after factory reset.)

That's Cool! I Want to Know More!

This article on the XDA portal covers everything you could possibly want to know about A/B partitions and what they do.

Good luck and happy modding.

(Note: Devs and experienced users are encouraged to submit corrections if any of this is a bit off.)
Thanks to @jisoo for a guide in the Pixel forums I adapted some of this from.
The Following 183 Users Say Thank You to iElvis For This Useful Post: [ View ] Gift iElvis Ad-Free
 
 
13th July 2018, 11:28 PM |#2  
Senior Member
Flag Vancouver
Thanks Meter: 627
 
More
Very informative and I'd even recommend this read for users who already know a bit about the partitions!
The Following 3 Users Say Thank You to rickysidhu_ For This Useful Post: [ View ] Gift rickysidhu_ Ad-Free
13th July 2018, 11:55 PM |#3  
lollyjay's Avatar
Senior Member
Flag Fresno
Thanks Meter: 1,516
 
Donate to Me
More
Excellent guide. Can I link it?
The Following User Says Thank You to lollyjay For This Useful Post: [ View ] Gift lollyjay Ad-Free
14th July 2018, 12:25 AM |#4  
iElvis's Avatar
OP Senior Member
Flag Modville
Thanks Meter: 2,746
 
More
Quote:
Originally Posted by lollyjay

Excellent guide. Can I link it?

Of course, your guide is linked here too.
14th July 2018, 12:25 AM |#5  
MishaalRahman's Avatar
Editor in Chief
Thanks Meter: 1,866
 
More
A quick read over this and I can't find anything glaringly wrong with it. Nice write up. Considering adapting it for the Portal if you're okay with that, OP.
The Following User Says Thank You to MishaalRahman For This Useful Post: [ View ] Gift MishaalRahman Ad-Free
14th July 2018, 01:00 AM |#6  
iElvis's Avatar
OP Senior Member
Flag Modville
Thanks Meter: 2,746
 
More
Quote:
Originally Posted by MishaalRahman

A quick read over this and I can't find anything glaringly wrong with it. Nice write up. Considering adapting it for the Portal if you're okay with that, OP.

Feel free!
14th July 2018, 01:09 AM |#7  
lollyjay's Avatar
Senior Member
Flag Fresno
Thanks Meter: 1,516
 
Donate to Me
More
Quote:
Originally Posted by iElvis

Of course, your guide is linked here too.

Done! And thank you.
14th July 2018, 03:26 AM |#8  
vikasb32's Avatar
Recognized Themer
Flag Hardwar
Thanks Meter: 2,022
 
Donate to Me
More
Still little confused here.so if I flashed full ROM zip(not ota zip) from twrp then I have updated system or my phone will soft brick?
14th July 2018, 05:56 AM |#9  
iElvis's Avatar
OP Senior Member
Flag Modville
Thanks Meter: 2,746
 
More
Quote:
Originally Posted by vikasb32

Still little confused here.so if I flashed full ROM zip(not ota zip) from twrp then I have updated system or my phone will soft brick?

Flashing the full rom zip will give you an updated system, but stock unless you follow by reinstalling twrp, etc.
15th July 2018, 12:57 PM |#10  
sighted's Avatar
Member
Flag Sorocaba SP
Thanks Meter: 46
 
More
No other words than THANK YOU! You've clarified our minds!
The Following 2 Users Say Thank You to sighted For This Useful Post: [ View ] Gift sighted Ad-Free
15th July 2018, 04:53 PM |#11  
texasaggie1's Avatar
Senior Member
Thanks Meter: 224
 
Donate to Me
More
Nice write up. I did have a question though. If I flash the full stock rom in TWRP does it automatically flash to the non-active partition? I've had a couple of unexpected issues when flashing.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes