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

-19
View File
@@ -1,19 +0,0 @@
# Root filesystem, slot A
#
# /etc and /usr as read-only erofs, protected by dm-verity (roothash= in the
# UKI). Updates replace it whole. /var holds the state, on its own partition
# (30-var.conf).
[Partition]
Type=root
Label=%M_%A
Format=erofs
Compression=lz4hc
CopyFiles=/
ExcludeFilesTarget=/var/
Verity=data
VerityMatchKey=root
SizeMinBytes=1G
SizeMaxBytes=1G
# SplitName holds the partition UUID (%U): roothash= finds the root by it, and
# updates keep it (@u in mkosi.extra/usr/lib/sysupdate.d).
SplitName=%t.%U
+19
View File
@@ -0,0 +1,19 @@
# /usr, slot A
#
# The OS as read-only erofs, protected by dm-verity (usrhash= in the UKI).
# Updates replace it whole. The image holds nothing else but the ESP: the
# initrd makes the root filesystem, with /etc and /var, at first boot
# (mkosi.extra/usr/lib/repart.d/50-root.conf).
[Partition]
Type=usr
Label=%M_%A
Format=erofs
Compression=lz4hc
CopyFiles=/usr:/
Verity=data
VerityMatchKey=usr
SizeMinBytes=1G
SizeMaxBytes=1G
# SplitName holds the partition UUID (%U): usrhash= finds /usr by it, and
# updates keep it (@u in mkosi.extra/usr/lib/sysupdate.d).
SplitName=%t.%U
-11
View File
@@ -1,11 +0,0 @@
# Root verity, slot A
#
# The dm-verity hashes of the root filesystem in 10-root.conf.
[Partition]
Type=root-verity
Label=%M_%A_verity
Verity=hash
VerityMatchKey=root
SizeMinBytes=64M
SizeMaxBytes=64M
SplitName=%t.%U
+11
View File
@@ -0,0 +1,11 @@
# /usr verity, slot A
#
# The dm-verity hashes of /usr in 10-usr.conf.
[Partition]
Type=usr-verity
Label=%M_%A_verity
Verity=hash
VerityMatchKey=usr
SizeMinBytes=64M
SizeMaxBytes=64M
SplitName=%t.%U
@@ -1,8 +1,8 @@
# Root filesystem, slot B
# /usr, slot B
#
# Empty until systemd-sysupdate writes the next version to it.
[Partition]
Type=root
Type=usr
Label=_empty
SizeMinBytes=1G
SizeMaxBytes=1G
-9
View File
@@ -1,9 +0,0 @@
# Root verity, slot B
#
# The dm-verity hashes for 20-root-b.conf, empty until the next update.
[Partition]
Type=root-verity
Label=_empty
SizeMinBytes=64M
SizeMaxBytes=64M
SplitName=-
+9
View File
@@ -0,0 +1,9 @@
# /usr verity, slot B
#
# The dm-verity hashes for 20-usr-b.conf, empty until the next update.
[Partition]
Type=usr-verity
Label=_empty
SizeMinBytes=64M
SizeMaxBytes=64M
SplitName=-
-13
View File
@@ -1,13 +0,0 @@
# State partition
#
# /var: everything reboots and updates keep, such as the setup answers, the
# root password and Claude's login (/var/lib/agent). /etc/fstab mounts it and
# grows it to fill the disk at boot. Claude's home is on it too, but is wiped
# at every boot (mkosi.extra/usr/lib/tmpfiles.d/agent.conf).
[Partition]
Type=var
Label=var
Format=ext4
CopyFiles=/var:/
Minimize=guess
SplitName=-