Fixing two wrolpi-portable-bootstrap.service bugs.

LAST_END parser was assigning to a scalar (not MAX), so on iso-hybrid layouts
where the small ESP is listed after the much larger boot partition, sfdisk
got a start sector inside an existing partition.  Also sfdisk -d pads values
with whitespace (`start=          64,`), which broke a naive awk tokenizer.
Switched to a sed parser that strips the padding, and computes the true
MAX(start+size).

`systemctl enable --now wrolpi-api ...` deadlocked: the runtime units have
implicit `After=wrolpi-portable-bootstrap.service` via this unit's `Before=`,
so --now waited forever for them to start while they waited for bootstrap to
finish.  Split enable from start; use --no-block so systemd queues the
starts after we exit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Roland 2026-05-22 20:10:19 -06:00 • committed by lrnselfreliance
parent 76d0b425f3
commit d329c34cbc

View file

@ -55,8 +55,18 @@ log "live medium $BOOT_PART on $BOOT_DRIVE"
PERSIST_PART=$(blkid -L persistence 2>/dev/null || true)
if [ -z "$PERSIST_PART" ]; then
progress "Creating persistence partition on $BOOT_DRIVE..."
# Compute next 1-MiB-aligned start sector after the last existing partition.
LAST_END=$(sfdisk -d "$BOOT_DRIVE" | awk '/^\/dev\// {n=$4+$6} END{print n}')
# Compute next 1-MiB-aligned start sector after the highest-ending existing
# partition. We need MAX(start+size), not LAST: iso-hybrid layouts list a
# small ESP (sdb2) AFTER the main data partition (sdb1) in sfdisk -d output
# even though sdb1 ends much later on disk. Parse via sed because sfdisk -d
# pads values with spaces ("start= 64,") which breaks naive awk.
LAST_END=$(sfdisk -d "$BOOT_DRIVE" \
| sed -n 's|^/dev/[^ ]* *: *start= *\([0-9]\+\), *size= *\([0-9]\+\).*|\1 \2|p' \
| awk '{e=$1+$2; if(e>m) m=e} END{print m+0}')
if [ "${LAST_END:-0}" -lt 1 ]; then
log "ERROR: failed to compute LAST_END from $BOOT_DRIVE partition table"
exit 1
fi
START=$(( ((LAST_END + 2047) / 2048) * 2048 ))
# --no-reread --force: required because the live medium is mounted from
# this same drive. Adding a new partition entry past the mounted one is
@ -148,9 +158,15 @@ mkdir -p /media/wrolpi/config
chown wrolpi:wrolpi /media/wrolpi/config
# --- Enable and start the WROLPi runtime services -----------------------
# These units declare `After=wrolpi-portable-bootstrap.service` (via our
# Before= here in this unit), so a blocking `systemctl --now` would deadlock:
# the runtime units won't start until bootstrap finishes, and bootstrap won't
# finish until systemctl returns. Enable, then start with --no-block so
# systemd queues the starts after we exit.
progress "Starting WROLPi services..."
systemctl enable --now wrolpi-api.service wrolpi-app.service wrolpi-kiwix.service
systemctl enable wrolpi-api.service wrolpi-app.service wrolpi-kiwix.service
systemctl start --no-block wrolpi-api.service wrolpi-app.service wrolpi-kiwix.service
progress "WROLPi Portable is ready."
log "bootstrap complete"