Skip to content

Consolidate partition derivation on lsblk-by-PARTLABEL — where early boot allows it - #958

Merged
VijitSingh97 merged 2 commits into
develop-v2from
refactor/926-partition-derivation
Aug 14, 2026
Merged

Consolidate partition derivation on lsblk-by-PARTLABEL — where early boot allows it#958
VijitSingh97 merged 2 commits into
develop-v2from
refactor/926-partition-derivation

Conversation

@VijitSingh97

Copy link
Copy Markdown
Collaborator

Closes #926, with the honest partial scope the issue asked for: pithead-data-reset's boot_disk_part() and pithead-install now share the lsblk-by-PARTLABEL shape; pithead-mount-generator deliberately keeps its positional arithmetic — lsblk's PARTLABEL lookup is udev-database-first and generators run before systemd-udevd, an unprovable early-boot dependency the commit documents in place.

Review round closed three findings (this is the reformat path — a wrong device here formats the wrong disk):

  • repart.d's Label=ESP (uppercase) contradicted every path that actually creates an ESP (mkimage/installer sgdisk: lowercase esp) — a latent trap normalized at the source. The verifier flagged this as critical against the lookup; ground truth showed live systems are all-lowercase, so the fix is the config file, not the lookup.
  • boot_disk_part returned rc 0 with empty output on a missing label (awk exits 0 either way) — now fails closed.
  • the stub test hand-typed labels that happened to match the code — it now DERIVES them from mkimage's sgdisk line and repart.d's Label=, so casing/name drift fails the test instead of green-lighting a dead lookup.

Solo suite 2192/0. Battery boot/install phases are the live proof (queued). Ponytail: net-deletion consolidation.

🤖 Generated with Claude Code

VijitSingh97 and others added 2 commits August 13, 2026 23:32
Three shapes of the same boot-disk/partition derivation existed:
pithead-mount-generator's awk/sed suffix arithmetic, pithead-data-reset's
own copy of that arithmetic, and pithead-install's simpler
`lsblk -lnpo NAME,PARTLABEL` scoped to the resolved disk.

pithead-data-reset now resolves its data/ESP partitions the same way
pithead-install already does: find the boot disk via `lsblk -no PKNAME`
(sysfs-only, no udev needed), then look up the PARTLABEL on that one
already-resolved disk. Behavior is unchanged — same partitions, same
fail-safe handling when a label isn't there yet (first boot, pre-repart).

pithead-mount-generator is deliberately left on its own derivation. It is
a systemd generator, which per systemd.generator(7) runs before any other
unit — including systemd-udevd — and "cannot rely on any external
services". lsblk's PARTLABEL column is sourced from the udev database
first, falling back to a direct blkid probe only once that database is
unavailable, and lsblk(8) itself recommends a `udevadm settle` first when
timing might be an issue — a settle a generator has no daemon left to run
against. Moving the generator onto lsblk would trade a self-contained
derivation (touches only /proc, does its own arithmetic) for one with an
unprovable early-boot dependency, which is the opposite of what this
refactor is for. Both files now carry the reasoning inline.

lsblk itself is not newly required: it ships via util-linux, an Essential
Debian package present in every debian:trixie-slim build regardless of
the image's explicit apt list, and pithead-install already calls it on
the appliance today.

Adds tier-1 coverage for pithead-data-reset's boot_disk_part() with
stubbed findmnt/lsblk (tests/stack/run.sh), covering the data and ESP
lookups, an absent label (first boot, before repart creates the
partition), and a non-/dev root (container/unexpected boot source).

make lint: all surfaces clean (shellcheck, ruff, biome, yamllint,
markdownlint, docs-voice, operator-strings, buf, taplo).
make test: pithead tests: 2190 passed, 0 failed (tests/stack/run.sh,
includes the new boot_disk_part coverage); dashboard 1763 passed
(96.72% coverage); frontend 312/312; test-compose all green;
selftest 154 passed, 0 failed; test-fakes 23 passed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…idation

- repart.d's 10-esp.conf declared Label=ESP while every path that
  actually CREATES an ESP labels it lowercase (mkimage sgdisk,
  pithead-install) — the rule only ever matches the existing ESP, but a
  second casing is a trap; normalized at the source with the reasoning.
- boot_disk_part returned rc 0 with empty output when no partition
  carried the label (awk exits 0 either way) — now fails closed.
- the stub test hand-typed lowercase labels that happened to match the
  code — it now DERIVES them from mkimage.sh's sgdisk line and
  repart.d's Label=, so a future casing/name drift fails the test
  instead of green-lighting a dead lookup.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@VijitSingh97
VijitSingh97 merged commit 4460411 into develop-v2 Aug 14, 2026
16 checks passed
@VijitSingh97
VijitSingh97 deleted the refactor/926-partition-derivation branch August 14, 2026 20:46
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