Skip to content

On-Device OTA Updates

os-upgrade (/usr/local/sbin/os-upgrade) lets you update an already-flashed headless-phone device directly over SSH or offline — without using fastboot or wiping /home, /root, Docker volumes, network configs, SSH host keys, or your customized /etc/headless-phone/*.conf files.

  1. Inspect current device & slot state

    Terminal window
    sudo os-upgrade status
    # Machine-readable JSON output for automation
    sudo os-upgrade status --json

    Displays device codename, running kernel, A/B slot flags, inactive-slot classification (headless-phone, android, empty, or unknown), vbmeta AVB status, battery telemetry, installed system manifest version, stored backups, and a preview of what --slot-policy auto will choose.

  2. Inspect the latest GitHub Release

    Terminal window
    os-upgrade check
    # Include prereleases or query a custom fork:
    os-upgrade check --prerelease --repo owner/headless-phone

    check queries the GitHub Releases API to report the latest release tag, whether the device’s boot/system/checksum assets exist in that release, and whether installed_version != latest_tag (it is a release inspection rather than a semantic-version or downgrade-order check).

  3. Dry-run the update first

    Terminal window
    sudo os-upgrade apply --release latest --dry-run

    Runs all pre-flight checks, downloads & verifies SHA256SUMS.txt, inspects boot image headers and vbmeta, and prints the exact slot and conffile plan with zero mutations.

  4. Apply and reboot

    Terminal window
    sudo os-upgrade apply --release latest --reboot

    Schedules a clean 2-second delayed reboot after writing and verifying everything.

Pulls SHA256SUMS.txt plus headless-phone-boot-<device>.tar.zst and headless-phone-system-<device>.tar.zst over HTTPS from dbech/headless-phone (or UPDATE_REPO in /etc/headless-phone/update.conf):

Terminal window
# Latest stable release (boot + system overlay; requires a PR #3+ release)
sudo os-upgrade apply --release latest --reboot
# Pin a specific release tag
sudo os-upgrade apply --release <release-tag> --reboot
# System scripts/units/shims only (no kernel flash, no reboot needed)
sudo os-upgrade apply --release latest --system-only
# Kernel & boot partitions only
sudo os-upgrade apply --release latest --kernel-only --reboot

Set GITHUB_TOKEN in the environment if you hit unauthenticated GitHub API rate limits.

Slot Policies (auto, same-slot, inactive-ab)

Section titled “Slot Policies (auto, same-slot, inactive-ab)”

os-upgrade inspects the inactive slot’s boot image (via headless_bootimg.py bounded initramfs inspection) and chooses how to flash boot partitions without accidentally overwriting stock Android:

Policy Behavior When It Is Chosen / Hard Limits
auto (default) Selects inactive-ab only when every A/B criterion passes; otherwise falls back to same-slot so stock Android on the inactive slot stays untouched. Fails closed (blocked) if bootctrl metadata is configured but unreadable/corrupt or if a pending A/B slot switch has not been rebooted yet. Recommended for normal use.
same-slot Backs up the running slot’s boot partitions + /lib/modules/<kver> into /var/lib/headless-phone/backups/, then writes and read-back verifies the running slot in place. Leaves the inactive slot untouched. Refuses to overwrite /lib/modules/<kver> if that exact kernel release is shared with a fallback slot unless --allow-same-kver is passed. Automatic under auto whenever the inactive slot is classified as android, empty, or unknown, when vbmeta_<other> still enforces AVB, when BOOTCTRL_BACKEND=none, or when new_kver == running_kver.
inactive-ab Flashes the inactive slot (boot_<other>, vendor_boot_<other>, dtbo_<other>, etc.), stages modules, and switches the active slot via headless_bootctrl.py (devinfo, gpt-ab, or bcb) with tries = 3. Automatic ABL fallback if the new kernel fails to come online. Automatic under auto only when: (1) device is A/B, (2) bootctrl backend is enabled & valid, (3) bootloader is allowlisted, (4) current slot is successful=1, (5) inactive slot is already headless-phone, (6) vbmeta_<other> has AVB disabled, and (7) new_kver != running_kver.

If a previous inactive-ab update already switched the active slot and you have not rebooted yet, os-upgrade detects the pending slot switch and blocks further updates until you reboot or run os-upgrade rollback.

Before flashing raw boot partitions (and again right before writing), os-upgrade apply and rollback check both battery state of charge and instantaneous voltage:

  • Default minimum SOC: --min-battery 15 (15%)
  • Default minimum voltage: --min-voltage-uv 3550000 (3.55 V)
  • Override only if you are on a reliable wired supply and know what you are doing: --force-low-battery
  • Strict partition allowlist: Only boot, init_boot, vendor_boot, vendor_kernel_boot, and dtbo can ever be flashed (never bootloader, radio, super, userdata, misc, or devinfo raw images).
  • SHA-256 verification & size bounds: Online downloads and archive extraction are capped at 512 MiB and verified against SHA256SUMS.txt (both outer and inner boot-bundle checksums).
  • AVB tail scrubbing: Clears stale 64-byte AVBf partition footers (4 KiB aligned) when writing smaller boot images over older partitions.
  • Write-ahead crash recovery journals: Uses flock serialization and atomic journals under /var/lib/headless-phone/ (pending-update.json, pending-rollback.json, pending-enable-services.json) so a power loss mid-operation is detected and recovered cleanly on the next run.
Terminal window
# Preview rollback of the most recent boot/kernel update
sudo os-upgrade rollback --dry-run
# Roll back (switches active slot back on inactive-ab, or restores backed-up
# partitions + /lib/modules/<kver> on same-slot) and reboot
sudo os-upgrade rollback --reboot
# Roll back to a specific backup ID listed by `os-upgrade status`
sudo os-upgrade rollback --backup <backup-id> --reboot
# Prune old backups (default keeps 2 newest) and unused /lib/modules/<kver> trees
# (never deletes the running kernel's or the other slot's modules)
sudo os-upgrade cleanup --dry-run
sudo os-upgrade cleanup --keep-backups 2

System Overlay Updates & 3-Way /etc/ Protection

Section titled “System Overlay Updates & 3-Way /etc/ Protection”

The system overlay bundle (headless-phone-system-<device>.tar.zst, built by rootfs/build_system_bundle.py) carries managed files under strict allowlisted prefixes (/usr/local/{bin,sbin,lib}/, /etc/headless-phone/, /etc/systemd/, /etc/udev/rules.d/, /etc/sysctl.d/, /etc/tmpfiles.d/, /etc/modules-load.d/, /etc/modprobe.d/, /etc/ssh/sshd_config.d/, /etc/cloud/cloud.cfg.d/), tracked against /var/lib/headless-phone/installed-system-manifest.json.

os-upgrade hard-denies writing or deleting any path in:

  • /home/, /root/, /var/lib/docker/, /var/lib/cloud/, /var/lib/headless-phone/, /etc/netplan/, /etc/ssh/ssh_host_*, /etc/systemd/system/frigate-*, /etc/sudoers.d/
  • /etc/hostname, /etc/hosts, /etc/machine-id, /etc/resolv.conf, /etc/fstab, /etc/passwd, /etc/shadow, /etc/group, /etc/gshadow, /etc/sudoers
  • User config files: /etc/headless-phone/charge-limit.conf, /etc/headless-phone/brownout-guard.conf, /etc/headless-phone/update.conf

When an updated managed file under /etc/ differs from the previously installed manifest hash on disk (meaning you edited it locally):

  • By default, os-upgrade preserves your file untouched and writes the new upstream version alongside it as <path>.headless-new so you can diff and merge at your leisure.
  • Pass --overwrite-configs if you explicitly want to replace locally modified managed /etc/ files.
  • Masked systemd units stay masked across updates, orphaned files removed from newer overlays are pruned cleanly, and critical transport/runtime services (ssh, systemd-networkd, systemd-resolved, wpa_supplicant, usb-role, mount-vendor, docker, containerd) are never live-restarted during an SSH session. Safe services (charge-limit.service, brownout-guard.service) are restarted unless --no-restart is passed.

Configuring /etc/headless-phone/update.conf

Section titled “Configuring /etc/headless-phone/update.conf”

To point os-upgrade check and apply at a custom fork by default without repeating --repo:

/etc/headless-phone/update.conf
UPDATE_REPO=your-org/headless-phone
Subcommand Key Flags Purpose
status --json Inspect device, kernel, A/B slots, inactive classification, AVB, battery, manifest version, and backups.
check --repo, --prerelease, --json Inspect the latest GitHub Release tag and check whether matching device assets exist (installed_version != latest_tag).
apply --release, --repo, --prerelease, --boot-bundle, --system-bundle, --bundle-dir, --checksums, --require-checksums, --kernel-only, --system-only, --slot-policy {auto,same-slot,inactive-ab}, --min-battery, --min-voltage-uv, --force-low-battery, --allow-overwrite-android, --allow-same-kver, --allow-unconfirmed-current-slot, --allow-shell-mode, --overwrite-configs, --no-restart, --dry-run, --reboot, --json Validate, stage, and apply online or offline boot and/or system overlay updates.
rollback --backup, --min-battery, --min-voltage-uv, --force-low-battery, --dry-run, --reboot Revert the previous boot/kernel update.
cleanup --keep-backups N, --dry-run, --json Remove old backups and unused /lib/modules/<kver> trees safely.