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.
Quick Workflow
Section titled “Quick Workflow”-
Inspect current device & slot state
Terminal window sudo os-upgrade status# Machine-readable JSON output for automationsudo os-upgrade status --jsonDisplays device codename, running kernel, A/B slot flags, inactive-slot classification (
headless-phone,android,empty, orunknown),vbmetaAVB status, battery telemetry, installed system manifest version, stored backups, and a preview of what--slot-policy autowill choose. -
Inspect the latest GitHub Release
Terminal window os-upgrade check# Include prereleases or query a custom fork:os-upgrade check --prerelease --repo owner/headless-phonecheckqueries the GitHub Releases API to report the latest release tag, whether the device’s boot/system/checksum assets exist in that release, and whetherinstalled_version != latest_tag(it is a release inspection rather than a semantic-version or downgrade-order check). -
Dry-run the update first
Terminal window sudo os-upgrade apply --release latest --dry-runRuns all pre-flight checks, downloads & verifies
SHA256SUMS.txt, inspects boot image headers andvbmeta, and prints the exact slot and conffile plan with zero mutations. -
Apply and reboot
Terminal window sudo os-upgrade apply --release latest --rebootSchedules a clean 2-second delayed reboot after writing and verifying everything.
Online vs. Offline Updates
Section titled “Online vs. Offline Updates”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):
# Latest stable release (boot + system overlay; requires a PR #3+ release)sudo os-upgrade apply --release latest --reboot
# Pin a specific release tagsudo 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 onlysudo os-upgrade apply --release latest --kernel-only --rebootSet GITHUB_TOKEN in the environment if you hit unauthenticated GitHub API rate limits.
Copy release or local-build .tar.zst archives onto the phone over scp or USB storage:
# Directory containing headless-phone-boot-<dev>.tar.zst,# headless-phone-system-<dev>.tar.zst, and SHA256SUMS.txt# (SHA256SUMS.txt is required whenever --require-checksums is passed)sudo os-upgrade apply --bundle-dir /tmp/release --require-checksums --reboot
# Explicit individual bundle pathssudo os-upgrade apply \ --boot-bundle /tmp/headless-phone-boot-raven.tar.zst \ --system-bundle /tmp/headless-phone-system-raven.tar.zst \ --checksums /tmp/SHA256SUMS.txt \ --reboot
# System overlay only from a local buildsudo os-upgrade apply \ --system-only \ --system-bundle /tmp/headless-phone-system-raven.tar.zstSlot 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.
Safety Gates, Crash Recovery & Rollback
Section titled “Safety Gates, Crash Recovery & Rollback”Dual-Point Battery & Voltage Gates
Section titled “Dual-Point Battery & Voltage Gates”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
Partition & Archive Integrity
Section titled “Partition & Archive Integrity”- Strict partition allowlist: Only
boot,init_boot,vendor_boot,vendor_kernel_boot, anddtbocan ever be flashed (neverbootloader,radio,super,userdata,misc, ordevinforaw images). - SHA-256 verification & size bounds: Online downloads and archive extraction are capped at
512 MiBand verified againstSHA256SUMS.txt(both outer and inner boot-bundle checksums). - AVB tail scrubbing: Clears stale 64-byte
AVBfpartition footers (4 KiB aligned) when writing smaller boot images over older partitions. - Write-ahead crash recovery journals: Uses
flockserialization 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.
Rolling Back & Cleaning Up
Section titled “Rolling Back & Cleaning Up”# Preview rollback of the most recent boot/kernel updatesudo 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 rebootsudo 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-runsudo os-upgrade cleanup --keep-backups 2System 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.
Protected User Data (Never Touched)
Section titled “Protected User Data (Never Touched)”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
3-Way /etc/ Conffile Preservation
Section titled “3-Way /etc/ Conffile Preservation”When an updated managed file under /etc/ differs from the previously installed manifest hash on disk (meaning you edited it locally):
- By default,
os-upgradepreserves your file untouched and writes the new upstream version alongside it as<path>.headless-newso you can diff and merge at your leisure. - Pass
--overwrite-configsif 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-restartis 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:
UPDATE_REPO=your-org/headless-phoneSubcommand & Flag Summary
Section titled “Subcommand & Flag Summary”| 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. |