Skip to content

fix(layout): find the disk under a device-mapper label - #362

Open
ci-robbot wants to merge 1 commit into
mudler:masterfrom
ci-robbot:fix/layout-grow-device-mapper
Open

ci-robbot wants to merge 1 commit into
mudler:masterfrom
ci-robbot:fix/layout-grow-device-mapper

Conversation

@ci-robbot

Copy link
Copy Markdown
Contributor

Fixes kairos-io/kairos#6165

What

When COS_PERSISTENT is on an encrypted partition, the label resolves to the LUKS mapping /dev/dm-0. parentDiskFromBlockDev took the parent directory of /sys/class/block/dm-0 as the disk. A device-mapper device lives in /sys/devices/virtual/block, so the disk came out as block and Grow persistent failed on every boot:

derive parent disk for /dev/dm-0 (got block): stat /sys/class/block/block: no such file or directory

How

  • backingDevice follows a device-mapper device through /sys/class/block/<dm>/slaves to the partition under it (stacked mappings too). FindDiskFromLabel and labelIsOnLastPartition use that partition, so the disk and the partition number are correct.
  • Disk.Mapper records the mapping, and the expansion is skipped with an info message when it is set. Growing through LUKS needs cryptsetup resize, and on LUKS2 that needs the volume key, which the plugin does not have. So this PR does not grow an encrypted partition; it stops the error.
  • The sysfs lookups take a root so tests can use a fake sysfs tree.

Verified

New unit tests build a fake sysfs (plain, nvme, LUKS on a partition, stacked mappings, a mapping on two devices, an image file). go test ./pkg/plugins/ and go vet ./pkg/plugins/ pass. Not booted on an encrypted install.

This PR was written with AI assistance (Claude Code).

🤖 Generated with Claude Code

When COS_PERSISTENT is on an encrypted partition, the label resolves to
the LUKS mapping /dev/dm-0. parentDiskFromBlockDev took the parent
directory of /sys/class/block/dm-0 as the disk, but a device-mapper
device lives in /sys/devices/virtual/block, so the disk came out as
"block" and the "Grow persistent" stage failed on every boot.

Follow a device-mapper device through /sys/class/block/<dm>/slaves to
the partition it sits on, and use that partition to find the disk and
the partition number. Expanding through the mapping is not done: the
LUKS2 mapping can only be resized with the volume key, which the plugin
does not have. The plugin now skips the expansion with an info message.

The sysfs lookups take a root so the tests can build a fake sysfs tree.

Fixes kairos-io/kairos#6165

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: mudler-agent <105103991+ci-robbot@users.noreply.github.com>
@mudler

mudler commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@ci-robbot needs QA

@itxaka-agent

Copy link
Copy Markdown

Automated triage agent (kairos-triage-agent) running as @itxaka-agent.
This comment was generated by software. A human maintainer can override
any action taken here.

QA: pass at 1ee8412, details and proof: kairos-io/kairos#6165 (comment)

@ci-robbot

Copy link
Copy Markdown
Contributor Author

Picking this up for QA.

@ci-robbot

Copy link
Copy Markdown
Contributor Author

QA Result: PASS

Tested at 1ee8412 in a full Kairos image, booted from an encrypted install. This adds to the standalone test on kairos-io/kairos#6165, which left "a full Kairos image with the yip bump" untested.

Check Result
Environment Released kairos-hadron-v0.6.3-core-amd64-generic-v4.5.2.iso, remastered twice with a kairos binary built from kairos master d98625b79. That binary is used for immucore in the initrd and for the agent. The two builds differ only in yip: base is e8a2711 (the merge base of this PR), PR is 1ee8412. Both binaries go into the ISO initrd, the rootfs, and the rootfs's own initrd. QEMU/KVM, BIOS, swtpm, a 16G disk installed with install.auto, then grown to 20G before the first boot.
Reproduction 1. encrypted_partitions: [COS_OEM, COS_PERSISTENT] (the bug path at boot), boot twice per arm. 2. encrypted_partitions: [COS_PERSISTENT], boot, then run the image's own Grow persistent step on the booted node with kairos-agent run-stage rootfs.after. 3. Unencrypted install, boot twice per arm, as a regression control.
Expected Encrypted: no derive parent disk error, an info line that the expansion is skipped, LUKS volume untouched, the node unlocks and mounts /usr/local. Plain: same behaviour on both arms.
Actual As expected. Details below.
Proofs immucore and agent log excerpts below, from /run/immucore/immucore.log.

1. COS_OEM + COS_PERSISTENT encrypted, real boot. immucore unlocks before the OEM mount, so COS_PERSISTENT -> dm-1 (stacked, OEM is dm-0) when rootfs.after runs. Same result on boot 1 and boot 2.

Base (v4.5.2-qabase):

INF OEM is encrypted: kcrypt unlock will run before OEM mount
INF Processing stage step 'Rootfs Layout Settings.Grow persistent'.
WRN Exiting, disk with label COS_PERSISTENT not found: derive parent disk for /dev/dm-1 (got block): stat /sys/class/block/block: no such file or directory
ERR Error on file /system/oem/00_rootfs.yaml on stage Grow persistent: derive parent disk for /dev/dm-1 (got block): stat /sys/class/block/block: no such file or directory
WRN stage completed with errors error="2 errors occurred: * no metadata/userdata found * derive parent disk for /dev/dm-1 ..." stage=rootfs

PR (v4.5.2-qapr), boot 2:

INF OEM is encrypted: kcrypt unlock will run before OEM mount
INF Processing stage step 'Rootfs Layout Settings.Grow persistent'.
INF COS_PERSISTENT is on the device-mapper device /dev/dm-1, skipping expansion: growing a partition under device-mapper (such as an encrypted LUKS volume) is not supported
WRN stage completed with errors error="1 error occurred: * no metadata/userdata found" stage=rootfs

After both boots, vda5 is still 12.4G with its crypt child, and /dev/mapper/vda5 is mounted on /usr/local.

2. COS_PERSISTENT encrypted only. At boot, immucore runs rootfs.after before unlock-all, so the label does not exist yet. Both arms log the same resolve label "COS_PERSISTENT": lstat /dev/disk/by-label/COS_PERSISTENT: no such file or directory, and the PR does not change that (see the note below). After boot the label resolves to /dev/dm-0 (slaves: vda5). Running the image's Grow persistent step on its own with kairos-agent run-stage rootfs.after:

base: ERR Error on file .../grow.yaml on stage Grow persistent: derive parent disk for /dev/dm-0 (got block): stat /sys/class/block/block: no such file or directory
pr:   INF COS_PERSISTENT is on the device-mapper device /dev/dm-0, skipping expansion: ...

3. Unencrypted control. Both arms behave the same. Boot 1 grows vda5 from 12.4G to 16.4G and logs the deferred re-read error. Boot 2 runs clean.

Notes, not caused by this PR:

  • With only COS_PERSISTENT encrypted (the default encrypted install), the Grow persistent step still logs an error on every boot, now resolve label ... no such file or directory, because it runs before the unlock. This PR fixes the COS_OEM-encrypted ordering, and the run-stage path, where the label already points at the mapping.
  • On a disk that was grown, the PR arm logs ERR Could not verify headers for /dev/vda: secondary Header is not at end of the disk once, just before the skip line. The existing GPT repair then moves the backup header, and no partition changes. The plain arms log the same line on both builds.
  • Unencrypted, both arms: after the partition grew to 16.4G, /usr/local still showed 13G on boot 2. The filesystem was not resized in the boots observed here.

Summary: On a real Kairos boot with an encrypted persistent partition behind a mapping, the fix turns the derive parent disk for /dev/dm-N error on every boot into an info-level skip. The LUKS volume is left alone, and unencrypted installs behave the same as on the merge base.

QA performed by ci-robbot (AI agent, Claude Code). A human did not review this verdict before it was posted.

@ci-robbot ci-robbot moved this from QA to QA OK in 🧙Issue tracking board Nov 19, 2026
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.

yip layout: "Grow persistent" fails on every boot when COS_PERSISTENT is on an encrypted (LUKS) partition

3 participants