Repository navigation
os: an installed machine can take the next appliance without losing its state (#712) - #1334
Conversation
…ts state (#712) Until now an update of an installed 1bit OS was "write the next image", which takes the save layer - home, services, /etc - with it, and there was no way back if the new appliance did not boot. An installed machine now carries two slots on its data partition and ONE save layer: /1bit psubdir=1bit set A /1bit-alt psubdir=1bit-alt set B, created by the first update The layer stays where the machine was installed and the other slot reaches it through a relative `upup64rsave` symlink, so Puppy's find_save_file + setup_psave use the same layer from either slot: an update changes the OS and not the machine. That mechanism was measured before any product code (second set + one GRUB entry + the symlink + a file written into the layer's upper dir before the boot: PUPMODE=12, root layer through the link, the file present). `1bit-update <release-dir | image.img>` writes the next appliance into the slot that is NOT running, checks the release first (the running set's own file names; a SHA256SUMS verified for those files when present; free space), cmp's every copied byte, links the layer, adds that slot's GRUB entries from the running entry's own UUID-pinned boot line, flips `set default` and re-reads the config the way GRUB counts entries before it says UPDATED. Refusals: not installed, no psubdir=, an active set with no save layer, a target slot that already owns a layer, too little space, a damaged release, and a grub.cfg that does not end up booting the slot it wrote (restored from its backup). `--rollback` flips the default back; `--status` says which slot runs, what each holds and what GRUB boots. update-gate.sh measures it over three boots of one installed disk: the update, a boot on psubdir=1bit-alt with PUPMODE=12, the new set's own marker file AND the state written before the update, then --rollback and a boot on /1bit with the previous appliance intact.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: CHANGES at a0cc2d5064260e75e6c95ea0bffde93bb9806657. The design is sound and the first update works as the gate shows. But a machine can take exactly one update: the second one, the normal next release, is refused, and the gate never runs it.
The defect. save_slot is defined as the slot holding the real layer directory (1bit-update:96-106, [ -d "$s" ] && [ ! -L "$s" ]). The update only ever symlinks the layer into the other slot (:249, ln -sfn "../$save_slot/$savename"), so save_slot stays 1bit forever. After the first update the machine runs from /1bit-alt, so the next update's target is 1bit (:80). The target guard (:235-243) then finds /1bit/upup64rsave as a real directory, which is the machine's own shared layer, and dies:
# a fake data partition laid out as the gate leaves it after boot 2 (/1bit/upup64rsave a real dir,
# /1bit-alt/upup64rsave -> ../1bit/upup64rsave), running the script's own lines 79-83, 96-106 and 235-243 verbatim:
active=1bit-alt target=1bit save_slot=1bit savename=upup64rsave
DIE(rc 2): /1bit already holds a save layer (upup64rsave): two layers cannot be merged by an update - pick the slot by hand if that is really what you want
So the lifecycle is: update 1 works; update 2 is refused unless the user first rolls back to the old appliance. The guard means "another machine's state", but here it is this machine's state.
Also on that path: if the guard were simply skipped, :249 would run ln -sfn ../1bit/upup64rsave /data/1bit/upup64rsave against a real directory. ln would then create a self-referencing upup64rsave/upup64rsave link inside the layer instead of replacing anything. The fix needs both halves.
Fix:
- when
target == save_slot, the layer in the target is the shared one: skip the merge guard for exactly that entry, and do notlnover it (the running slot already reaches it through its own link); - add a 4th and 5th boot to
update-gate.sh: frompsubdir=1bit-alt, run a second1bit-updatewith a third marker set. It must come uppsubdir=1bit,PUPMODE=12, with the boot-1 marker still present and noupup64rsave/upup64rsave. That is the row that proves an installed machine can keep updating, which is #712 item 2's actual claim.
Checked and fine
- Write ordering is safe: copy into the inactive slot,
cmpevery file,sync, and only then back upgrub.cfg(.pre-1bit-update) and changeset default. A failure while copying leaves GRUB on the running slot. - The refusals before writing: not root, not installed (
/data/.installed), nopsubdir=, an unknown slot name, no save layer (pre-#1291), too little space (+256 MiB slack), a release missing the running set's file names, and aSHA256SUMSthat fails for those files.
Nit: with no SHA256SUMS the update proceeds ("sizes are checked, the bytes are not"). The cmp after copying proves a faithful copy of the source, not a good source. Consider requiring an explicit --no-verify for an unhashed release, since this is the path that replaces the bootable appliance.
Not run: the three-boot gate itself, which needs the install gate's VM disk. The defect above is on a path the gate does not exercise.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: READY at a0cc2d5064260e75e6c95ea0bffde93bb9806657
I read the updater as the thing it is — a program that can brick an installed machine — and every invariant that matters is enforced in the code, not just documented. bash -n is clean on 1bit-update, update-gate.sh and container-build.sh. I did not run the gate (update-gate.sh needs qemu-system-x86_64, sudo, loop devices and three real boots of an installed target.img, ~600 s each); everything below is the script's own logic, which is where the damage would come from.
The blast radius is bounded by construction:
- it refuses to be an updater on anything but an installed disk — root,
/datamounted, and$DATA/.installedpresent; a live stick gets "a stick is replaced by writing the next image, it is not updated in place", and a disk whosepsubdir=it cannot name gets "this disk was not laid out by 1bit-install". So the failure mode "ran it on the wrong thing" is a refusal, not a partial write; - it writes only the slot that is not running, and names that slot from the boot line, never from a guess;
- the source is checked before anything is written: it must carry the running set's own file names (
vmlinuz initrd.gz+ the running slot's*.sfs), aSHA256SUMSis verified for exactly those files when present, and free space is required to beset + 256 MiB— with the honest fallback stated in the log when a release carries no sums ("sizes are checked, the bytes are not"); - another machine's state cannot be clobbered: a target slot that already holds a real save layer is refused ("two layers cannot be merged by an update"), while a stale link is replaced;
- every copy is
cmp'd against the source, thensynced, before GRUB is touched.
The GRUB flip is done the careful way, which is the part I most expected to find fragile: it backs up grub.cfg to $cfg.pre-1bit-update, builds the new entries from the running slot's own linux line (skipping the 1bit.serial=1 one), appends only if absent, sets set default=<index>, and then re-reads the file the way GRUB counts entries — the Nth menuentry must be the one whose linux line carries psubdir=<target> — and restores the backup if that read-back fails. A half-applied GRUB edit is the classic way to make a machine unbootable, and this cannot report success with one.
Rollback is a set default flip with nothing moved (--rollback requires the other slot to have a non-empty initrd.gz first, so it cannot "roll back" to an empty slot), and both sets stay on the disk — so even a bad update leaves the previous appliance bootable, which is the property the PR exists to add.
The mechanism was measured before the code was written, and that is in the record: the save-layer symlink was proven on the install gate's own disk (pupsfs=… psubdir=1bit-alt, PUPMODE=12, the layer found through the link, a marker written on boot 1 present on boot 2). PUPMODE=12 rather than 5 is the interesting detail — it is what proves the link is followed rather than a second layer being created, i.e. that the two slots share one machine's state instead of forking it.
What the gate will add when pi-release runs it (update-gate.sh, three boots: update → must come up on 1bit-alt with the boot-1 marker intact → rollback → must come back on 1bit with the new set's marker gone and the boot-1 marker still there) is the end-to-end proof of exactly those invariants. My verdict is about the script being safe to hand to that gate and to an installed machine; if the gate finds a boot problem, this READY is about the code, not the boot.
Nit, one line: the free-space check covers the new set and the checksums but not the ESP, where the four appended menuentry lines go — trivial in size, but the ESP is the one place a write failure is unrecoverable-without-a-rescue-stick, so a df against $esp before mount_esp would close the last "could fail half-way" path. --status and --rollback both unmount the ESP on every exit path I traced, which is right.
|
For the merge queue: both verdicts are at |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT: CHANGES at 81ae64eea149ce7234f11d2c328a7d412493d510. Main merges only since a0cc2d50: no non-merge commit of its own, and the PR's own +/- lines against its merge-base are identical (hash 27cd4a602b66). 1bit-update is byte-for-byte the same, including the target-slot guard at :235-243. So the defect from my CHANGES at a0cc2d50 stands: the second update is refused on the machine's own save layer (save_slot stays 1bit, and from /1bit-alt the guard dies), and the gate never runs a second update. Fix: the target == save_slot exemption, no ln over the real directory, and gate boots 4-5.
|
Post-merge note: this merged at 16:10:21Z at |
) (#1385) * os: the shared layer is identified by file, and a release without hashes needs --no-verify (#1376) Two things on top of the second-update fix, both from review: * **identity by file, not by name** (pi-os3's correction on #1378). The guard asked whether the target slot holds a layer with the same SLOT and the same NAME. That is right for this issue - the layer keeps its name across the slots - but it silently accepts a hand-copied or restored upup64rsave, which is a different directory carrying this machine's name, and refusing exactly that is what the guard exists for. `[ "$s" -ef "$1/$save_slot/$savename" ]` compares device+inode: the same file. New arm in tests/one_bit_update_slots_test.sh for the case a name check passes. * **the two nits from the #1334 review**: a release with no SHA256SUMS now needs an explicit `--no-verify` (this path replaces the appliance the machine boots), and the ESP gets its own free-space check before the grub.cfg rewrite. The operator also gets the "holds this machine's save layer ... left in place, no link needed" line. update-gate.sh runs FOUR boots now: the update, a boot on 1bit-alt, the second update FROM there into the slot that holds the layer, a boot on 1bit with the second set and no nested link, then a rollback and a boot on the first updated set. Two releases are built from the disk's own SFS so which set is running is read off the machine, and RESET=1 puts a used disk back to the post-install state so the gate can be re-run without re-installing. * os: an image carries its set's hashes, so the image form never needs --no-verify (#1385 review) Three findings from the review, plus the row it asked for. 1. **Blocking: `--no-verify` had become mandatory for every shipped image.** For `1bit-update <image.img>` the source is the image's own /1bit, and nothing in `os/` wrote a SHA256SUMS there, so every weekly image would have refused - and the gate could not see it, because it only ever builds release directories and writes their sums itself. Fix at the source: **`mkimage.sh` writes `/1bit/SHA256SUMS`** from the bytes it just copied, so the image form verifies against the image's own hashes. The refusal message no longer points at the data-partition root either. 2. **A gate row for the image form**, which is where that fix is testable: the gate now builds a real .img in the guest (GPT partition labelled 1BIT-DATA holding /1bit + SHA256SUMS) around a THIRD marker set, updates from it on boot 4 with the user's own command, and boot 5 must show that set running, PUPMODE=12, its marker present and the boot-1 marker intact. The row asserts the log's `1bit/SHA256SUMS` line, so the HASH SOURCE is what is tested. 3. **The -ef rationale was wrong** and is corrected in the code comment, the test comment and docs/os-v3.md: the name form also refused a same-named foreign layer, because it required the slot to match too (the reviewer ran the new arm against main's updater and it passed). -ef stays as the clearer statement of intent; the arm stays as a regression guard; the false claim is gone. 4. Nit: the ESP free-space check moved BEFORE the copy (it used to refuse a full ESP after ~1.5 GB was already written into the other slot). * os: the image form reads the partition offset sfdisk actually prints (#1385 review follow-up) The new image-form gate row found that `1bit-update <image.img>` had never worked: its awk took the field `start=`, stripped the prefix and printed that - but `sfdisk -d` prints `start=` and the sector number as TWO fields, so the offset came back empty and every image was refused with "has no 1BIT-DATA partition (not a 1bit OS image)" while the partition was right there. So the review's finding 1 (no SHA256SUMS in images) was the second of two independent blocks on the image form, and the row it asked for is what caught the first one. Read the number wherever it is (`start=2048,` or `start= 2048,`), checked against a real sfdisk -d on a GPT image before re-running the gate. * os: the image-form gate row builds a real image, and checks it before using it (#1385 review) The row's first version escaped the printf one level too deep, so the guest's sfdisk received a single mangled line, the 'image' had no partition table, and `1bit-update` refused it - correctly - while the gate reported the product as broken (measured in the guest: 'does not contain a recognized partition table'). The row now writes the table with the escaping printf actually needs, and asserts `sfdisk -d` names 1BIT-DATA before the boot that judges the updater, so a broken fixture fails as a fixture. * os: the update gate refuses a reused disk instead of looking broken (#1385 review) RESET=1 puts the slots and grub.cfg back, but it cannot un-patch the SFS the machine is running - so the next run's "base" already carries a marker, patch-sfs refuses (correctly), and the gate reports the product as broken for a fixture problem (measured: 'etc/1bit/set-alt2 ... already has these bytes'). The gate now refuses a disk that still carries a release directory or the test image, and a patch-sfs failure is reported with the same explanation: this needs a FRESH install, run install-probe.sh first. * os: the gate's first menu selection retries like its reboot does (harness, #1385) The serial-shell selection sent three arrows and one Enter, once, and waited 120 s - inside the range of a loaded boot (measured: 155 s to userspace, and the shell line present in the transcript while the row reported "no serial root shell"). It now presses again on a lost Enter and gives the retry 300 s, the same shape the reboot path already uses. * os: the gate's test image gets a partition table and then a filesystem, in that order (harness, #1385) mkfs.ext4 was formatting the image file itself, which erases the GPT sfdisk had just written - so the fixture had no 1BIT-DATA partition, the updater refused it (correctly) and the check row I added caught it: 'the image's partition table names 1BIT-DATA: 0'. The filesystem now goes into its own file and is dd'ed in at the partition offset, which is what mkimage.sh does. * os: one loop device for the image form, taken at the partition offset (#1385 review) The image path attached the whole image, detached it, and immediately attached it again at an offset - and the second attach raced the detach, so the mount failed with "cannot mount the data partition in ..." (measured in the gate's image-form row). sfdisk reads the file directly and needs no loop at all, so the whole-image attach/detach is gone and there is exactly one loop, opened at the offset. A mount failure now prints the mount's own error instead of a bare refusal. Checked on the box without a VM: a 200 MB GPT image with a 1BIT-DATA partition and an ext4 filesystem dd'ed in at offset 2048 - the same commands, the same awk, losetup -o + ro mount + the set's files readable. * os: update-gate can run just the image form (#1385 review) The row the review asked for is the image form, and the five-boot run it lives in needs ~40 quiet minutes - which a shared box at load 50-73 has not given all night (two chains hit the 2 h timeout). `MODE=image` runs only that claim, in two boots: build the .img in the guest (GPT + a 1BIT-DATA partition with the set and its SHA256SUMS, checked before use), update from it, reboot, and assert the set it carried is running on the machine's own save layer with the marker written before the update intact. The five-boot run stays the full gate for a quiet box. * os: image mode builds its set before the image that needs it (harness, #1385) * os: the set's hashes are verified for every file, not just the two without a ./ prefix (#1385 review) The image-form row found the verification count: 'hashes: 2 file(s) of the set verified' for a set of six, because `sha256sum ./*.sfs` writes "./name" and the membership test compared it to the bare name - so the SFS were copied but never hash-checked. The filter strips a leading ./ now, and the gate row asserts the count covers the set, which is the thing that would have hidden it. --------- Co-authored-by: bong-water-water-bong <[email protected]>
#712, item 2: an installed machine can take the next appliance without losing its state
The last thing an installed 1bit OS could not do that a real OS must: upgrade itself. Until now an "update" was
"write the next image", which takes the save layer — home, services,
/etc— with it, and there was no way to go backif the new appliance did not boot. This adds the two-slot update and measures it end to end.
The design, proven before any product code
An installed machine carries two slots on its data partition and one save layer:
/1bitpsubdir=1bit— the appliance the machine was installed with/1bit-altpsubdir=1bit-alt— created by the first update/1bit/<prefix>save); the other slot reaches it through a relativeupup64rsavesymlinkA symlink is the whole trick, so it was measured before the script was written (
~/wt/i712-alt-slot.py, on the installgate's own installed disk: second set hard-linked into
/1bit-alt, one GRUB entry withpsubdir=1bit-alt, the relativelink, a marker written into the layer's
upper/root/before the boot):So Puppy's
find_save_file(ls -d ${PSUBDIR}/<prefix>save*,[ -d ]) andsetup_psave(mkdir -p $SAVE_FN/upper,then
upperdir=it) both follow the link, and both sets share one machine's state instead of forking it.1bit-updateos/v3/puppy/embed/usr/local/bin/1bit-update:<release-dir>/<image.img>--rollbackset defaultback to the other slot — both sets stay on the disk, nothing is moved--statusAn update checks before it writes and re-reads after: the release must carry the running set's own file names (so the
init will find the same SFS set), a release
SHA256SUMSis verified for those files when present, space is checked,every copied file is
cmp'd against its source, and the rewrittengrub.cfgis re-read the way GRUB counts entriesbefore the run says
UPDATED. It refuses: a machine that is not installed, a boot line with nopsubdir=, an active setwith no save layer (an image older than #1291 — nothing to carry across), a target slot that already owns a layer of its
own (two machines' state cannot be merged by an update), too little space, a damaged release, and it restores its
grub.cfgbackup if the entry it wrote is not the entry GRUB would boot.The gate (
os/v3/puppy/update-gate.sh, three boots of one installed disk)The "next release" is built by the gate from that disk's own SFS plus one file (
etc/1bit/set-alt) and a realSHA256SUMS, so which set is running is a fact read off the running system rather than a date or a size:Candidate:
~/wt/puppy-out-i712f/1bit-os-puppy.img(85f0e1d5…, SFS8da0628a…) = c31's shipped SFS +1bit-install(#1291) +
07onboard-user(#1302) +1bit-update(fd7e4959…). The install gate on the same bytes is== PASStoo(
~/wt/i712-inst4.log). Four runs before that output, and what each caught — every one in my own code, none in thedesign: (1)
patch-sfs.shrefuses an addition through its single-file form (its one-difference check compares the raw
Only in <dir>: <name>line against the target path; the manifest branch is the one with
matches_targetfor that shape) — worked around withthe manifest form, and reported to that tool's owner rather than patched in passing here; (2) my gate's
val()built itssentinel with
%-formatting and the sentinel itself contains%s%Nfromdate +%s%N→TypeError; (3)1bit-updatewrote its checksum scratch file into
/tmp/1bit-update/before that directory existed, and its log was truncated atstart-up, so the failure that followed (
cannot mount the ESP) destroyed its own evidence — the directory is created upfront and the log is appended with its tail printed on failure; (4) two more in the script that only running it found —
the ESP's mount guard compared my spelling of
/tmp/…with/proc/mounts' resolved/initrd/mnt/tmpfs/tmp/…, so anyearlier
--statusmade the next update fail on "already mounted" (esp_mounted()now comparesreadlink -f), and awkgave the first menu entry the empty string as its index (
i = n; n++withnuninitialised), which would havewritten
set default=with nothing after it on a rollback to/1bit—BEGIN { n = 0; i = 0 }in both programs, andthe gate now exercises the index-0 path.
Files
os/v3/puppy/embed/usr/local/bin/1bit-updateos/v3/puppy/update-gate.shos/v3/puppy/container-build.shos/v3/puppy/README.md1bit-updateandupdate-gate.shrowsdocs/os-v3.mdaptupdates inside a set), the refusals, and the measurementrefs #712 — item 2 of the acceptance. Item 3 (the server-shaped rest: firewall default, NTP, hostname/static address,
logging without systemd) stays open and named.