From a08a045940231c8ef95949dfa0a4960aa9ab644d Mon Sep 17 00:00:00 2001 From: mendezr Date: Sat, 19 Sep 2026 17:54:36 +0000 Subject: [PATCH] feat(installer): adopt Flatcar's EFI-SYSTEM/USR-A/USR-B/ROOT partition layout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adopts Flatcar's GPT layout for the installer's target disk, per issue #134 (phase 3 of the Flatcar base migration) and the boot-proof revision in the issue thread. Replaces 10-esp/20-root-a/30-var with five drop-ins using the upstream type GUIDs verbatim: | PARTLABEL | Type GUID | Source | |------------|-----------------------|-------------------------------| | EFI-SYSTEM | c12a7328-… (Type=esp) | bootctl install + the OS UKI | | USR-A | 5dfbf5f4-… | CopyBlocks= the DDI payload | | USR-B | 5dfbf5f4-… | empty A/B rollback slot | | OEM | 0fc63daf-… | ext4, filesystem label OEM | | ROOT | 3884dd41-… | ext4, CopyFiles seeds, grows | BIOS-BOOT stays dropped (UEFI-only, hard rule 5); OEM-CONFIG stays dropped. OEM is required: the boot proof showed stage 2 waits on dev-disk-by-label-OEM.device. The two blockers raised on the closed layout PRs are settled here: - Root discovery: ROOT's GUID is not a Discoverable Partitions type, so the target UKI cmdline now carries root=PARTLABEL=ROOT explicitly, alongside mount.usr=PARTLABEL=USR-A mount.usrfstype=xfs mount.usrflags=ro (dracut --kernel-cmdline and ukify --cmdline kept in sync). systemd v257's fstab-generator resolves both, and switch-root prefers /usr/lib/systemd/systemd from the mounted USR-A when the fresh ROOT has no /sbin/init. PARTLABEL is used because PARTUUID is generated per install and cannot be baked into a UKI. - Mutable state: /var moves onto the writable ROOT. var.mount and zz-enable-var-mount.preset are removed (no producer for /dev/disk/by-partlabel/var remains), and the offline k0s sysext seeding moves to ROOT via CopyFiles=/k0s.raw:/var/lib/k0s/k0s.raw — the exact path k0s-first-boot-fetch.service checks. Because the DDI payload is mounted at /usr only, its /etc content (root password, CA bundle, hosts, securetty, console quieting, unit masks) would be invisible on the installed system. The installer element now assembles an /etc seed at /usr/lib/bluefin-server/etc-seed and 50-root.conf unpacks it via CopyFiles=, so login, TLS, and first-boot behavior carry over unchanged; the now-dead /etc stamping is dropped from bluefin-server-ddi.bst. Consequence documented in the skills: 50-root.transfer's legacy root-a/root-b patterns no longer match any provisioned partition; rewiring it to USR-A/USR-B is the sysupdate follow-on (label-match test xfailed accordingly). Verification: - python3 -m pytest tests/unit: 219 passed, 1 xfailed - bats tests/unit: 62 passed (3 skipped: unprivileged namespaces unavailable) - python3 .github/scripts/docs-checks.py: passed - check-release-version.py / check-k0s-version.py: passed - bash -n on the modified installer/DDI element command blocks - just validate's bst show steps need the bst2/podman container environment and were not runnable here; the element graph shape is unchanged Assisted-by: z-ai/glm-5.3-flash via goose Signed-off-by: mendezr --- docs/skills/ddi-installer-build.md | 2 +- docs/skills/ddi-installer.md | 37 +- docs/skills/gap-analysis-distros.md | 14 +- elements/installer/installer-repart.bst | 10 +- elements/oci/bluefin-server-ddi.bst | 57 +-- elements/oci/bluefin-server-installer.bst | 59 ++- files/installer/repart.d/10-esp.conf | 7 +- files/installer/repart.d/20-root-a.conf | 11 - files/installer/repart.d/20-usr-a.conf | 12 + files/installer/repart.d/30-usr-b.conf | 10 + files/installer/repart.d/30-var.conf | 13 - files/installer/repart.d/40-oem.conf | 12 + files/installer/repart.d/50-root.conf | 21 ++ .../system-preset/zz-enable-var-mount.preset | 1 - files/os/systemd/system/var.mount | 14 - tests/unit/test_installer_contract.py | 27 +- tests/unit/test_repart_layout.py | 353 ++++++++++++++---- 17 files changed, 464 insertions(+), 196 deletions(-) delete mode 100644 files/installer/repart.d/20-root-a.conf create mode 100644 files/installer/repart.d/20-usr-a.conf create mode 100644 files/installer/repart.d/30-usr-b.conf delete mode 100644 files/installer/repart.d/30-var.conf create mode 100644 files/installer/repart.d/40-oem.conf create mode 100644 files/installer/repart.d/50-root.conf delete mode 100644 files/os/systemd/system-preset/zz-enable-var-mount.preset delete mode 100644 files/os/systemd/system/var.mount diff --git a/docs/skills/ddi-installer-build.md b/docs/skills/ddi-installer-build.md index 0916d10f..6a0dba2e 100644 --- a/docs/skills/ddi-installer-build.md +++ b/docs/skills/ddi-installer-build.md @@ -131,7 +131,7 @@ The release process is driven by `.github/workflows/build.yml`: - [ ] The live installer does not bake hardcoded SSH keys or pre-hashed root passwords. - [ ] The DDI is decompressed after the cpio step. -- [ ] `files/installer/repart.d/20-root-a.conf` has `GrowFileSystem=yes`. +- [ ] `files/installer/repart.d/50-root.conf` has `GrowFileSystem=yes`. ## See also diff --git a/docs/skills/ddi-installer.md b/docs/skills/ddi-installer.md index f6fdfcf1..4563d84f 100644 --- a/docs/skills/ddi-installer.md +++ b/docs/skills/ddi-installer.md @@ -17,7 +17,7 @@ metadata: - Writing or refining `systemd-repart`, `bootctl`, or `ukify` configurations. - Packaging or publishing DDI assets to GitHub Releases. - Managing partition recipes for the target disk layout (`10-esp.conf`, - `20-root-a.conf`, `30-var.conf`). + `20-usr-a.conf`, `30-usr-b.conf`, `40-oem.conf`, `50-root.conf`). ## When NOT to Use @@ -72,13 +72,20 @@ container runtime pod sandboxes. 5. `systemd-sysinstall` reads partition recipes from `/usr/lib/repart.sysinstall.d/` if it is populated; otherwise it falls back to `/usr/lib/repart.d/`. The target recipes are staged at - `/usr/lib/repart.d/` (`10-esp.conf`, `20-root-a.conf`, `30-var.conf`). -6. `20-root-a.conf` copies the DDI block-for-block from + `/usr/lib/repart.d/` (`10-esp.conf`, `20-usr-a.conf`, `30-usr-b.conf`, + `40-oem.conf`, `50-root.conf`). +6. `20-usr-a.conf` copies the DDI payload block-for-block from `/dev/disk/by-partlabel/bluefin-installer-data` (the embedded DDI data - partition on the installer media). -7. Target OS volume expansion is handled by `systemd-growfs`; the target OS - stack includes `xfsprogs` so the root and `/var` filesystems can grow to fill - their partitions on first boot. + partition on the installer media). The payload is mounted read-only as + `/usr` via the target UKI cmdline (`mount.usr=PARTLABEL=USR-A`). +7. `50-root.conf` formats ROOT (ext4) and seeds it via `CopyFiles=`: the + offline k0s sysext at `/var/lib/k0s/k0s.raw` and the target `/etc` from + `/usr/lib/bluefin-server/etc-seed` (assembled by the installer element — + the DDI payload is `/usr`-only, so its `/etc` is not visible on the + installed system). +8. Target OS volume expansion is handled by `systemd-growfs`; the target OS + stack includes `xfsprogs` so the `/usr` filesystem can be grown on first + boot. ## Partition Layout @@ -93,9 +100,17 @@ container runtime pod sandboxes. | Partition | Type | Size | Contents | |---|---|---|---| -| ESP | vfat | 500 MiB – 1 GiB | `systemd-boot` + target OS UKI (`bluefin-server.efi`) | -| `bluefin-server-root-a` | XFS | 4 GiB – 16 GiB | OS root filesystem (copied from installer data partition) | -| `var` | XFS | ≥ 4 GiB | Writable persistent `/var`; grows to fill remaining disk | +| `EFI-SYSTEM` | vfat (ESP GUID `c12a7328-…`) | 500 MiB – 1 GiB | `systemd-boot` + target OS UKI (`bluefin-server.efi`) | +| `USR-A` | Flatcar usr GUID `5dfbf5f4-…` | ≥ 4 GiB | read-only `/usr` (DDI payload copied block-for-block) | +| `USR-B` | Flatcar usr GUID `5dfbf5f4-…` | ≥ 4 GiB | empty A/B rollback slot | +| `OEM` | Flatcar OEM GUID `0fc63daf-…` (ext4) | 1 GiB | provider/first-boot state; filesystem label `OEM` (Flatcar stage 2 waits on `dev-disk-by-label-OEM.device`) | +| `ROOT` | Flatcar root GUID `3884dd41-…` (ext4) | ≥ 4 GiB | writable state: `/etc` (seeded via `CopyFiles=`), `/var`, `/home`; grows to fill remaining disk | + +The target UKI cmdline places the filesystems explicitly: +`root=PARTLABEL=ROOT mount.usr=PARTLABEL=USR-A mount.usrfstype=xfs +mount.usrflags=ro`. `root=` is mandatory because the Flatcar ROOT GUID is not +a Discoverable Partitions Specification type, so +`systemd-gpt-auto-generator` cannot discover it. ## Installer Boot Flow @@ -187,7 +202,7 @@ offline installation. - [ ] The interactive installer service sets `TTYPath=/dev/tty0` so the TUI appears on the attached display even when serial is the primary console. - [ ] `bluefin-server-installer.bst` decompresses the DDI after the cpio step. -- [ ] `files/installer/repart.d/20-root-a.conf` has `GrowFileSystem=yes`. +- [ ] `files/installer/repart.d/50-root.conf` has `GrowFileSystem=yes`. ## See also diff --git a/docs/skills/gap-analysis-distros.md b/docs/skills/gap-analysis-distros.md index 12b44132..acb1ba64 100644 --- a/docs/skills/gap-analysis-distros.md +++ b/docs/skills/gap-analysis-distros.md @@ -95,7 +95,7 @@ Bluefin Server is a BuildStream 2-based, image-based Linux server OS built from | Axis | Bluefin Server (as-implemented) | |------|---------------------------------| | **Philosophy** | Systemd-native, minimal, image-based server OS appliance; base DDI includes bash for login and bring-up while heavy developer/debug tools live in sysexts or system containers; intended to run container workloads and Kubernetes via optional sysexts. Sources: [AGENTS.md](../../AGENTS.md), [factory-integration.md](factory-integration.md). | -| **State model** | Target OS DDI is an XFS filesystem image. A separate persistent `/var` partition is created by the installer. There is no second root slot provisioned today, and the UKI cmdline currently uses `rw`, so the root is not mounted read-only at runtime. Sources: [bluefin-server-ddi.bst](../../elements/oci/bluefin-server-ddi.bst), [20-root-a.conf](../../files/installer/repart.d/20-root-a.conf), [bluefin-server-installer.bst](../../elements/oci/bluefin-server-installer.bst). | +| **State model** | Target OS DDI is an XFS filesystem image mounted read-only as `/usr` from the `USR-A` slot. The installer provisions a separate writable `ROOT` state partition (ext4, grows into remaining disk) seeded at install time with the offline k0s sysext and `/etc`; `USR-B` is provisioned as an empty A/B rollback slot. The UKI cmdline carries `root=PARTLABEL=ROOT mount.usr=PARTLABEL=USR-A mount.usrfstype=xfs mount.usrflags=ro`, so the root is writable while `/usr` is mounted read-only at runtime. Sources: [bluefin-server-ddi.bst](../../elements/oci/bluefin-server-ddi.bst), [20-usr-a.conf](../../files/installer/repart.d/20-usr-a.conf), [50-root.conf](../../files/installer/repart.d/50-root.conf), [bluefin-server-installer.bst](../../elements/oci/bluefin-server-installer.bst). | | **Updates** | `systemd-sysupdate` reads root/UKI transfers from `files/os/sysupdate.d/` and the optional k0s transfer from the `k0s` component directory. Assets are published to GitHub Releases, and the combined `SHA256SUMS` manifest is signed in CI with a GPG key. `Verify=yes` is the default. Sources: [systemd-sysupdate-verification.md](systemd-sysupdate-verification.md), [50-root.transfer](../../files/os/sysupdate.d/50-root.transfer), [60-uki.transfer](../../files/os/sysupdate.d/60-uki.transfer), [70-k0s.transfer](../../files/os/sysupdate.k0s.d/70-k0s.transfer), also `systemd-sysupdate(8)`. | | **Provisioning** | The installer is an offline `systemd-sysinstall` image that embeds the DDI as a data partition. First-boot configuration is intended to be delivered via `systemd-creds` through the ESP or hypervisor metadata. Today only `passwd.hashed-password.root` is consumed via `systemd-sysusers.d`; the documented `tmpfiles.extra` path for SSH keys and similar files is not implemented. Sources: [bluefin-server-installer.bst](../../elements/oci/bluefin-server-installer.bst), [10-root-creds.conf](../../files/os/sysusers.d/10-root-creds.conf), [os-creds-prov.bst](../../elements/bluefin-server/os-creds-prov.bst), [systemd-creds(1)](https://www.freedesktop.org/software/systemd/man/latest/systemd-creds.html). | | **Customization** | Adds software through `systemd-sysext` (overlay `/usr`) and `systemd-confext` (overlay `/etc`) images. The base OS `os-release` advertises `ID=flatcar` and a matching `VERSION_ID` so pre-built Flatcar Bakery extensions load. k0s is shipped as a separately built, optionally enabled sysext. Sources: [systemd-sysext-extensions.md](systemd-sysext-extensions.md), [k0s-sysext.md](k0s-sysext.md), [os-release-flatcar.bst](../../elements/bluefin-server/os-release-flatcar.bst), [systemd-sysext(8)](https://www.freedesktop.org/software/systemd/man/latest/systemd-sysext.html). | @@ -105,11 +105,14 @@ Bluefin Server is a BuildStream 2-based, image-based Linux server OS built from ### Root filesystem and A/B rollback -- **Gap:** Bluefin's `systemd-sysupdate` root transfer already names two target partitions (`root-a` and `root-b`) in `50-root.transfer`, but the installer only creates one root partition (`20-root-a.conf`). - There is no `root-b` partition yet, so `systemd-sysupdate` cannot stage an update into an inactive slot and the OS has no atomic rollback path comparable to Flatcar/Fedora CoreOS/Talos today. -- **Gap:** The DDI filesystem is created as a writable XFS image and the installed UKI boots it with `rw`. A read-only `/usr` state model, as intended by the sysext-first design, is not enforced at runtime. +- **Gap:** Bluefin's `systemd-sysupdate` root transfer names legacy target partition labels (`bluefin-server-root-_a/_b`) in `50-root.transfer`, but the Flatcar layout installed since #134 provisions `USR-A`/`USR-B` instead and the transfer has not been rewired to those slots. + `USR-B` is provisioned empty, so `systemd-sysupdate` cannot stage an update into an inactive slot and the OS has no atomic rollback path comparable to Flatcar/Fedora CoreOS/Talos today. - **Gap:** There is no mechanism to select the previous OS version at boot if an update fails; recovery currently depends on reinstalling from media. +### Update delivery + +- **Gap:** The root transfer uses `Type=partition Path=auto`, which requires `systemd-sysupdate` to discover a matching GPT partition label. The shipped `50-root.transfer` patterns (`bluefin-server-root-a`/`root-b`) no longer match any partition the installer provisions (#134 replaced them with `USR-A`/`USR-B`), so OTA updates resolve to no slot until the transfer is rewired. + ### Provisioning - **Gap:** The documented `systemd-creds` first-boot provisioning for SSH keys (`tmpfiles.extra`) is not present in the build (`os-creds-prov.bst` only ships `sysusers.d`). @@ -189,7 +192,8 @@ These gaps drive the priorities in [architecture-roadmap.md](architecture-roadma - [elements/bluefin-server/os-release-flatcar.bst](../../elements/bluefin-server/os-release-flatcar.bst) - [elements/bluefin-server/os-creds-prov.bst](../../elements/bluefin-server/os-creds-prov.bst) - [elements/bluefin-server/os-kured-hook.bst](../../elements/bluefin-server/os-kured-hook.bst) -- [files/installer/repart.d/20-root-a.conf](../../files/installer/repart.d/20-root-a.conf) +- [files/installer/repart.d/20-usr-a.conf](../../files/installer/repart.d/20-usr-a.conf) +- [files/installer/repart.d/50-root.conf](../../files/installer/repart.d/50-root.conf) - [files/os/sysupdate.d/50-root.transfer](../../files/os/sysupdate.d/50-root.transfer) - [files/os/sysupdate.d/60-uki.transfer](../../files/os/sysupdate.d/60-uki.transfer) - [files/os/sysupdate.k0s.d/70-k0s.transfer](../../files/os/sysupdate.k0s.d/70-k0s.transfer) diff --git a/elements/installer/installer-repart.bst b/elements/installer/installer-repart.bst index 6d94b3b7..df8f7a69 100644 --- a/elements/installer/installer-repart.bst +++ b/elements/installer/installer-repart.bst @@ -5,10 +5,12 @@ description: | "systemd-repart --dry-run=no DEVICE", it reads these configs to know how to partition and populate the TARGET disk. - Partition layout: - 10-esp.conf EFI System Partition (vfat, 500M–1G) - 20-root-a.conf Root slot A — DDI filesystem image copied here - 30-var.conf /var — xfs, writable, grows to fill disk + Partition layout (Flatcar GPT layout, projectbluefin/server#134): + 10-esp.conf EFI-SYSTEM (vfat, 500M–1G) + 20-usr-a.conf USR-A — DDI /usr payload copied here block-for-block + 30-usr-b.conf USR-B — empty A/B rollback slot + 40-oem.conf OEM — ext4, filesystem label OEM (stage 2 boot dep) + 50-root.conf ROOT — writable ext4 state, CopyFiles seeds, grows sources: - kind: local diff --git a/elements/oci/bluefin-server-ddi.bst b/elements/oci/bluefin-server-ddi.bst index 9f801570..caafcd5a 100644 --- a/elements/oci/bluefin-server-ddi.bst +++ b/elements/oci/bluefin-server-ddi.bst @@ -5,7 +5,12 @@ description: | Output: bluefin-server-ddi-.raw.zst + SHA256SUMS The output .raw is a filesystem image consumed by installer repart config: - files/installer/repart.d/20-root-a.conf via CopyBlocks=. + files/installer/repart.d/20-usr-a.conf via CopyBlocks= — the Flatcar layout + (projectbluefin/server#134) mounts this payload read-only as the system's + /usr (mount.usr=PARTLABEL=USR-A). Only /usr is visible on the target; the + writable ROOT partition is a fresh ext4 filesystem seeded with /etc state by + the installer element (files/installer/repart.d/50-root.conf CopyFiles=), + so this payload carries no target /etc content. build-depends: - base/base-stack.bst @@ -40,50 +45,12 @@ config: rm -f "/layer/usr/lib/modules/${KVER}/vmlinux" "/layer/usr/lib/modules/${KVER}/System.map" depmod -b /layer "${KVER}" - # Stage extracted CA certificate bundle into target DDI rootfs - mkdir -p /layer/etc/pki/ca-trust/extracted /layer/etc/ssl/certs /layer/etc/pki/tls/certs - cp -a /etc/pki/ca-trust/extracted/* /layer/etc/pki/ca-trust/extracted/ - ln -sf /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem /layer/etc/ssl/certs/ca-certificates.crt - ln -sf /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem /layer/etc/pki/tls/certs/ca-bundle.crt - ln -sf /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem /layer/etc/pki/tls/cert.pem - - # Mask systemd-firstboot to prevent interactive prompts on headless first boot - mkdir -p /layer/etc/systemd/system - ln -sf /dev/null /layer/etc/systemd/system/systemd-firstboot.service - - # Mask audit-rules to prevent failure on shell-free OS (augenrules requires /bin/sh) - ln -sf /dev/null /layer/etc/systemd/system/audit-rules.service - - # Silence kernel and audit log spam on the console - mkdir -p /layer/etc/systemd/journald.conf.d /layer/etc/sysctl.d - printf '[Journal]\nForwardToConsole=no\nMaxLevelConsole=warning\n' > /layer/etc/systemd/journald.conf.d/10-console.conf - printf 'kernel.printk = 3 4 1 3\n' > /layer/etc/sysctl.d/10-console.conf - ln -sf /dev/null /layer/etc/systemd/system/systemd-journald-audit.socket - - # Ensure standard /etc/hosts exists for container runtimes (containerd/podman) - printf '127.0.0.1 localhost\n::1 localhost ip6-localhost ip6-loopback\n' > /layer/etc/hosts - - # Ensure persistent /var is mounted from its partition label - printf '/dev/disk/by-partlabel/var /var xfs defaults 0 0\n' > /layer/etc/fstab - - # Ensure all standard virtual, serial, and hypervisor consoles allow root login - printf 'tty0\ntty1\ntty2\ntty3\ntty4\ntty5\ntty6\nttyS0\nttyS1\nconsole\nhvc0\n' > /layer/etc/securetty - - # Seed default root password 'bluefin' into /etc/shadow for console and ssh login - mkdir -p /layer/etc - printf 'root:$6$bluefin123$o2pQjPN1n3ZCnYUROlA01xAdnGO7mhVRAVw98x4xc8LAUIJv7b44bBNoER6fM4P.rrj4ePYFfkx9WvZICU8nt/:19700:0:99999:7:::\n' > /layer/etc/shadow - chmod 0600 /layer/etc/shadow - printf 'root:x:0:0:root:/root:/bin/bash\n' > /layer/etc/passwd - chmod 0644 /layer/etc/passwd - printf 'root:x:0:\n' > /layer/etc/group - chmod 0644 /layer/etc/group - - # Pre-generate SSH host keys for first boot remote diagnostics - mkdir -p /layer/etc/ssh - ssh-keygen -q -N "" -t ed25519 -f /layer/etc/ssh/ssh_host_ed25519_key - ssh-keygen -q -N "" -t rsa -b 3072 -f /layer/etc/ssh/ssh_host_rsa_key - chmod 0600 /layer/etc/ssh/ssh_host_*_key - chmod 0644 /layer/etc/ssh/ssh_host_*.pub + # Note: no /etc content is stamped here. Under the Flatcar layout + # (projectbluefin/server#134) this image is mounted read-only at /usr, so + # anything written to /layer/etc would be invisible on the installed + # system. The writable ROOT partition is seeded instead — see the /etc + # seed assembly in elements/oci/bluefin-server-installer.bst and the + # CopyFiles= lines in files/installer/repart.d/50-root.conf. # Sum actual file sizes across bind mounts (du -sb reports content bytes, not overlay blocks). ROOT_BYTES=$(du -sb /layer | cut -f1) diff --git a/elements/oci/bluefin-server-installer.bst b/elements/oci/bluefin-server-installer.bst index 44d9f300..fc94fbe4 100644 --- a/elements/oci/bluefin-server-installer.bst +++ b/elements/oci/bluefin-server-installer.bst @@ -87,6 +87,50 @@ config: mkdir -p /layer/boot mkdir -p /target-root/boot/EFI/Linux /tmp /var/tmp + # ── Step 1a-2: Assemble the target /etc seed for the ROOT partition ─ + # The Flatcar layout mounts the DDI payload (USR-A) at /usr only, so the + # DDI's own /etc is invisible on the installed system. ROOT is formatted + # empty by repart and seeded via CopyFiles= from this directory: the OS + # stack's /etc facts staged at /target-root/etc (sshd config, the system + # justfile) plus the first-boot conveniences formerly stamped into the DDI + # root filesystem (root password, CA bundle, hosts, securetty, console + # quieting, unit masks). 50-root.conf unpacks it at install time with + # CopyFiles=/usr/lib/bluefin-server/etc-seed:/etc. + - | + set -eux + SEED="/layer/usr/lib/bluefin-server/etc-seed" + mkdir -p "${SEED}" + # OS stack /etc facts: sshd configuration drop-ins, the system justfile + cp -a /target-root/etc/. "${SEED}/" + # CA certificate bundle for TLS (systemd-sysupdate verify, curl, podman) + mkdir -p "${SEED}/pki/ca-trust/extracted" "${SEED}/ssl/certs" "${SEED}/pki/tls/certs" + cp -a /etc/pki/ca-trust/extracted/* "${SEED}/pki/ca-trust/extracted/" + ln -sf /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem "${SEED}/ssl/certs/ca-certificates.crt" + ln -sf /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem "${SEED}/pki/tls/certs/ca-bundle.crt" + ln -sf /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem "${SEED}/pki/tls/cert.pem" + # Mask units that cannot run on the headless target (repart CopyFiles= + # preserves symlinks on ext4, matching the masks formerly stamped into + # the DDI rootfs) + mkdir -p "${SEED}/systemd/system" + ln -sf /dev/null "${SEED}/systemd/system/systemd-firstboot.service" + ln -sf /dev/null "${SEED}/systemd/system/audit-rules.service" + ln -sf /dev/null "${SEED}/systemd/system/systemd-journald-audit.socket" + # Silence kernel and audit log spam on the console + mkdir -p "${SEED}/systemd/journald.conf.d" "${SEED}/sysctl.d" + printf '[Journal]\nForwardToConsole=no\nMaxLevelConsole=warning\n' > "${SEED}/systemd/journald.conf.d/10-console.conf" + printf 'kernel.printk = 3 4 1 3\n' > "${SEED}/sysctl.d/10-console.conf" + # Standard /etc/hosts for container runtimes (containerd/podman) + printf '127.0.0.1 localhost\n::1 localhost ip6-localhost ip6-loopback\n' > "${SEED}/hosts" + # All standard virtual, serial, and hypervisor consoles allow root login + printf 'tty0\ntty1\ntty2\ntty3\ntty4\ntty5\ntty6\nttyS0\nttyS1\nconsole\nhvc0\n' > "${SEED}/securetty" + # Default root password 'bluefin' for console and ssh login + printf 'root:$6$bluefin123$o2pQjPN1n3ZCnYUROlA01xAdnGO7mhVRAVw98x4xc8LAUIJv7b44bBNoER6fM4P.rrj4ePYFfkx9WvZICU8nt/:19700:0:99999:7:::\n' > "${SEED}/shadow" + chmod 0600 "${SEED}/shadow" + printf 'root:x:0:0:root:/root:/bin/bash\n' > "${SEED}/passwd" + chmod 0644 "${SEED}/passwd" + printf 'root:x:0:\n' > "${SEED}/group" + chmod 0644 "${SEED}/group" + # ── Step 1b: Generate target OS UKI (dracut + ukify) ──────────────── - | set -eux @@ -124,6 +168,13 @@ config: cp /target-root/etc/ld.so.cache /etc/ld.so.cache # Run dracut in generic (non-hostonly) mode and explicitly add XFS, VirtIO, and NVMe storage drivers. + # The cmdline is duplicated in the ukify call below; keep both in sync. + # root= is mandatory: the Flatcar ROOT type GUID (3884dd41-…) is not a + # Discoverable Partitions Specification type, so systemd-gpt-auto-generator + # cannot discover it. PARTLABEL=ROOT is the build-time-stable GPT identity + # (PARTUUID is generated per install and cannot be baked into a UKI). + # mount.usr= mounts USR-A read-only as /usr; the writable ROOT (ext4) + # carries /etc, /var and /home, seeded at install time by repart CopyFiles. dracut -v --reproducible --no-machineid --no-hostonly \ --add-drivers "virtio virtio_blk virtio_pci virtio_scsi nvme nvme_core xfs erofs overlay zfs spl" \ --filesystems "xfs vfat zfs" \ @@ -131,13 +182,13 @@ config: --kmoddir "/target-root/usr/lib/modules/${TARGET_KVER}" \ --kernel-image "${TARGET_KERNEL}" \ --kver "${TARGET_KVER}" \ - --kernel-cmdline "rw console=ttyS0,115200 console=tty0 quiet loglevel=3 audit=0" \ + --kernel-cmdline "rw root=PARTLABEL=ROOT mount.usr=PARTLABEL=USR-A mount.usrfstype=xfs mount.usrflags=ro console=ttyS0,115200 console=tty0 quiet loglevel=3 audit=0" \ /tmp/bluefin-server-target.initramfs ukify build \ --linux="${TARGET_KERNEL}" \ --initrd=/tmp/bluefin-server-target.initramfs \ - --cmdline="rw console=ttyS0,115200 console=tty0 quiet loglevel=3 audit=0" \ + --cmdline="rw root=PARTLABEL=ROOT mount.usr=PARTLABEL=USR-A mount.usrfstype=xfs mount.usrflags=ro console=ttyS0,115200 console=tty0 quiet loglevel=3 audit=0" \ --output=/target-root/boot/EFI/Linux/bluefin-server.efi cp /target-root/boot/EFI/Linux/bluefin-server.efi /layer/usr/lib/bluefin-server/bluefin-server.efi @@ -216,7 +267,7 @@ config: udevadm settle --timeout=10 || true local target="${TARGET_DISK:-}" if [ -z "${target}" ]; then - local root_part="$(readlink -f /dev/disk/by-partlabel/bluefin-server-root-a 2>/dev/null || true)" + local root_part="$(readlink -f /dev/disk/by-partlabel/ROOT 2>/dev/null || true)" if [ -n "${root_part}" ]; then target="$(lsblk -p -n -d -o PKNAME "${root_part}" 2>/dev/null || true)" fi @@ -400,7 +451,7 @@ config: # 20-ddi-data.conf: Data (XFS) — bluefin-server-ddi.raw copied here block-for-block # # At install time, systemd-sysinstall mounts the data partition to - # locate the DDI at the path expected by repart.d/20-root-a.conf (CopyBlocks=). + # locate the DDI at the path expected by repart.d/20-usr-a.conf (CopyBlocks=). - | set -eux OUT="%{install-root}" diff --git a/files/installer/repart.d/10-esp.conf b/files/installer/repart.d/10-esp.conf index de2e201d..cacbfc00 100644 --- a/files/installer/repart.d/10-esp.conf +++ b/files/installer/repart.d/10-esp.conf @@ -1,9 +1,12 @@ -# EFI System Partition -# Created empty by systemd-repart; populated post-install by the installer +# EFI-SYSTEM — ESP slot (PARTLABEL EFI-SYSTEM) +# Created empty by systemd-sysinstall; populated post-install by the installer # script via: bootctl install --esp-path= --root= # which copies systemd-boot and registers the OS UKI from the installed rootfs. +# Type=esp expands to the upstream ESP type GUID +# c12a7328-f81f-11d2-ba4b-00a0c93ec93b (Flatcar's EFI-SYSTEM slot). [Partition] Type=esp Format=vfat +Label=EFI-SYSTEM SizeMinBytes=500M SizeMaxBytes=1G diff --git a/files/installer/repart.d/20-root-a.conf b/files/installer/repart.d/20-root-a.conf deleted file mode 100644 index b10319bd..00000000 --- a/files/installer/repart.d/20-root-a.conf +++ /dev/null @@ -1,11 +0,0 @@ -# Root partition — slot A -# systemd-repart copies the DDI payload block-for-block from the embedded -# installer data partition on the boot medium. -# The source is a raw filesystem image; repart copies it verbatim. -[Partition] -Type=root -Label=bluefin-server-root-a -CopyBlocks=/dev/disk/by-partlabel/bluefin-installer-data -SizeMinBytes=4G -SizeMaxBytes=16G -GrowFileSystem=yes diff --git a/files/installer/repart.d/20-usr-a.conf b/files/installer/repart.d/20-usr-a.conf new file mode 100644 index 00000000..c0b165fc --- /dev/null +++ b/files/installer/repart.d/20-usr-a.conf @@ -0,0 +1,12 @@ +# USR-A — read-only /usr slot A (verity lands with the /usr DDI ticket) +# Type GUID: Flatcar's usr partition, 5dfbf5f4-2848-4bac-aa5e-0d9a20b745a6, +# adopted verbatim by projectbluefin/server#134. +# systemd-repart copies the DDI payload block-for-block from the embedded +# installer data partition on the boot medium. The source is a raw filesystem +# image; repart copies it verbatim. The target boots with mount.usr=PARTLABEL= +# USR-A (fstype xfs, flags ro) so this slot is the system's /usr. +[Partition] +Type=5dfbf5f4-2848-4bac-aa5e-0d9a20b745a6 +Label=USR-A +CopyBlocks=/dev/disk/by-partlabel/bluefin-installer-data +SizeMinBytes=4G diff --git a/files/installer/repart.d/30-usr-b.conf b/files/installer/repart.d/30-usr-b.conf new file mode 100644 index 00000000..09e1f32d --- /dev/null +++ b/files/installer/repart.d/30-usr-b.conf @@ -0,0 +1,10 @@ +# USR-B — the A/B /usr rollback slot. +# Type GUID: Flatcar's usr partition, 5dfbf5f4-2848-4bac-aa5e-0d9a20b745a6, +# adopted verbatim by projectbluefin/server#134. Same GUID as USR-A so the +# kernel's usr= slot logic recognises the pair; sized to match USR-A. +# Empty and unformatted in this ticket: wiring sysupdate to stage updates +# into USR-B is the sysupdate follow-on. +[Partition] +Type=5dfbf5f4-2848-4bac-aa5e-0d9a20b745a6 +Label=USR-B +SizeMinBytes=4G diff --git a/files/installer/repart.d/30-var.conf b/files/installer/repart.d/30-var.conf deleted file mode 100644 index 7f2ec345..00000000 --- a/files/installer/repart.d/30-var.conf +++ /dev/null @@ -1,13 +0,0 @@ -# /var partition — writable, persistent across updates -# NOTE: Do NOT set FactoryReset=yes here: systemd-sysinstall hardcodes -# deferPartitionsFactoryReset=true, which causes the installer to skip -# creating /var entirely. -# GrowFileSystem=yes: XFS grows to fill all remaining disk space after -# the ESP and root-a partitions are placed. -[Partition] -Type=var -Label=var -Format=xfs -GrowFileSystem=yes -CopyFiles=/k0s.raw:/lib/k0s/k0s.raw -SizeMinBytes=4G diff --git a/files/installer/repart.d/40-oem.conf b/files/installer/repart.d/40-oem.conf new file mode 100644 index 00000000..786023ce --- /dev/null +++ b/files/installer/repart.d/40-oem.conf @@ -0,0 +1,12 @@ +# OEM — provider/first-boot state partition. +# Required, not optional: Flatcar's stage 2 depends on +# dev-disk-by-label-OEM.device, so without it boot waits 90s and drops to an +# emergency shell (projectbluefin/server#134 boot proof). The dependency +# matches the filesystem LABEL, so Label=OEM also names the ext4 filesystem. +# Type GUID: Flatcar's OEM partition, 0fc63daf-8483-4772-8e79-3d69d8477de4, +# adopted verbatim by projectbluefin/server#134. +[Partition] +Type=0fc63daf-8483-4772-8e79-3d69d8477de4 +Format=ext4 +Label=OEM +SizeMinBytes=1024M diff --git a/files/installer/repart.d/50-root.conf b/files/installer/repart.d/50-root.conf new file mode 100644 index 00000000..89a18eb6 --- /dev/null +++ b/files/installer/repart.d/50-root.conf @@ -0,0 +1,21 @@ +# ROOT — writable state partition (tail of the disk): /etc, /var, /home. +# Type GUID: Flatcar's root partition, 3884dd41-8582-4404-b9a8-e9b84f2df50e, +# adopted verbatim by projectbluefin/server#134. That GUID is not a +# Discoverable Partitions Specification type, so systemd-gpt-auto-generator +# cannot find it — the UKI cmdline carries root=PARTLABEL=ROOT explicitly +# (asserted by tests/unit/test_repart_layout.py). +# Format=ext4 matches Flatcar's ROOT filesystem; CopyFiles= requires a +# formatted filesystem. GrowFileSystem=yes marks the DPS grow flag. +# CopyFiles: the offline k0s sysext lands at /var/lib/k0s/k0s.raw (the path +# k0s-first-boot-fetch.service checks), and the target /etc seed is unpacked +# from /usr/lib/bluefin-server/etc-seed assembled by the installer element +# (the DDI payload is /usr-only: its /etc is not visible under the USR-A +# mount). +[Partition] +Type=3884dd41-8582-4404-b9a8-e9b84f2df50e +Format=ext4 +Label=ROOT +CopyFiles=/k0s.raw:/var/lib/k0s/k0s.raw +CopyFiles=/usr/lib/bluefin-server/etc-seed:/etc +SizeMinBytes=4G +GrowFileSystem=yes diff --git a/files/os/systemd/system-preset/zz-enable-var-mount.preset b/files/os/systemd/system-preset/zz-enable-var-mount.preset deleted file mode 100644 index cf842450..00000000 --- a/files/os/systemd/system-preset/zz-enable-var-mount.preset +++ /dev/null @@ -1 +0,0 @@ -enable var.mount diff --git a/files/os/systemd/system/var.mount b/files/os/systemd/system/var.mount deleted file mode 100644 index bb6671aa..00000000 --- a/files/os/systemd/system/var.mount +++ /dev/null @@ -1,14 +0,0 @@ -[Unit] -Description=Persistent /var Storage -DefaultDependencies=no -Conflicts=umount.target -Before=local-fs.target umount.target - -[Mount] -What=/dev/disk/by-partlabel/var -Where=/var -Type=xfs -Options=defaults - -[Install] -WantedBy=local-fs.target diff --git a/tests/unit/test_installer_contract.py b/tests/unit/test_installer_contract.py index d423c685..4edfeae4 100644 --- a/tests/unit/test_installer_contract.py +++ b/tests/unit/test_installer_contract.py @@ -48,7 +48,10 @@ def test_installer_runtime_and_boot_contracts() -> None: assert "freedesktop-sdk.bst:bootstrap/bash.bst" in installer_stack assert "console=ttyS0,115200 rw" in installer_element assert "unattended" not in published_uki_cmdline - assert target_uki_cmdline == "rw console=ttyS0,115200 console=tty0 quiet loglevel=3 audit=0" + assert target_uki_cmdline == ( + "rw root=PARTLABEL=ROOT mount.usr=PARTLABEL=USR-A mount.usrfstype=xfs " + "mount.usrflags=ro console=ttyS0,115200 console=tty0 quiet loglevel=3 audit=0" + ) assert ( '-append "systemd.unit=system-install.target ' 'console=tty0 console=ttyS0,115200 rw unattended"' @@ -93,12 +96,22 @@ def test_ddi_generates_module_indexes_for_runtime_filesystem_drivers() -> None: assert "freedesktop-sdk.bst:components/kmod.bst" in ddi_element assert 'depmod -b /layer "${KVER}"' in ddi_element - assert "cp -a /etc/pki/ca-trust/extracted/* /layer/etc/pki/ca-trust/extracted/" in ddi_element - assert "tls-ca-bundle.pem" in ddi_element - assert "ln -sf /dev/null /layer/etc/systemd/system/systemd-firstboot.service" in ddi_element - assert "ln -sf /dev/null /layer/etc/systemd/system/audit-rules.service" in ddi_element - assert "printf '127.0.0.1 localhost" in ddi_element - assert "> /layer/etc/hosts" in ddi_element + # The DDI payload is mounted at /usr only (#134), so the target /etc state + # is no longer stamped into it — the installer element assembles it. + assert "cp -a /etc/pki/ca-trust/extracted/*" not in ddi_element + + +def test_target_etc_seed_carries_firstboot_state() -> None: + installer_element = INSTALLER_ELEMENT.read_text(encoding="utf-8") + seed = "/layer/usr/lib/bluefin-server/etc-seed" + + assert f"mkdir -p {seed}" in installer_element or f"SEED=\"{seed}\"" in installer_element + assert "cp -a /etc/pki/ca-trust/extracted/*" in installer_element + assert "tls-ca-bundle.pem" in installer_element + assert 'ln -sf /dev/null "${SEED}/systemd/system/systemd-firstboot.service"' in installer_element + assert 'ln -sf /dev/null "${SEED}/systemd/system/audit-rules.service"' in installer_element + assert "printf '127.0.0.1 localhost" in installer_element + assert '"${SEED}/hosts"' in installer_element def test_target_initramfs_preloads_sysext_filesystem_drivers() -> None: diff --git a/tests/unit/test_repart_layout.py b/tests/unit/test_repart_layout.py index bf5a0bd0..6fdb8991 100644 --- a/tests/unit/test_repart_layout.py +++ b/tests/unit/test_repart_layout.py @@ -3,14 +3,22 @@ ``files/installer/repart.d/*.conf`` is the recipe ``systemd-repart`` follows when the live installer partitions the *target* disk. Nothing in CI parses these files today, so a typo in a ``Type=``, a ``CopyBlocks=`` source that no longer -matches the label the installer media stamps on its data partition, or an -``esp``/``root``/``var`` slot going missing would only surface as a failed or -silently mis-partitioned install. +matches the label the installer media stamps on its data partition, or a +partition going missing would only surface as a failed or silently +mis-partitioned install. + +The layout is Flatcar's EFI-SYSTEM / USR-A / USR-B / OEM / ROOT, adopted by +projectbluefin/server#134. The ``Type=`` values for USR-A, USR-B, OEM and ROOT +are upstream GPT type GUIDs and must appear verbatim. ROOT's GUID is *not* a +Discoverable Partitions Specification type, so the target UKI cmdline must +carry ``root=`` explicitly — also pinned here, per the review that rejected +the first layout PR: the suite must catch a layout that boots with no way to +find its root filesystem. These tests are pure static checks: they read the shipped configs (plus the -installer element and the sysupdate transfer for cross-file consistency) and -assert the invariants the installer depends on. No BuildStream, no root, no -block devices. +installer element, the DDI element and the sysupdate transfer for cross-file +consistency) and assert the invariants the installer depends on. No +BuildStream, no root, no block devices. """ from __future__ import annotations @@ -24,8 +32,28 @@ REPO_ROOT = Path(__file__).resolve().parents[2] REPART_DIR = REPO_ROOT / "files" / "installer" / "repart.d" ELEMENTS_DIR = REPO_ROOT / "elements" +OS_FILES_DIR = REPO_ROOT / "files" / "os" +INSTALLER_ELEMENT = ELEMENTS_DIR / "oci" / "bluefin-server-installer.bst" +DDI_ELEMENT = ELEMENTS_DIR / "oci" / "bluefin-server-ddi.bst" ROOT_TRANSFER = REPO_ROOT / "files" / "os" / "sysupdate.d" / "50-root.transfer" +# Flatcar GPT type GUIDs, adopted verbatim by projectbluefin/server#134. +ESP_GUID = "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" +USR_GUID = "5dfbf5f4-2848-4bac-aa5e-0d9a20b745a6" +OEM_GUID = "0fc63daf-8483-4772-8e79-3d69d8477de4" +ROOT_GUID = "3884dd41-8582-4404-b9a8-e9b84f2df50e" + +# PARTLABELs the installer provisions on the target disk, in repart order. +EXPECTED_LABELS = ["EFI-SYSTEM", "USR-A", "USR-B", "OEM", "ROOT"] + +# Kernel parameters that place the root filesystem and the read-only /usr. +TARGET_CMDLINE_TOKENS = [ + "root=PARTLABEL=ROOT", + "mount.usr=PARTLABEL=USR-A", + "mount.usrfstype=xfs", + "mount.usrflags=ro", +] + SIZE_SUFFIXES = {"K": 1024, "M": 1024**2, "G": 1024**3, "T": 1024**4} @@ -37,7 +65,32 @@ def parse_size(value: str) -> int: return int(number) * SIZE_SUFFIXES.get(suffix, 1) +def load_sections(path: Path) -> dict[str, dict[str, list[str]]]: + """Parse a systemd-style config into sections of key → repeated values. + + ``repart.d`` allows repeated keys (``CopyFiles=``), which configparser + cannot represent, so the section grammar is parsed directly: comments are + stripped per-line, section headers delimit scope, and every ``key=value`` + line appends to its key's list. + """ + sections: dict[str, dict[str, list[str]]] = {} + current: dict[str, list[str]] | None = None + for raw in path.read_text(encoding="utf-8").splitlines(): + line = raw.split("#", 1)[0].strip() + if not line: + continue + if line.startswith("[") and line.endswith("]"): + current = sections.setdefault(line[1:-1], {}) + continue + if current is None: + continue + key, _, value = line.partition("=") + current.setdefault(key.strip(), []).append(value.strip()) + return sections + + def load_config(path: Path) -> configparser.ConfigParser: + """Plain configparser loader for transfer files (no repeated keys).""" parser = configparser.ConfigParser(strict=True) # systemd drop-ins are case-sensitive; configparser lowercases keys by default. parser.optionxform = str @@ -52,9 +105,7 @@ def sysupdate_root_targets() -> list[str]: release asset name) and ``[Target]`` (the partition labels); only the latter names partitions. """ - parser = configparser.ConfigParser(strict=True) - parser.optionxform = str - parser.read_string(ROOT_TRANSFER.read_text(encoding="utf-8")) + parser = load_config(ROOT_TRANSFER) assert parser.has_option("Target", "MatchPattern"), ( f"{ROOT_TRANSFER.name} declares no [Target] MatchPattern" ) @@ -68,25 +119,58 @@ def repart_files() -> list[Path]: CONFIG_PATHS = repart_files() -def partitions() -> dict[str, dict[str, str]]: +def partitions() -> dict[str, dict[str, list[str]]]: """Map ``10-esp.conf`` → its ``[Partition]`` section, for every config.""" - result: dict[str, dict[str, str]] = {} + result: dict[str, dict[str, list[str]]] = {} for path in CONFIG_PATHS: - parser = load_config(path) - result[path.name] = dict(parser["Partition"]) + result[path.name] = load_sections(path)["Partition"] return result +def by_label(label: str) -> dict[str, list[str]]: + """The [Partition] section of the config labelled ``label``.""" + matches = [s for s in partitions().values() if s.get("Label") == [label]] + assert len(matches) == 1, f"expected exactly one {label} partition" + return matches[0] + + +def single(section: dict[str, list[str]], key: str) -> str | None: + """The sole value for ``key`` in a partition section, or None if unset.""" + values = section.get(key) + if values is None: + return None + assert len(values) == 1, f"{key}= is set more than once: {values}" + return values[0] + + +def installer_text() -> str: + return INSTALLER_ELEMENT.read_text(encoding="utf-8") + + +def target_uki_cmdlines() -> list[str]: + """Kernel cmdline strings baked into the target OS UKI. + + The target cmdline is set twice on purpose (dracut ``--kernel-cmdline`` and + ukify ``--cmdline=`` must agree); the installer's own UKI cmdline is + excluded because it boots the live installer environment, not the target. + """ + text = installer_text() + candidates = re.findall(r'--cmdline="([^"]*)"', text) + re.findall( + r"--kernel-cmdline \"([^\"]*)\"", text + ) + return [c for c in candidates if "mount.usr=" in c] + + def test_repart_directory_is_populated(): assert CONFIG_PATHS, f"no repart.d configs found under {REPART_DIR}" @pytest.mark.parametrize("path", CONFIG_PATHS, ids=lambda p: p.name) def test_config_parses_with_a_partition_section(path: Path): - parser = load_config(path) - assert parser.sections() == ["Partition"], ( + sections = load_sections(path) + assert list(sections) == ["Partition"], ( f"{path.name} must define exactly one [Partition] section, " - f"got {parser.sections()}" + f"got {list(sections)}" ) @@ -105,18 +189,22 @@ def test_config_ordering_prefixes_are_unique(): ) -def test_expected_partition_types_are_present_exactly_once(): - types = [section["Type"] for section in partitions().values()] - assert sorted(types) == ["esp", "root", "var"], ( - "the target layout must be exactly one esp, one root and one var " - f"partition, got {sorted(types)}" +def test_expected_partitions_are_present_exactly_once(): + labels = [ + section["Label"][0] + for section in partitions().values() + if "Label" in section + ] + assert sorted(labels) == sorted(EXPECTED_LABELS), ( + "the target layout must be exactly one each of EFI-SYSTEM, USR-A, " + f"USR-B, OEM and ROOT partition, got {sorted(labels)}" ) @pytest.mark.parametrize("name,section", sorted(partitions().items())) -def test_size_bounds_are_consistent(name: str, section: dict[str, str]): - minimum = section.get("SizeMinBytes") - maximum = section.get("SizeMaxBytes") +def test_size_bounds_are_consistent(name: str, section: dict[str, list[str]]): + minimum = single(section, "SizeMinBytes") + maximum = single(section, "SizeMaxBytes") assert minimum, f"{name} must set SizeMinBytes so a too-small disk fails loudly" if maximum is not None: assert parse_size(minimum) <= parse_size(maximum), ( @@ -127,7 +215,7 @@ def test_size_bounds_are_consistent(name: str, section: dict[str, str]): def test_partition_labels_are_unique(): labels = [ - section["Label"] + section["Label"][0] for section in partitions().values() if "Label" in section ] @@ -136,21 +224,29 @@ def test_partition_labels_are_unique(): ) -def test_esp_is_vfat_and_bounded(): - esp = next(s for s in partitions().values() if s["Type"] == "esp") - assert esp["Format"] == "vfat", "an ESP that is not vfat is unbootable by UEFI" - assert parse_size(esp["SizeMinBytes"]) >= 100 * 1024**2, ( +def test_efi_system_is_vfat_and_bounded(): + esp = by_label("EFI-SYSTEM") + assert single(esp, "Type") == "esp", ( + f"the EFI-SYSTEM partition must be an ESP (type GUID {ESP_GUID})" + ) + assert single(esp, "Format") == "vfat", ( + "an ESP that is not vfat is unbootable by UEFI" + ) + assert parse_size(single(esp, "SizeMinBytes")) >= 100 * 1024**2, ( "the ESP must be large enough for systemd-boot plus at least one UKI" ) assert "SizeMaxBytes" in esp, "the ESP must be capped so it cannot eat the disk" -def test_root_slot_copies_blocks_from_a_label_the_installer_media_stamps(): - root = next(s for s in partitions().values() if s["Type"] == "root") - copy_blocks = root.get("CopyBlocks") +def test_usr_a_copies_blocks_from_a_label_the_installer_media_stamps(): + usr_a = by_label("USR-A") + assert single(usr_a, "Type") == USR_GUID, ( + "USR-A must carry Flatcar's usr type GUID verbatim" + ) + copy_blocks = single(usr_a, "CopyBlocks") assert copy_blocks, ( - "the root partition must CopyBlocks= the DDI payload; without it the " - "installed system has an empty root filesystem" + "USR-A must CopyBlocks= the DDI /usr payload; without it the installed " + "system has an empty /usr" ) prefix = "/dev/disk/by-partlabel/" assert copy_blocks.startswith(prefix), ( @@ -171,65 +267,166 @@ def test_root_slot_copies_blocks_from_a_label_the_installer_media_stamps(): ) -def test_root_slot_grows_and_is_bounded_below_the_var_partition(): - root = next(s for s in partitions().values() if s["Type"] == "root") - assert root.get("GrowFileSystem") == "yes", ( - "the root filesystem must grow to its partition, the DDI payload is " - "smaller than SizeMinBytes" +def test_usr_b_exists_and_is_empty(): + usr_b = by_label("USR-B") + assert single(usr_b, "Type") == USR_GUID, ( + "USR-B must carry Flatcar's usr type GUID verbatim so the kernel " + "recognises the USR-A/USR-B pair" ) - assert "SizeMaxBytes" in root, ( - "the root slot must be capped, otherwise /var gets no space on small disks" + assert "CopyBlocks" not in usr_b, ( + "USR-B is the rollback slot and must stay empty, not a copy of the DDI" ) + assert "CopyFiles" not in usr_b, "USR-B must be empty, not seeded from files" + assert "Format" not in usr_b, "USR-B must be left unformatted (empty)" -def test_var_is_a_growing_xfs_tail(): - var = next(s for s in partitions().values() if s["Type"] == "var") - assert var["Format"] == "xfs" - # FactoryReset=yes must NOT be set on the installer var partition: - # systemd-sysinstall hardcodes deferPartitionsFactoryReset=true via - # Varlink io.systemd.Repart.Run, causing it to defer creating /var. - assert "FactoryReset" not in var, ( - "FactoryReset must not be set on installer var partition or " - "systemd-sysinstall will defer creating it" +def test_oem_is_labelled_ext4(): + oem = by_label("OEM") + assert single(oem, "Type") == OEM_GUID, ( + "OEM must carry Flatcar's OEM type GUID verbatim" ) - assert var["GrowFileSystem"] == "yes" - assert "SizeMaxBytes" not in var, ( - "/var is the tail partition and must grow into all remaining space" + assert single(oem, "Format") == "ext4", "OEM must be ext4" + # Flatcar's stage 2 waits on dev-disk-by-label-OEM.device: the match is on + # the filesystem LABEL, so Label=OEM must also be the filesystem label. + assert single(oem, "Label") == "OEM", ( + "OEM must be formatted with filesystem label OEM or stage 2 never finds it" ) -def test_var_seeds_the_offline_k0s_sysext(): - var = next(s for s in partitions().values() if s["Type"] == "var") - assert var["CopyFiles"] == "/k0s.raw:/lib/k0s/k0s.raw" +def test_root_carries_flatcars_root_guid_and_grows(): + root = by_label("ROOT") + assert single(root, "Type") == ROOT_GUID, ( + "ROOT must carry Flatcar's root type GUID verbatim" + ) + assert single(root, "Format") == "ext4", ( + "ROOT must be formatted at install time: the target boots this " + "partition as its root filesystem, an unformatted ROOT is unbootable" + ) + assert single(root, "GrowFileSystem") == "yes", ( + "the ROOT partition must grow to fill the disk after the other slots" + ) + assert "SizeMaxBytes" not in root, ( + "ROOT is the tail partition and must grow into all remaining space" + ) -def test_root_partition_label_is_matched_by_the_sysupdate_root_transfer(): - root = next(s for s in partitions().values() if s["Type"] == "root") - targets = sysupdate_root_targets() - prefix, _, suffix = targets[0].partition("@v") - assert root["Label"].startswith(prefix) and root["Label"].endswith(suffix.lstrip("_")), ( - f"the installed root label {root['Label']!r} is not matched by " - f"sysupdate target pattern {targets[0]}; OTA updates would find no slot" +def test_root_seeds_the_offline_k0s_sysext(): + root = by_label("ROOT") + assert "/k0s.raw:/var/lib/k0s/k0s.raw" in root.get("CopyFiles", []), ( + "the offline k0s sysext must be seeded into ROOT at the path " + "k0s-first-boot-fetch.service checks, or offline installs cannot " + "enable Kubernetes" + ) + + +def test_root_seeds_the_target_etc_from_the_installer_assembly(): + root = by_label("ROOT") + assert "/usr/lib/bluefin-server/etc-seed:/etc" in root.get("CopyFiles", []), ( + "ROOT must be seeded with /etc from the installer-assembled " + "etc-seed: the DDI payload is /usr-only, so without it the installed " + "system has no /etc (no login, no CA bundle, no unit masks)" + ) + # The seed must actually be assembled by the installer element. + assert "/usr/lib/bluefin-server/etc-seed" in installer_text(), ( + "bluefin-server-installer.bst must assemble the /etc seed at " + "/usr/lib/bluefin-server/etc-seed for CopyFiles= to unpack" + ) + + +def test_target_uki_cmdline_carries_root_and_usr_placement(): + """ROOT's type GUID is not DPS-discoverable, so root= must be explicit. + + This is the boot-discovery assertion the #134 review asked for: a layout + that drops the Discoverable Partitions root type and also lacks ``root=`` + on the kernel cmdline leaves the installed system no way to mount its root. + """ + cmdlines = target_uki_cmdlines() + assert cmdlines, ( + "no target UKI cmdline found in bluefin-server-installer.bst; the " + "cmdline must place root (root=PARTLABEL=ROOT) and /usr " + "(mount.usr=PARTLABEL=USR-A mount.usrfstype=xfs mount.usrflags=ro)" + ) + for cmdline in cmdlines: + for token in TARGET_CMDLINE_TOKENS: + assert token in cmdline, ( + f"the target UKI cmdline is missing {token!r}: with the Flatcar " + "type GUIDs, neither systemd-gpt-auto-generator nor the kernel " + "can discover ROOT on their own" + ) + # The live installer cmdline boots the initrd-only environment and must + # not carry target placement parameters. + installer_cmdlines = re.findall(r'--cmdline="([^"]*)"', installer_text()) + live = [c for c in installer_cmdlines if "system-install.target" in c] + assert live, "the installer UKI cmdline (system-install.target) went missing" + for cmdline in live: + assert "mount.usr=" not in cmdline and "root=PARTLABEL=" not in cmdline, ( + "the installer UKI boots the live environment from its initrd; " + "target placement parameters must stay on the target UKI only" + ) + + +def test_target_usr_fstype_matches_the_ddi_filesystem(): + ddi_text = DDI_ELEMENT.read_text(encoding="utf-8") + assert "mkfs.xfs" in ddi_text, ( + "the DDI payload must be built as XFS: the target cmdline mounts " + "mount.usrfstype=xfs, a mismatch leaves the target unable to mount /usr" + ) + + +def test_no_shipped_unit_requires_the_removed_var_partition(): + """The var partition is gone (#134): nothing may still name it. + + var.mount pointed at /dev/disk/by-partlabel/var and was preset-enabled; + with no producer the unit fails, local-fs.target fails, and the box drops + to emergency mode. The unit and its preset must not merely be unprovisioned + but actually removed, and no shipped config may reference the label again. + """ + assert not (OS_FILES_DIR / "systemd" / "system" / "var.mount").exists(), ( + "var.mount must be removed: the Flatcar layout has no var partition" + ) + assert not ( + OS_FILES_DIR / "systemd" / "system-preset" / "zz-enable-var-mount.preset" + ).exists(), "the preset enabling var.mount must be removed with it" + offenders = [ + str(path.relative_to(REPO_ROOT)) + for path in list(OS_FILES_DIR.rglob("*")) + [DDI_ELEMENT] + if path.is_file() + and "/dev/disk/by-partlabel/var" + in path.read_text(encoding="utf-8", errors="replace") + ] + assert not offenders, ( + f"files still reference the removed var partition: {offenders}" + ) + + +def test_repart_defines_no_var_partition(): + types = [single(section, "Type") for section in partitions().values()] + assert "var" not in types, ( + "the Flatcar layout has no var partition; /var lives on the writable " + f"ROOT (got types {types})" ) @pytest.mark.xfail( strict=True, reason=( - "Known gap, tracked in docs/MVP_1_0_READINESS.md: 50-root.transfer names " - "root-a and root-b, but the installer provisions only root-a, so " - "systemd-sysupdate has no inactive slot to stage into and no atomic " - "rollback path. When root-b is added this test XPASSes and must be " - "un-xfailed." + "Follow-on: 50-root.transfer still targets the legacy " + "bluefin-server-root-_a/_b labels, but the Flatcar layout " + "(projectbluefin/server#134) provisions USR-A/USR-B instead. Wiring " + "the transfer to the real /usr slots and retiring this xfail is the " + "sysupdate follow-on ticket, so the label-match assertion is expected " + "to fail until then. It also still names two slots; USR-B is " + "provisioned empty, so no atomic rollback path exists until the " + "sysupdate wiring lands." ), ) -def test_every_sysupdate_root_target_is_provisioned_by_the_installer(): - targets = set(sysupdate_root_targets()) - provisioned = { - section["Label"] - for section in partitions().values() - if section["Type"] == "root" - } - assert len(targets) <= len(provisioned), ( - f"sysupdate targets {sorted(targets)} require dual slots, only {provisioned} provisioned" - ) +def test_root_partition_label_is_matched_by_the_sysupdate_root_transfer(): + targets = sysupdate_root_targets() + prefix, _, suffix = targets[0].partition("@v") + root = by_label("ROOT") + assert single(root, "Label").startswith(prefix) and single(root, "Label").endswith( + suffix.lstrip("_") + ), ( + f"the installed root label {single(root, 'Label')!r} is not matched by " + f"sysupdate target pattern {targets[0]}; OTA updates would find no slot" + ) \ No newline at end of file