</>EmbeddedInterview

How do A/B (dual-copy) OTA updates work?

MediumEmbedded Linux & Boot

Short answer: The device has two copies (slots) of the system. While running from slot A, the update client writes the new image into slot B, verifies it, and tells the bootloader to try B on the next boot. If B boots and the application confirms it is healthy, B becomes the active slot. If B fails to boot after a few attempts (detected by the bootloader's boot counter, often helped by a watchdog), the bootloader rolls back to A.

Step by step

  1. Download the update (full image or delta) over HTTPS; verify its signature.
  2. Write it to the inactive slot (B) while the device keeps working on A.
  3. Verify what was written (hash).
  4. Set bootloader variables: boot_slot=B, boot_count=0, upgrade_available=1.
  5. Reboot. The bootloader increments boot_count and boots B.
  6. User space (after the application is up and passes self-tests) marks the slot good: upgrade_available=0.
  7. If the system reboots before that and boot_count exceeds the limit (e.g. 3), the bootloader switches back to A (rollback).

What makes it robust

  • Atomic: the switch is a single variable change; a power cut during writing only affects the inactive slot.
  • Automatic rollback: a bad kernel, a missing library or a crashing application does not brick the device.
  • Watchdog: if the new system hangs instead of crashing, the hardware watchdog resets it so the boot counter can work.

Costs and variations

  • Double storage for the system partitions. Alternatives: a single system plus a small recovery partition (cheaper, but the device is offline during the update).
  • Delta updates (binary diffs, casync, zchunk) reduce download size, which matters for cellular devices.
  • Data, configuration and the bootloader itself are usually not A/B; bootloader updates need extra care.

Tools to name: RAUC, SWUpdate, Mender, OSTree/Aktualizr (file-level, not block-level), and Android's update_engine (A/B "seamless updates").

Security: sign updates, check versions to prevent rollback attacks (installing an old vulnerable image; anti-rollback counters in fuses or RPMB), and combine with secure boot so a modified slot cannot boot.