Identify new persistence partition by start sector, not lsblk's tail.
Some checks failed
Controller Tests / controller-tests (push) Has been cancelled
Jest Tests / jest-tests (push) Has been cancelled

The fallback after `partx -a` (which is wrapped in `|| true` and can
silently no-op) was `lsblk -lnpo NAME "$BOOT_DRIVE" | tail -1`.  If the
new partition node has not appeared in the kernel's partition table yet,
that fallback returns the previous last partition — typically sdb2 (the
ESP) or sdb1 (the live ISO data partition).  Both are valid block
devices, so the `[ -b ... ]` guard passes; the next line is
`mkfs.ext4 -L persistence -F`, which wipes whichever wrong partition the
fallback returned.  Narrow conditions, but catastrophic when triggered.

Switching to matching on the start sector we just assigned via sfdisk:
no existing partition can share it, so the result is unambiguous.  Retry
loop allows up to 5s for udev to register the new node.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Roland 2026-05-22 22:17:09 -06:00
parent 2ac2f20ec5
commit 6862f21598
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680

View file

@ -74,12 +74,24 @@ if [ -z "$PERSIST_PART" ]; then
# a re-read of the whole partition table.
echo "start=$START, type=83" | sfdisk --append --no-reread --force "$BOOT_DRIVE"
partx -a "$BOOT_DRIVE" 2>/dev/null || true
udevadm settle || true
PERSIST_PART=$(blkid -L persistence 2>/dev/null || true)
if [ -z "$PERSIST_PART" ]; then
PERSIST_PART=$(lsblk -lnpo NAME "$BOOT_DRIVE" | tail -1)
fi
if ! [ -b "$PERSIST_PART" ]; then
# Identify the new partition by the start sector we just assigned to it.
# We deliberately avoid `lsblk | tail -1` here: if partx -a or udev have
# not registered the new node yet, that fallback would return the
# existing last partition (typically the ESP or the live data partition)
# — and the mkfs.ext4 -F below would wipe it. Matching on start sector
# is unambiguous: no existing partition can share it. Retry up to 5s
# for udev to settle and the partition node to appear.
PERSIST_PART=""
for _i in 1 2 3 4 5; do
udevadm settle || true
PERSIST_PART=$(lsblk -lnpo NAME,START "$BOOT_DRIVE" 2>/dev/null \
| awk -v s="$START" '$2 == s {print $1; exit}')
[ -n "$PERSIST_PART" ] && [ -b "$PERSIST_PART" ] && break
PERSIST_PART=""
sleep 1
done
if [ -z "$PERSIST_PART" ] || ! [ -b "$PERSIST_PART" ]; then
log "ERROR: failed to locate the newly created persistence partition"
exit 1
fi