Skip to content

os: a boot chain mounts its own data partition and says LIVE from USB or INSTALLED on <disk> (#711) - #727

Merged
bong-water-water-bong merged 3 commits into
osv2/709-efivarfs-bootentryfrom
osv2/711-boot-identity
Nov 1, 2026
Merged

bong-water-water-bong merged 3 commits into
osv2/709-efivarfs-bootentryfrom
osv2/711-boot-identity

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes #711. After the first install the firmware fell back to the stick, and init mounted the internal NVMe's
data partition (same label), ran the stick's kernel over the installed system's data and said "live usb" while
the banner facts came from the NVMe.

The boot chain now says where its data lives: mkimage makes a data-partition UUID and puts 1bit.data=UUID=...
on the kernel command line, which lives in the grub.cfg of the ESP the firmware just loaded; 1bit-install gives
the target disk its own UUID and rewrites the copied grub.cfg - after step 6 has verified the copy byte-for-byte.
init mounts exactly that partition, derives the parent disk and whether it is removable, and the chooser, the
MODE lines and 1bit-menu's header say LIVE from USB /dev/sda or INSTALLED on nvme0n1. The QEMU gate asserts
the installed banner names the disk.
PR-READY.

bong-water-water-bong added 3 commits November 1, 2026 00:52
… or INSTALLED on <disk> (#711)

Two 1BIT-DATA partitions are normal once a machine is installed, and LABEL=1BIT-DATA answered with
whichever the kernel found first: the first install's fallback boot ran the stick's kernel over the
NVMe's data and said 'live usb' while the banner facts came from the NVMe. mkimage now makes a data
UUID and names it on the kernel command line (1bit.data=UUID=...), which lives in the grub.cfg of the
ESP the firmware just loaded; 1bit-install gives the target disk its own UUID and rewrites the copied
grub.cfg after the byte-for-byte verification. init mounts that partition and nothing else, and the
chooser, the MODE lines and 1bit-menu's header name the device: LIVE from USB /dev/sda, or
INSTALLED on nvme0n1. The QEMU gate asserts the installed banner names the disk.
…ading digit is not a shell assignment (#710)

The gate passed '1BIT_INSTALL_NO_REBOOT=1 1bit-install …' over ssh and the remote sh answered
'sh: 1BIT_INSTALL_NO_REBOOT=1: not found' (rc=127): a name that starts with a digit is not a valid
variable assignment, so the shell read it as a command. Renamed in install.sh and vmtest.sh.
… as the machine's own address (#711, #705)

The QEMU live boot said 'LIVE from the internal disk /dev/sda' for a usb-storage stick (QEMU reports
removable=0 for it), and 'Lemonade: up on http://0.0.0.0:13305/' which is not an address anyone can open.
The bus the disk sits on decides USB, and a 0.0.0.0/:: bind is shown as the first global IPv4.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY

At 5ec6111f (+81 −16, 5 files). The last of the stack, and the bug it fixes is the nastiest one in it.

The fix is wired at both ends, which is what makes it real. init.sh reads its own data partition from the cmdline:

dataspec=$(sed -n 's/.*[[:space:]]1bit\.data=\([^[:space:]]*\).*/\1/p' /proc/cmdline)
… if [ -n "$dataspec" ]; then data=$(findfs "$dataspec"); else data=$(findfs LABEL=1BIT-DATA); fi

and the two writers both produce that token: mkimage.sh:685 appends 1bit.data=UUID=$datauuid to the live grub cmdline, install.sh:318 rewrites 1bit.data=UUID=… in the installed ESP's grub.cfg to the UUID it just created (and logs it). So the boot chain names its own data partition instead of a label that two partitions can share — the 2026-10-31 failure (stick kernel + installed system's /data, banner saying "live usb" while the facts came from the NVMe) cannot recur, and the LABEL= lookup stays as the fallback rather than the rule.

Both gate strings survive, which is the check this stack exists to protect:

  • MODE: INSTALLED on ${disk:-an unknown disk} still contains INSTALLED, and the new gate assertion wants INSTALLED on nvme, which is exactly what the banner now prints;
  • the live line keeps LIVE: runs from RAM verbatim, with [from $WHERE] appended.

bash -n clean on all five files, and the partition node → parent disk derivation (/sys/class/block/<node>/..) is the right way to name the disk for the banner.

Not verified: the two-partition case itself needs the QEMU install gate (install, then boot with the stick still attached) — deferred while another lane's VM is live. That is the run this PR deserves, since it is the exact scenario it was written for; it belongs with #726's boot-entry check in one gate run.

tprs-ready applied. Stack note: #719 and #720 are still the two items holding this whole chain.

@bong-water-water-bong bong-water-water-bong added the tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied label Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

711 - Partially compliant

Compliant requirements:

  • The boot chain now uses UUIDs to identify the data partition, preventing label collisions
  • The init script mounts the specific data partition identified by the UUID in the kernel command line
  • The banner clearly states whether the system is running from a live USB or an installed system on a specific disk
  • The installer assigns a unique UUID to the installed disk's data partition and updates the grub.cfg
  • The installer verifies the copied grub.cfg byte-for-byte before modifying it to point to the new data partition

Non-compliant requirements:

  • None

Requires further human verification:

  • The QEMU gate assertions for the installed banner naming the disk should be verified on actual hardware
⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Potential race condition in disk detection

The code uses readlink -f to determine the parent disk of a partition, but this could potentially race with the kernel's device enumeration if the device is not yet fully initialized. This could result in disk being empty or incorrect, leading to an inaccurate "WHERE" message. While the code has fallbacks, a more robust approach might be needed for very slow devices.

disk=${data#/dev/}; disk=${disk##*/}
disk=$(basename "$(readlink -f "/sys/class/block/$disk/.." 2>/dev/null)" 2>/dev/null || echo "")
removable=$(cat "/sys/class/block/${disk:-none}/removable" 2>/dev/null || echo 0)
# a USB stick can report removable=0 (QEMU's usb-storage does): the bus it sits on is the honest answer
case "$(readlink -f "/sys/class/block/${disk:-none}" 2>/dev/null)" in *usb*) removable=1 ;; esac
UUID consistency in grub.cfg

The UUID is generated in mkimage.sh and then used in install.sh to update the grub.cfg. If the UUID generation in mkimage.sh is not consistent (e.g., due to different random sources or timing), it could lead to a mismatch between the UUID in the kernel command line and the one in the installed grub.cfg. This would prevent the correct data partition from being mounted.

datauuid=$(cat /proc/sys/kernel/random/uuid)

: > "$STEPS"
steps_add "target disk confirmed: $DEV ($model, ${gb} GB)"
steps_add "partition table written (${esp_mb} MB ESP + $DATA_LABEL)"
steps_add "ESP formatted ($ESP_LABEL, vfat)"
steps_add "data partition formatted ($DATA_LABEL, ext4)"
steps_add "boot files copied from the live stick"
steps_add "boot files verified (sha256, read back from the disk)"
steps_add "data partition filled from the live boot"
steps_add ".installed and the key material carried over"
steps_add "firmware boot entry created (1bit OS, first in BootOrder)"
steps_add "final verification (both partitions, read-only)"
steps_draw

# 1: nothing to do - the checks above decided it, and the screen says which disk it is
step_begin 1
step_end 1 OK

# 2: the same script mkimage.sh uses to build the live stick, so an installed disk and a stick are the
# same layout: 2048-sector start, EFI system partition, then the data partition filling the disk
run 2 sh -c "printf 'label: gpt\nstart=2048, size=%s, type=U, name=\"EFI\"\ntype=L, name=\"%s\"\n' $((esp_mb * 2048)) '$DATA_LABEL' | $SFDISK -q '$DEV'"

# the kernel needs a moment to publish the new partitions
i=0
while [ ! -b "$esp" ] || [ ! -b "$data" ]; do
    i=$((i + 1))
    [ "$i" -gt 20 ] && fail 2 "the kernel never published $esp / $data"
    sleep 1
done
sleep 1

run 3 mkdosfs -F 32 -n "$ESP_LABEL" "$esp"
run 4 sh -c "$MKE2FS -q -t ext4 -L '$DATA_LABEL' -U '$datauuid' '$data'"

mkdir -p /tmp/install/esp /tmp/install/data /tmp/install/live-esp
[ -n "$live_esp" ] || live_esp=$(findfs LABEL=$ESP_LABEL 2>/dev/null || true)   # fallback: no /data mount
run 5 sh -c "mount -t vfat '$esp' /tmp/install/esp && mount -t vfat -o ro '$live_esp' /tmp/install/live-esp && cp -a /tmp/install/live-esp/. /tmp/install/esp/"
# the ESP copy is read back from the disk itself: a boot chain that is not byte-identical is not a boot
# chain that boots, and this is the step that would have caught a truncated kernel or initramfs
step_begin 6
ver_bad=0
for f in EFI/BOOT/BOOTX64.EFI EFI/BOOT/grubx64.efi EFI/BOOT/grub.cfg 1bit/vmlinuz 1bit/initramfs.img; do
    [ -e "/tmp/install/live-esp/$f" ] || continue
    a=$(sha256sum "/tmp/install/live-esp/$f" 2>/dev/null | cut -d' ' -f1)
    b=$(sha256sum "/tmp/install/esp/$f" 2>/dev/null | cut -d' ' -f1)
    if [ -z "$a" ] || [ "$a" != "$b" ]; then
        echo "sha256 mismatch on $f: source ${a:-missing}, written ${b:-missing}" >> /tmp/install-step.log
        ver_bad=$((ver_bad + 1))
    else
        log "    $f matches ($a)"
    fi
done
[ "$ver_bad" = 0 ] || fail 6 "$ver_bad boot file(s) do not match the source"
step_end 6 OK

# 7: the data partition. The live ESP is unmounted here rather than earlier, because step 6 read from it.
step_begin 7
# #711: before the ESP goes, point this disk's grub.cfg at THIS disk's data partition. It is done after
# step 6 on purpose: the copy is verified byte-for-byte against the source first, and only then does the
# installed system's own copy differ in the one value that must differ.
if [ -e /tmp/install/esp/EFI/BOOT/grub.cfg ]; then
    sed -i "s/1bit\.data=UUID=[0-9a-fA-F-]*/1bit.data=UUID=$datauuid/g" /tmp/install/esp/EFI/BOOT/grub.cfg ||
        fail 7 "cannot point the installed grub.cfg at this disk's data partition"
    log "    grub.cfg on $esp: 1bit.data=UUID=$datauuid (this disk's data partition)"
fi

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Superseded by #742 — the same reviewed content as one commit on origin/main (+598 −63, six files in os/mini/), because #721/#725/#727 were merged into their base branches rather than main and each later branch was then built on a base that had moved (which is why #726 read CONFLICTING). Both review fixes are in #742 (/dev/kmsg transcript for #703; ls-tree HRX pin for #704). Please close this one and merge #742 so nothing lands twice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review effort 4/5 tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant