Professional Documents
Culture Documents
How A/B Partitions and Seamless Updates Affect Custom Development on XDA
When Android Nougat released, it had us talking about all kinds of new features. We got a newly updated user interface for starters
along with long-awaited multiwindow capabilities and Vulkan Graphics API support. But one under-the-hood addition flew over the
heads of most users. Android Nougat introduced “Seamless Updates” on devices that support A/B partitions. The vast majority of
existing Android devices (excluding the new Google Pixel and Google Pixel XL) did not have A/B partitions at the time and thus
couldn’t take advantage of seamless updates. The basic premise of this feature is that the device has a second set of the system,
boot, vendor, and other important partitions, and when you get an OTA update the update happens in the background while the
second set of partitions are patched which lets you reboot into an updated software build seamlessly. If an update fails, you’ll be
kicked back to a working build, meaning companies will have fewer headaches to deal with and consumers are better protected.
Supporting seamless updates is not a requirement for any new Android device, unlike Project Treble. As such, the vast majority of
new Android devices don’t support the feature. We’ve been keeping a list of all the supported devices so far, and it’s clear that this
feature is not widely supported. That’s a shame because A/B partitions bring a lot of benefits for both regular users and power-
users alike. However, the feature has a bit of a bad reputation in the enthusiast community because it’s perceived to make Android
development and flashing custom modifications more difficult. This is not actually the case, so we wanted to demystify seamless
updates and explain how A/B partitions affect custom development on XDA.
Many thanks to XDA Senior Member npjohnson, a contributor to LineageOS and maintainer of the Motorola Moto Z2 Force, who helped us
fact check this article.
A partition is simply a discrete section on the phone’s internal storage where data is kept. What kind of data is kept on each
partition depends on the hardware, operating system, and many other factors. The bootloader will have one, the system (Android
OS) will have one, the user data will have one… and so on and so forth. When you see people talk about “/system” and “/cache”,
they’re referring to the given names for those partitions. The OnePlus 6, for example, has 72 partitions. That sounds like a lot, but
the OnePlus 6 is one of the devices that supports seamless updates which means many of these partitions are simply duplicates of
each other.
Comprehensive Vendor
Vendor Management Software Solution.
Management Tool View A Demo Today.
Quantivate
Partial output of the partitions on the OnePlus 6. Some A/B partitions are underlined for demonstration purposes.
Ad
There are a lot of partitions on a device that you will never have to worry about as a user. Many of these partitions are never
modified when flashing custom ROMs, kernels, recoveries, or modifications
Comprehensive like Magisk or Xposed. A lot of these partitions will
Vendor
Vendor Management Software Solution.
either be unused for our purposes or are too dangerousTool
Management to touch unless you Today.
View A Demo know what you’re doing (XLOADER and OEMINFO on
Quantivate
Huawei/Honor devices come to mind.) For the vast majority of Android users, the partitions that we mostly deal with are system,
boot, recovery, userdata and more recently vendor and vbmeta. Here’s a brief explanation of the purpose of each partition:
system – holds the Android OS, system libraries, system apps, and other system media like bootanimations, stock wallpapers,
ringtones, etc.
boot – holds the kernel, ramdisk, and on A/B devices also the recovery as well
recovery – holds the recovery, where TWRP is most commonly flashed on A-only devices (A/B devices don’t have a dedicated
recovery partition)
userdata – holds all of your app, system, and internal storage data
vendor – holds platform and device-specific HALs, the files necessary for the Android OS to communicate with the underlying
hardware
vbmeta – the partition for Android Verified Boot 2.0 which verifies the integrity of the boot process
Device OEMs can change their partition schemes to use whatever layout they want. For instance, Huawei splits the boot partition
into ramdisk_recovery and kernel. There are also a lot of extra partitions that may contain other system apps such as cust, product,
and oem, and while these are safe to modify, it’s generally not recommended if you want to make it easier on yourself to return to
stock. So where do A/B partitions play a role?
The very simple image I made below illustrates how an update is handled on a device with A/B partition support. The partition that
is illustrated is the system partition, though other partitions such as boot and vendor may also be updated with any given OTA
update from an OEM. This update process happens with not only major Android version updates but also security patch updates.
1. We start with two system partitions, system_a and system_b, both on the same version of Android.
2. Assuming that system_a is active, the OTA update will patch system_b, the inactive partition, in the background.
3. system_a is set to inactive and system_b then becomes active once the user reboots.
4. The now-inactive partition, system_a, will be updated when the next OTA update rolls out.
1. If an update fails, the device will roll back to the working build on the other
Comprehensive slot.
Vendor
Vendor Management Software Solution.
2. Your data is kept perfectly intact, evenManagement
if the updateTool
is borked,View
as there
A Demois only one partition (userdata) which houses your data.
Today.
Quantivate
3. Update streaming: If your data partition is full, then the update can be downloaded and streamed to the inactive slot. It’s a pretty
neat feature and means that you don’t have to waste any temporary storage on your updates. That’s why there’s no cache
partition on A/B devices as they’re no longer needed.
What impact does the A/B partitioning scheme have on the storage of a device?
Does the fact that seamless updates result in a bunch of duplicated partitions mean you’re losing a bunch of storage space? Not at
all. Google says that devices with seamless update support should only be down about a few hundred Megabytes thanks to
removing the /cache and /recovery partitions. Removing both balances the cost of adding a second set of partitions. According to
Google, the Pixel’s A/B system image is half the size of the A-only system image. Most of the additional storage usage actually
comes from the addition of a second vendor partition. That makes sense as the vendor partition houses all of the proprietary
binaries used by OEMs (part of Project Treble), so it’s expected to take up quite a bit of space. While Google doesn’t recommend
having A/B partitioning on devices with 4GB of storage (as it’s nearly 10% of total available storage), they do recommend it on
devices with 8GB and higher.
Here’s a breakdown of the storage space used on a Google Pixel with and without A/B partitions.
The underlying Linux kernel on Android devices is what lets Android recognize and use the hardware properly on a smartphone. On
A-only Android devices, you generally have two versions of the kernel: One is packed inside of the recovery partition while the other
is in the boot partition. On A/B devices supporting seamless updates, the recovery is now inside of the boot image along with the
kernel. The recovery’s main function was to install updates, but since that’s handled by the system itself (update_engine) while
Android is booted up the dedicated recovery partition is no longer needed.
To install a custom recovery on A/B devices, we thus need to modify the boot partition and replace the stock recovery with our own.
This is why to install TWRP you need to use a fastboot command to boot a custom boot image first and then flash the TWRP
installation script, as fastboot can’t patch partitions—only flash over them entirely. You could technically pre-patch your existing
boot image with TWRP and then flash it via fastboot, but that’s more trouble than it’s worth. The TWRP installer script patches
both the boot_a and boot_b partitions to install TWRP.
Fun fact: The Android update_engine which handles seamless updates is basically ripped straight from Chrome OS. Only recently
were strings containing “Chrome OS” removed from update_engine’s log to avoid confusion for anyone who happens to check
logcat.
While we keep a list of all devices that support it, you can also easily check yourself.
In addition, a lack of understanding of how A/B partitions changed the way users need to install custom ROMs, kernels, recoveries,
and modifications led to A/B partition support being unpopular. With the recovery now living inside of the boot image, flashing
modifications in the wrong order such as Magisk or Xposed can cause conflicts and can lead to a bootloop. What order you flash
these mods in can be important, though in the case of custom ROMs you shouldn’t need to worry about what slot you’re flashing
to. Contrary to common belief, the installation script for most custom ROMs does not flash to both slots. You mostly don’t need to
worry about that as you shouldn’t need to be swapping slots manually.
When building a ROM, developers can make use of both partitions to test separate builds. If one doesn’t work, they can just revert
back to the working partition and rebuild their ROM. Developers can also test for regressions by simply installing an update,
switching the active partition, and comparing the two without having to wipe data. Here’s how the LineageOS team views A/B
partition support:
“Many around the Android community have bashed A/B as being ‘hard to support’ and ‘not developer friendly’, when in fact,
properly implemented it is easier to support and just as developer friendly.” – jrizzoli, LineageOS Changelog 19
The initial difficulty with A/B support for developers came from modifying their existing tools to support these devices. The
developer of Magisk, topjohnwu, added official support for the Google Pixel a year after it was released—not because it was
difficult, but rather because it took him a year to actually obtain the device to work on. TWRP support came pretty quickly on A/B
devices after the lead developer, Dees_Troy, took a crack at it. LineageOS 15.1 now supports A/B devices after volunteers found
time to fix their addon.d script.
How to update an A/B device that has a custom recovery, kernel, or other mods
Custom ROMs
Flashing updates on a device with a custom ROM means that you’ll have to be wary of which slot you’re flashing too, right? Not
quite. TWRP will actually handle a lot of that for you, and it defaults to the inactive slot for flashing a custom ROM. If your active
slot is A and you flash a custom ROM, you’re actually flashing to slot B. When you reboot, the active slot is now B. Developers can
modify the installation script and flash to both slots to make it easier on the end user, although most custom ROM installation
scripts currently only flash to a single slot. Lastly, custom ROMs can implement an A/B updater in their ROM so that users don’t
even need to mess with manually flashing updates—the latest LineageOS 15.1 includes a Lineage Updater tool, and XDA Senior
Member USA-RedDragon made a generic A/B updater
Vendor that other developers can use.
Comprehensive Vendor
Management Software Solution.
Management Tool View A Demo Today.
Quantivate
Stock ROMs
But isn’t it problematic if your device is running the stock ROM with various modifications and you want to install an update without
losing all of these mods? It can be if you don’t know the right steps to install an update. On the OnePlus 6, for example, you can’t
flash an incremental OTA on your modified device because the incremental OTA will attempt to patch your modified boot image.
Thus, you’ll likely end up with a bootloop, and that’s why you have to flash the full ROM update to completely overwrite your
modified boot image. Here are the general steps you need to take to install an OxygenOS update on your OnePlus 6 while still
retaining TWRP, Magisk, and optionally a custom kernel.
On the Google Pixel devices, you can flash the factory image without wiping data, then boot TWRP, install TWRP via the install
script, then install Magisk.
Update files for many A/B devices are a little different compared to A-only devices. They’re no longer just a zip file containing lots of
images (excluding Google and Razer’s factory images), instead, they’re in the form of a payload.bin file. You can extract this file and
flash each part manually, but it requires a special tool to do so. If you’re interested in learning how to do so on the OnePlus 6,
Xiaomi Mi A1, and many other A/B devices, read on.
You can flash each of these images separately now via fastboot if you wish. The next section shows you how to do that.
There are a number of commands that are exclusive to A/B partition system devices. You can change your active slot and flash to
specific slots. If you have a Project Treble-compatible device and want to learn how to flash Generic System Images, you should be
familiar with these commands. Take a look at the table below.
Comprehensive Vendor
Vendor Management Software Solution.
Management Tool View A Demo Today.
Quantivate
fastboot getvar all | grep “current-slot”
Get current active slot
If you’re on a Windows PC, the “grep” command won’t work.
fastboot set_active $
OR
Set specified slot as active
fastboot –set-active=_$slot
where $ is either a or b
Flash image to the specified partition in the current slot fastboot flash partition partition.img
fastboot flash partition_a partition.img
Flash image to the specified partition in the specified slot
fastboot flash partition_b partition.img
(Note: On A/B devices, you can either specify a partition in a particular slot to flash to or you can leave out the slot suffix and it’ll
flash to the current active slot. For example, you can replace “partition” in the flash command with “system”, “system_a”, or
“system_b.”)
A common misconception is that having Project Treble support and A/B partition support are related to one another, but that’s not
actually the case. Having one does not imply the other. The Motorola Moto Z2 Force uses an A/B partitioning scheme but doesn’t
support Treble. On the other hand, the Honor 9 Lite supports Project Treble, yet is an A-only device.
Comprehensive Vendor
Vendor Management Software Solution.
Management Tool View A Demo Today.
Quantivate
The Honor 9 Lite supports Project Treble but does not support Seamless
Updates