To truly understand how Virtual A/B performs its magic, we must look at the low-level Linux kernel mechanism that makes it possible: dm-snapshot (Device Mapper Snapshot).
Device Mapper is a framework in the Linux kernel that allows you to map physical block devices onto virtual block devices. It is the exact same underlying technology used to encrypt disks.
The Copy-on-Write (COW) Concept
When Android is running normally, the system partition is strictly read-only.
When a Virtual A/B update begins, the update_engine instructs the dm-snapshot kernel module to create a virtual mapping over the system partition.
From that moment on, a strict Copy-on-Write (COW) protocol is enforced:
- Reading: If the OS needs to read a file from
/system, the request passes through the virtual mapping directly to the physical storage, operating at full native speed. - Writing the Update: When the update engine tries to write the new OS data, it does not overwrite the physical
/systempartition. Instead, thedm-snapshotmodule intercepts the write request and redirects those specific bytes into a specialized "COW Device" (which is actually just a hidden file residing on the/datapartition).
# Developers can manually monitor the snapshot merge status
adb shell snapshotctl dump
The Virtual Overlay (The Reboot)
After the update finishes downloading and writing to the COW file, the user reboots.
During the early boot phase, the init process from the ramdisk realizes an update is pending. Instead of mounting the raw /system partition, init instructs the kernel to mount the dm-snapshot virtual mapping.
This virtual mapping acts like a piece of transparent glass placed over the old system partition, with the new changes from the COW file painted on top.
- When a system app asks the kernel for a file, the
dm-snapshotdriver checks the COW file first. If the file was modified in the update, it serves the new file from the COW storage. - If the file wasn't modified, it passes the request down to the original
systempartition.
This overlay allows the device to instantly boot into the newly updated operating system, even though the physical system partition has not actually been changed yet.
The Final Merge
Running the entire operating system through a virtual dm-snapshot overlay incurs a slight CPU and storage performance penalty.
Therefore, once the device successfully boots and reaches the home screen, a low-priority background thread (the snapshotctl daemon) begins the merge process. It silently copies the updated blocks from the temporary COW file and physically overwrites the corresponding blocks on the actual /system partition.
Once the merge is complete, the temporary COW file is permanently deleted, the virtual mapping is destroyed on the next reboot, and the device returns to operating at maximum native storage speeds.