Simple tool to implement an A/B partition image update strategy for a Raspberry Pi.
ab-flasher updates a Raspberry Pi in place, using what is sometimes known as a double copy, dual copy, or A/B strategy. This is where the device has two OS partitions but only one is active. Updates are done by flashing the inactive partition, then the bootloader is updated to switch to the new version.
When you run ab-flasher:, it:
Your Raspberry Pi should contain the standard boot partition, and two ext4 partitions for the OS.
If you need a bootstrap image, you can flash with an image containing ab-flasher from the Releases. This image contains the boot partition, two OS partitions, and a data partition. You can flash it with the usual tools (dd, Raspberry Pi Imager, etc).
After flashing, run ./config.py. If you don't already have one, this will create a .env file that you can fill in, then run ./config.py again. This will create configuration on the data partition.
You're ready to boot the Pi. On boot, the partitions will be expanded and ab-flasher will run.
How you run ab-flasher in your own image is up to you. Beyond the bootstrap image it doesn't take responsibility for how it runs or how you update its configuration. Any solution which lets you push configuration and run a command will be suitable.
Install using poetry install, or use the Docker image.
Usage: ab-flasher [OPTIONS] OS_IMAGE_URL [NEW_VERSION]
Arguments:
OS_IMAGE_URL URL to new gzipped image. [env var:
AB_OS_IMAGE_URL;required]
[NEW_VERSION] New version number (e.g. 1.2.3). [env var: AB_NEW_VERSION]
Options:
--boot-files-url TEXT URL to gzipped boot files (or skip boot
files update if not set). [env var:
AB_BOOT_FILES_URL]
--hash-url TEXT URL to a file containing a hash, used to
verify the write. [env var: AB_HASH_URL;
default: <OS_IMAGE_URL>.<hash-type>]
--hash-type TEXT Type of hash contained in the hash file
[env var: AB_HASH_TYPE; default: sha256]
--host TEXT Path to host's active root (usually only
needed for Docker) [env var: AB_HOST;
default: /]
--version-file TEXT File to check for existing version (at host)
[env var: AB_VERSION_FILE; default:
/.ab_version]
--reboot / --no-reboot Reboot after an update. [env var:
AB_REBOOT; default: True]
--boot-partition TEXT Partition number containing boot files [env
var: AB_BOOT_PARTITION; default: 1]
--os-partitions <INTEGER INTEGER>...
Which two OS partition numbers to consider
for flashing [env var: AB_OS_PARTITIONS;
default: 2, 3]
--force / --no-force Assume upgrade is required. [env var:
AB_FORCE; default: False]
--dry-run / --no-dry-run Take no actions. [env var: AB_DRY_RUN;
default: False]
-v Verbosity of logging. Specify multiple times
for more. [env var: AB_VERBOSE; default: 0]
--help Show this message and exit.
ab-flasher \
--boot-files-url https://example.com/boot.tar.gz \
https://example.com/os.img.gz
1.2.3
Using docker:
docker run --privileged -v /:/host jonoh/ab-flasher \
--boot-files-url https://example.com/boot.tar.gz \
https://example.com/os.img.gz
1.2.3
(The entrypoint passes --host /host so that the container can see the host filesystem.)
Traditionally you might keep a Pi updated by either running in place upgrades (apt-get update etc) or reflashing the SD card. These options are slow, and risky or difficult to automate.
The double copy strategy implemented by ab-flasher lets updates be fast and reliable, at the expense of more storage space. The system will be down only for the duration of a reboot and will then boot to a known state.
I built this to keep a small cluster of Raspberry Pis up to date. I found existing tools too complicated for my needs.
ab-flasher is deliberately simple and makes a lot of assumptions.
Some known limitations:
Content type
Image
Digest
Size
342.2 MB
Last updated
over 5 years ago
docker pull jonoh/ab-flasher