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

@@ -8,8 +8,3 @@ Kind=!*
[Network]
DHCP=yes
[DHCPv4]
# UseHostname=no keeps the hostname asked at setup (agent-boot) instead of the
# DHCP server's.
UseHostname=no
@@ -5,19 +5,16 @@
enable systemd-networkd.service
enable systemd-resolved.service
enable sshd.service
# sshd.path starts sshd once there is an ssh key, so Fedora's preset of
# sshd.service is overruled.
enable sshd.path
disable sshd.service
# getty@.service is the login on the screen, which Fedora disables (tty1, and
# tty2-6 through its autovt@ alias).
enable getty@.service
enable agent-setup@.service tty1 ttyS0
enable etc-shadow.mount
enable agent-boot.service
enable claude-remote.path
enable systemd-sysupdate-update.timer
enable systemd-sysupdate-reboot.timer
# These services do nothing here, but Fedora enables them: no PAM or crypto
# changes on a read-only /etc, and no system or config extensions.
# authselect-apply-changes would rewrite /etc/authselect, which links into the
# read-only /usr (mkosi.finalize), and fails.
disable authselect-apply-changes.service
disable fips-crypto-policy-overlay.service
disable systemd-sysext.service
disable systemd-confext.service
@@ -1,17 +0,0 @@
# Apply setup
#
# Runs /usr/libexec/agent-boot at every boot. Before the setup is done there
# is nothing to apply, so agent-setup starts this once it is.
[Unit]
Description=Apply agent setup
ConditionPathExists=/var/lib/agent/hostname
After=systemd-tmpfiles-setup.service
Before=sshd.service claude-remote.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/libexec/agent-boot
[Install]
WantedBy=multi-user.target
@@ -1,25 +0,0 @@
# First-boot setup
#
# Runs /usr/libexec/agent-setup on the screen (tty1) and the serial console
# (ttyS0) at once, so it can be answered on either. Whichever is answered first
# stops the other.
[Unit]
Description=Agent first-boot setup on %I
ConditionPathExists=!/var/lib/agent/hostname
After=systemd-tmpfiles-setup.service
Before=getty@%i.service serial-getty@%i.service
[Service]
Type=oneshot
ImportCredential=agent.*
ExecStart=/usr/libexec/agent-setup
StandardInput=tty
StandardOutput=tty
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
# SuccessExitStatus counts being stopped by the other console as success.
SuccessExitStatus=SIGTERM
[Install]
WantedBy=multi-user.target
@@ -6,7 +6,7 @@
Description=Start Claude Remote Control once logged in
[Path]
PathExists=/var/lib/agent/claude/.credentials.json
PathExists=/home/agent/.claude/.credentials.json
[Install]
WantedBy=multi-user.target
@@ -1,17 +1,16 @@
# Claude Remote Control
#
# Runs Claude Code in the background, in Claude's home, so it can be used from
# claude.ai/code or the Claude app. claude-remote.path starts it once Claude is
# logged in.
# Runs Claude Code in the background, as the user agent in its home, so it can
# be used from claude.ai/code or the Claude app. claude-remote.path starts it
# once Claude is logged in.
[Unit]
Description=Claude Code Remote Control
Wants=network-online.target user@1000.service
After=network-online.target user@1000.service agent-boot.service
After=network-online.target user@1000.service
[Service]
User=claude
User=agent
WorkingDirectory=~
EnvironmentFile=/etc/environment
Environment=XDG_RUNTIME_DIR=/run/user/1000
ExecStart=/usr/bin/claude remote-control --name %H
Restart=always
@@ -1,16 +0,0 @@
# Root password
#
# /etc is read-only, so agent-setup writes the shadow file to /var and this
# mounts it over /etc/shadow.
[Unit]
Description=Root password from /var
ConditionPathExists=/var/lib/agent/etc/shadow
RequiresMountsFor=/var
[Mount]
What=/var/lib/agent/etc/shadow
Where=/etc/shadow
Options=bind
[Install]
WantedBy=local-fs.target
@@ -0,0 +1,14 @@
# Start sshd once there is a key
#
# sshd starts only once root or the user agent has an ssh key, so a new VM
# has no open port. Root adds the keys after the first boot (README.md). The
# ssh.authorized_keys.root credential also fills root's, such as for mkosi ssh.
[Unit]
Description=Start sshd once an ssh key is set
[Path]
PathExists=/home/agent/.ssh/authorized_keys
PathExists=/root/.ssh/authorized_keys
[Install]
WantedBy=multi-user.target
@@ -1,7 +0,0 @@
# sshd after setup
#
# sshd needs the host key, which agent-boot makes once the setup is done.
# agent-setup then starts sshd.
[Unit]
After=agent-boot.service
ConditionPathExists=/var/lib/agent/ssh_host_ed25519_key