AOSP Foundations
6 min read

A/B Partitions (Seamless Updates)

Discover the dual-slot architecture that allows Android devices to install major OS updates transparently in the background.

Why Traditional OTA Updates Were a Liability

Imagine updating a phone on a train with a low battery. You tap accept on an over-the-air update prompt, and the system reboots into a minimal environment called recovery mode. An Android robot appears with a spinning gear. The device locks you out completely while it slowly overwrites the active system partition. If the battery dies halfway through this process, the system partition becomes hopelessly corrupt. The device permanently bricks.

Old architectures forced the standard operating system to halt. The OS could not overwrite files it was actively using. It relied on that dedicated recovery environment to safely delete and replace core components. A power failure or flash error during this process meant fatal data loss. Engineers needed a mechanism to upgrade a live system without risking the active software. This exact vulnerability is why Google engineered a system that never touches the active OS during an update.

Introducing the Slot A and Slot B Architecture

Writing to a live disk is mathematically unsafe. You cannot replace an airplane engine while flying at thirty thousand feet. The platform needed a second engine to work on safely in the background. Android solved this by duplicating the core physical partitions on the flash storage.

This dual-slot structure creates two identical sets of system partitions. Engineers call these Slot A and Slot B. One slot actively runs the device. The other sits completely dormant. When a device boots, it relies on system, vendor, and boot partitions from the active slot.

Tip: Both slots share exactly one userdata partition. Photos, apps, and databases exist in a single location to prevent storage waste and data desynchronization.

Visualizing this hardware layout clarifies the physical separation of duplicated and shared flash blocks. This isolation prevents background writes from corrupting the active system.

The diagram illustrates how flash storage cleanly separates the active and inactive OS components. The shared userdata partition remains outside both slots to guarantee persistent state.

Engineers frequently need to know which slot is actively running to debug update failures. The Android Debug Bridge provides a direct property query for this exact purpose. It outputs either _a or _b based on the currently running OS.

adb shell getprop ro.boot.slot_suffix

Many developers make a mistake with this command by assuming it indicates the slot that will run on the next boot. It only confirms the slot currently executing the system image. Having two sets of partitions solves the storage layout problem, but we need a mechanism to coordinate downloading and writing to the offline slot.

How update_engine Orchestrates Background Flashes

A second set of partitions only helps if something intelligently manages them. An operating system cannot just blindly write internet payloads to a raw disk. The system requires a dedicated service to unpack the update and negotiate with the hardware. A background daemon called update_engine handles this exact orchestration.

The daemon treats an update payload as a slow background task. It streams data from the server directly to the raw, unmounted blocks of the inactive slot. The CPU processes this download while the user plays a game or browses the web. The active operating system experiences zero downtime. Once the final byte lands safely on the inactive slot, the system contacts the Hardware Abstraction Layer. The boot_control HAL receives the command to flip the active bootloader flag.

Tracking this communication flow demonstrates how an update transitions from a background download to an actionable boot flag. This specific interaction protects the active OS from direct modification.

This sequence illustrates the daemon handling the disk writes independently. It delegates the final active slot change to the bootloader via the hardware abstraction layer.

Once the hardware abstraction layer flips the flag, the user simply reboots. The restart takes the exact same amount of time as a normal device restart. But what happens if the newly installed OS contains a fatal bug?

Self-Healing Systems: The Failsafe Rollback Mechanism

Broken updates install smoothly, users reboot naturally, and the new kernel immediately panics. A traditional single-slot device would now be a paperweight requiring a manual flash tool recovery. Dual-slot architecture turns this catastrophic failure into a minor hiccup. The bootloader contains intelligence to protect the device from unbootable updates.

Hardware manages a boot attempt counter for the newly activated slot. A successful boot requires the Android framework to fully load and explicitly tell the bootloader that everything works. If the system crashes before reaching that milestone, the bootloader increments its failure counter. After three consecutive failed attempts, it assumes the new slot contains corrupt code. The device automatically flips the active flag back to the previous, working slot.

Mapping the bootloader logic isolates the specific retry loop that protects the system. This state machine demonstrates the automated fallback mechanism in action.

These states map the exact conditions the bootloader evaluates during startup. The failure counter acts as a guaranteed safety net for catastrophic crashes.

Platform engineers often need to manually test this fallback mechanism when building custom ROMs. The fastboot tool provides a command to force the bootloader to switch its active slot. It outputs a confirmation of the newly active slot and bypasses the Android framework entirely.

fastboot set_active other
fastboot reboot

A critical mistake engineers make here is forgetting that the userdata partition does not roll back. If the broken new OS upgraded a database schema before crashing, the older OS might fail to read that newer database upon fallback.

Warning: Rolling back the OS partition does not roll back user data. A newer OS version modifying database schemas can cause application crashes when an older OS attempts to read them.

Background updates completely eliminated the risk of bricked phones, but this perfection came with a massive hardware cost.

Dual-slot architectures fundamentally changed Android platform stability. They eliminated installation downtime by flashing raw bits in the background. The bootloader gained the intelligence to self-heal by falling back to a guaranteed working state. Engineers gained direct manual control over active slots through fastboot commands.

Duplicating the entire OS creates absolute safety, but at the cost of gigabytes of expensive flash storage. Losing four to eight gigabytes for a backup operating system is unacceptable for cheap, entry-level devices. How did Google fix this severe storage bloat in modern Android versions?