feat: ParticleOS-like layout: /usr image, encrypted btrfs root

The image now holds only the ESP and a verity-protected /usr (A/B). At
first boot, systemd-repart in the initrd makes the root filesystem: btrfs,
encrypted with a TPM key sealed to the signed PCR 11 policy, with /var as
its own subvolume. A TPM is required. systemd.image_policy= accepts only
an encrypted root and a verity-checked /usr, and FactoryReset=yes lets
factory-reset.target wipe it.

/etc is writable but nearly empty: mkosi.finalize keeps the build's /etc
in /usr/share/factory/etc and systemd-tmpfiles links it in at boot. That
removes etc-shadow.mount, the host key on /var, fstab and /var/lib/agent.
/var now survives reboots.

systemd-firstboot replaces agent-setup: it asks for the root password on
the screen and offers a recovery key. Machines are named agent-???? from
the kernel command line. The user is now agent, with its home in
/home/agent and ssh keys in the default places. sshd.path starts sshd
only once root or agent has a key.

The test VM needs swtpm. The package cache moves to a podman volume
(AGENTS.md). No existing VMs can update to this layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Job79andClaude Opus 5.5 committed 2026-11-19 21:09:31 +01:00
1 parent db8fb0d5a4
commit c80e843cb5
39 files changed
+229 -342

No files matched your search

+38 -33
View File
@@ -2,9 +2,10 @@
#
# A Fedora VM image that runs Claude Code in the background. mkosi.extra/ is
# copied to /, mkosi.repart/ defines the disk and mkosi.sandbox/ adds the
# Claude Code package repository. The root filesystem, /etc included, is
# read-only and replaced whole by updates. All state lives on /var. Claude
# can't change the OS, so it runs its tools in containers.
# Claude Code package repository. /usr is read-only and replaced whole by
# updates. The root filesystem holds the state: /var, and an /etc that is
# mostly links into /usr (mkosi.finalize). Claude can't change the OS, so it
# runs its tools in containers.
# mkosi.extra/etc/claude-code/ sets Claude Code up for that:
# managed-settings.json lets it run without permission prompts, and CLAUDE.md
# tells it about this machine.
@@ -22,12 +23,6 @@ SplitArtifacts=uki,partitions
# builds a CVE affects. .gitea/workflows/os.yml publishes it with the image.
ManifestFormat=json
[Build]
# PackageCacheDirectory keeps downloaded packages between builds, also when
# mkosi runs in a throwaway container (AGENTS.md). dnf still installs the
# newest versions.
PackageCacheDirectory=mkosi.pkgcache
[Content]
Bootable=yes
Bootloader=systemd-boot
@@ -81,31 +76,44 @@ Locale=C.UTF-8
# it installs.
UnifiedKernelImageFormat=%i_%v
# KernelCommandLine sets:
# - console= shows the console on the screen and on the serial port.
# - systemd.machine_id=firmware takes the machine ID from the VM's firmware.
# mkosi.extra/etc/machine-id is empty, so no boot counts as the first.
# - systemd.firstboot=no leaves the questions to agent-setup.
# - console= shows the console on the serial port and the screen. The last
# one, the screen, is /dev/console, where systemd-firstboot asks for the root
# password at first boot.
# - rw mounts the root filesystem writable. The initrd finds it by its
# partition type (mkosi.extra/usr/lib/repart.d/50-root.conf).
# - systemd.hostname= names each machine agent- and four hex digits from its
# machine ID, from the initrd on. It wins over /etc/hostname, so hostnamectl
# renames only until the next boot.
# - systemd.image_policy= makes the initrd use only an encrypted root
# filesystem (or none yet, at first boot) and a verity-checked /usr.
# Otherwise someone with the disk could put in a plain root filesystem with
# their own /etc. Our UKI would boot it, and with PCR 11 unchanged, their
# code could unseal the key of the real one.
# - SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST lets systemd handle more mount
# changes per second. At the default of 5, it holds back mounts at boot and
# delays / and /var by up to a second each. The kernel passes it to systemd
# delays / and /usr by up to a second each. The kernel passes it to systemd
# as environment.
KernelCommandLine=
console=tty0
console=ttyS0,115200n8
console=tty0
quiet
systemd.machine_id=firmware
systemd.firstboot=no
rw
systemd.hostname=agent-????
systemd.image_policy=root=encrypted+absent:usr=verity:esp=unprotected
SYSTEMD_DEFAULT_MOUNT_RATE_LIMIT_BURST=50
# KernelInitrdModules are the modules the initrd needs to find and mount the
# disks of a VM.
# KernelInitrdModules are the modules the initrd needs to find the disks of a
# VM, mount /usr and make, unlock and mount the root filesystem.
KernelInitrdModules=
virtio_blk
virtio_scsi
sd_mod
nvme
tpm_tis
tpm_crb
dm-verity
dm-crypt
erofs
ext4
btrfs
# KernelModules keeps all modules but the hardware drivers, then the drivers a
# VM needs (disks, network, screen) and those of rootless podman's networks
# (pasta). The last matching line wins. Keyboard, USB and a basic screen are
@@ -129,12 +137,6 @@ KernelModules=
# - System.map is only for debugging the kernel.
# - The udev hwdb holds hardware names and quirks, nothing a VM needs.
# - homed, userdbd and nsresourced are unused services.
# - sshd-keygen would write host keys to the read-only /etc. sshd uses one host
# key on /var instead (mkosi.extra/etc/ssh/sshd_config.d).
# - /afs is the mount point for the AFS network filesystem.
# - /buildroot holds dnf's lock file, left by mkosi: it passes dnf5
# persistdir=/buildroot/var/lib/dnf and dnf5 puts the install root in front
# of it again.
RemoveFiles=
/usr/lib/modules/*/System.map
/usr/lib/udev/hwdb.bin
@@ -142,9 +144,6 @@ RemoveFiles=
/usr/lib/systemd/system/systemd-homed*
/usr/lib/systemd/system/systemd-userdbd.*
/usr/lib/systemd/system/systemd-nsresourced.*
/usr/lib/systemd/system/sshd-keygen*
/afs
/buildroot
[Validation]
# SecureBoot signs systemd-boot and the UKI, and puts our keys on the ESP.
@@ -154,12 +153,17 @@ RemoveFiles=
SecureBoot=yes
SecureBootKey=mkosi.key
SecureBootCertificate=mkosi.crt
# SignExpectedPcr signs the PCR 11 values that each UKI will measure, with
# mkosi.key. The TPM then unlocks the root filesystem only for UKIs we signed,
# also after updates (mkosi.extra/usr/lib/repart.d/50-root.conf).
SignExpectedPcr=yes
[Runtime]
# Runtime sets up the test VM of mkosi vm (AGENTS.md). Ephemeral boots a copy,
# so test runs don't change the built image. Credentials answer the setup
# (mkosi.extra/usr/libexec/agent-setup). mkosi ssh logs in as root with
# mkosi.key, which mkosi also authorizes for root in the VM.
# so test runs don't change the built image. Credentials sets the root
# password, and systemd.firstboot=no skips the questions at first boot, such
# as the offer of a recovery key. mkosi ssh logs in as root with mkosi.key,
# which mkosi also authorizes for root in the VM.
Ephemeral=yes
CPUs=4
RAM=8G
@@ -168,4 +172,5 @@ RuntimeSize=40G
# doesn't use hvc0: with Secure Boot, systemd-stub ignores the console= mkosi
# passes.
QemuArgs=-serial chardev:console
Credentials=agent.password=root agent.hostname=agent-test
Credentials=passwd.plaintext-password.root=root
KernelCommandLineExtra=systemd.firstboot=no