Skip to content

Upgrade buster devices to bookworm at night - #803

Open
cyberb wants to merge 1 commit into
masterfrom
os-upgrade-bookworm
Open

cyberb wants to merge 1 commit into
masterfrom
os-upgrade-bookworm

Conversation

@cyberb

@cyberb cyberb commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Upgrades buster devices to bookworm in place, at night, once redirect enables the device.

Builds on #804 (OS reporting), now merged. Rebased onto master.

  • Nightly job (03:00): on buster or bullseye, with a target release set for this domain in redirect (os_upgrade_target, redirect Disk detach without deactivation breaks device #106) and at least 3 GiB free on /, it upgrades to that target if this platform knows a path to it. A name it doesn't know (a typo, or a newer release) means no upgrade. It copies the os-upgrade binary out of the snap and starts it in its own transient systemd unit, then reboots when it finishes.
  • os-upgrade binary: its own Go module with only standard-library dependencies, so later backend or CLI changes can't break it. Takes the target as an argument and plans the whole path before touching anything. Goes buster → bullseye → bookworm, one release at a time, and downloads everything before installing anything; any failed step stops the run. While it runs, package scripts may not restart services, except ssh.
  • One Upgrade button: replaces the System and Installer buttons and the note about pressing them in order. It upgrades whatever is available: platform, then snapd, then Debian (the page says the Debian upgrade takes up to an hour and restarts the device). The Debian step follows redirect's os_upgrade_target like the nightly job, so the button never upgrades the OS on device types we haven't enabled; until then the page says it will be offered once tested on this device type. The plan lives in $SNAP_DATA so it carries on after the platform step restarts the backend; a failed step ends it and is shown on the page. platform.cli os status / os upgrade do the OS part from the command line.
  • No more updates running into each other: the snapd upgrade now runs in its own unit (platform-snapd-upgrade), so a platform refresh or the post-upgrade reboot can't kill it halfway and leave snapd broken. Every update (button, nightly snapd and Debian jobs, the reboot, CLI, installer/platform endpoints) starts only when no snap change, snapd upgrade or Debian upgrade is running; nightly jobs retry within their hour. App installs/upgrades only wait for a snapd upgrade.
  • CI: a new amd64 step upgrades a real buster container and checks the platform survives.
  • Kernel reporting: the domain update also sends the running kernel (redirect Disk detach without deactivation breaks device #106 stores it and graphs it by board). Board kernels stay as they are through the upgrade.

@cyberb
cyberb force-pushed the os-upgrade-bookworm branch 2 times, most recently from b122abb to 553f8d2 Compare December 4, 2026 04:35
@cyberb
cyberb force-pushed the os-upgrade-bookworm branch from 553f8d2 to 7f1e82c Compare December 4, 2026 14:57
cyberb added a commit that referenced this pull request Dec 4, 2026
Every periodic domain update now carries the device's Debian codename
(VERSION_CODENAME from /etc/os-release) as "os", next to
platform_version. Nothing records a device's release today: redirect
keeps only the platform version and board, and the store and caddy do
not log snapd's user agent. Before rolling out the in-place buster to
bookworm upgrade (#803) we need to know how many devices are still on
buster and on which boards.

Redirect ignores unknown request fields, so this can ship before the
redirect side that stores it.

The release reader moves here from #803 so both changes share it.
@cyberb
cyberb force-pushed the os-upgrade-bookworm branch 5 times, most recently from de6be2a to 8cccbaa Compare December 5, 2026 21:43
Buster devices can no longer install anything: buster left
deb.debian.org and apt update fails with "no longer has a Release
file". New images are bookworm, and the boards' kernels already run
bookworm userspace in those images, since they ship outside dpkg, so
the userspace upgrade is all a buster device needs.

The platform now upgrades the release itself. A nightly cron job
(03:00, same scheduler as the snapd upgrade) reads /etc/os-release, and
on buster or bullseye with at least 3GiB free on / starts the
os-upgrade binary in a transient systemd unit, platform-os-upgrade.
The unit is not a child of the backend, so neither a backend restart
nor a platform refresh can kill dpkg halfway; the binary is copied
into SNAP_DATA first because a refresh swaps /snap/platform/current
under a running process. Nothing runs from the snap refresh hooks.

os-upgrade is its own Go module under os-upgrade/ with no dependencies
outside the standard library, built statically next to the other
binaries. The upgrade is the one step that must keep working on every
device, so nothing added to the backend or the CLI later can reach it:
no shared packages, no go.mod it does not own. Being static it also
needs nothing from the host while apt replaces libc, bash and, during
usrmerge, /bin itself. It replaces a bash script, where set -e is
silently off inside any function called from an if, so a failed
apt-get clean in the download step was ignored; here every failed step
stops the run. Its steps have unit tests against a fake root and a
fake apt.

It walks buster -> bullseye -> bookworm, the only supported path, and
checks after each hop that /etc/os-release really moved. Each hop clears the apt lists,
updates, and checks that the target suite's index is really there,
since apt-get update exits 0 when every fetch fails. It then downloads
every package before it installs any, so a mirror or network failure
leaves the system untouched: bullseye comes from
deb.debian.org main and falls back to archive.debian.org when the
mirror no longer has it (bullseye-security on deb.debian.org already
serves an index whose packages 404, so the intermediate hop takes main
only). Conffiles keep the local version. apt-daily and
unattended-upgrades are stopped for the duration, those that are
loaded, because buster's apt predates DPkg::Lock::Timeout. Repositories in sources.list.d would
point at the old release, so they are moved aside into the work dir
and named in the log. A failed run leaves the release it reached and
is retried the next night from there.

A policy-rc.d that denies every action is in place for the run (an existing one is kept aside and put back), the
standard way to script a release upgrade: a maintainer script that
fails to restart its service would otherwise abort dpkg halfway and
block every retry (ntp did exactly that in testing). The old daemons
keep running until the reboot. ssh is the one exception: an sshd left
on the old binary refuses every new connection once openssh is
upgraded, which would lock the owner out for the whole run and for
good if it stopped halfway. When the upgrade finishes it leaves a
reboot marker and the job reboots the device on its next tick, still
within the night window, so nothing runs on a mixed userspace for
long. A run that stops halfway is picked up the next night by
dpkg --configure -a and the remaining hop.

Settings > Updates has a single Upgrade button in place of the System
and Installer buttons and the note telling the owner to press them in
the right order. It upgrades whatever is available, in the order that is
safe: the platform first, so the newest platform drives the rest, then
snapd, then the Debian release, which restarts the device when it
finishes. The Debian step follows the same redirect target as the
nightly job, so pressing the button cannot start an upgrade on a kind of
device it has not been tried on yet: until redirect allows it, the page
says the new release will be offered once it has been tested on this
type of device and the button leaves the release alone. Once allowed,
the page says it takes up to an hour and restarts the device.
platform.cli os upgrade stays ungated, for support and CI. The plan is
kept in SNAP_DATA (system-upgrade.json) and moved one step at a time by
a loop in the backend, because the platform step restarts the backend
that runs it; each step is taken off the plan before it starts, so a
step that keeps failing cannot loop, and a failure ends the plan and is
shown on the page. GET /rest/upgrade reports the step in progress, POST
/rest/upgrade starts it. platform.cli os status prints the release, and
platform.cli os upgrade starts the Debian upgrade now.

The domain update also reports the running kernel
(/proc/sys/kernel/osrelease) next to the release (redirect #106). Board
kernels ship outside dpkg and stay as they are through the upgrade, so
the next release's rollout needs to know which kernels are out there.

Nothing used to stop these updates from running into each other, and
two combinations leave a device that cannot update itself again. The
snapd upgrade ran upgrade.sh as a child of the backend: a platform
refresh, or the reboot after a Debian upgrade, killed it halfway
through copying snapd's binaries, leaving snapd stopped and half
replaced. It now runs in its own transient unit,
platform-snapd-upgrade, which the backend only waits for. And every
update now starts only when no other one is running (update.Guard: no
snap change in progress, no snapd upgrade unit, no Debian upgrade
unit): the button, the nightly snapd and Debian jobs, the reboot that
finishes a Debian upgrade, platform.cli os upgrade, and the installer
and platform upgrade endpoints. App installs and upgrades only wait for
a snapd upgrade, so several apps can still be queued together. A
nightly job that finds another update running tries again on its next
tick within its hour instead of skipping the night. snapd's own
auto-refresh window (23:00) is outside platform's control; it does not
overlap the 03:00 Debian upgrade or the 05:00 snapd upgrade, both of
which wait for it.

The nightly job starts only on devices redirect has enabled, and only as
far as redirect allows: the domain update response carries
os_upgrade_target (redirect #106), the release the domain may upgrade
to, and the redirect service keeps the latest value. The job upgrades
only to a release this platform knows a path to: a target it does not
know, whether a typo or a release newer than this platform, means no
upgrade, and so does no target or a device already at it. Each release
therefore gets its own rollout, boris first and then the rest, and can
be stopped from redirect without a platform release. Finishing an
upgrade that already ran (the reboot) does not depend on it.
platform.cli os upgrade is an explicit request and goes to the newest
known release, ungated.

os-upgrade takes the target as an argument and works out the whole path
to it before it touches anything, so a target it has no path to, or
one behind the current release, fails without changing the system.

A new amd64 CI step installs this platform on a clean buster container
of its own, runs the upgrade through the CLI and checks the release,
the reboot marker, the platform services, snapd and the sources. It
shares the runner's /dev, which snapd needs for loop devices, but not
dbus, which a release upgrade would restart under the host. Measured
in CI: 7m05s for the whole step, about 6 minutes of it the two hops.

The CI buster image already has a merged /usr, and usrmerge refuses
to convert on overlayfs anyway, so the conversion that older buster
devices (boris among them) go through during the bookworm hop is not
covered in CI. It was run by hand on a KVM VM booting an unmerged
buster debootstrap with the Syncloud package set from ext4 on the
buster 4.19 kernel: the conversion succeeded, ssh answered throughout,
and the VM came back up on bookworm with no failed units and a clean
dpkg --audit.
@cyberb
cyberb force-pushed the os-upgrade-bookworm branch from 8cccbaa to 7398ab8 Compare December 5, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant