Seal /etc: read-only root with /etc and /usr, state on /var

The root filesystem (/etc and /usr) is now one read-only erofs partition behind dm-verity,
updated A/B as a whole, so /etc can no longer drift from the image (stale CA certificates,
frozen Fedora defaults). All state lives on a new /var partition, mounted by /etc/fstab.

What used to be written to /etc at runtime:
- machine ID: from the VM's firmware UUID (systemd.machine_id=firmware); /etc/machine-id is
  empty, so no boot counts as the first.
- root password: gitea-runner-setup writes a shadow file to /var/lib/shadow, which
  etc-shadow.mount puts over /etc/shadow.
- hostname and runner.env: runner.env moves to /var/lib/gitea-runner and holds the runner's
  name; gitea-runner.service sets it as the (transient) hostname, and DHCP no longer does.

Hosts installed before this change must be reinstalled: updates can't change the partition
layout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V27snrGfdvwU7pMNBiDpHv
This commit is contained in:
Job79andClaude Opus 5.5 committed 2026-11-14 12:12:10 +01:00
1 parent c2ec9ddb29
commit b0a49de3e6
25 files changed
+96 -63

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
# /var, the only writable partition (mkosi.repart/30-var.conf). Grows to fill its partition at boot.
PARTLABEL=var /var ext4 x-systemd.growfs 0 2
View File
Whitespace-only changes.
+1 -1
View File
@@ -1,7 +1,7 @@
# The runner's configuration (gitea-runner.service).
# Every option: `gitea-runner config generate`.
runner:
# Parallel jobs, asked at first boot (stored in /etc/gitea-runner/runner.env).
# Parallel jobs, asked at first boot (stored in /var/lib/gitea-runner/runner.env).
capacity: ${GITEA_RUNNER_CAPACITY}
# On stop (before an update reboot), take no new jobs and give running ones this long to finish.
shutdown_timeout: 30m
@@ -1,4 +0,0 @@
# Grow the root partition to fill the disk at boot (systemd-repart); systemd-growfs then grows
# its filesystem (GrowFileSystem= in mkosi.repart/30-root.conf).
[Partition]
Type=root
+4
View File
@@ -0,0 +1,4 @@
# Grow the /var partition to fill the disk at boot (systemd-repart); x-systemd.growfs in /etc/fstab
# then grows its filesystem.
[Partition]
Type=var
@@ -6,3 +6,7 @@ Kind=!*
[Network]
DHCP=yes
[DHCPv4]
# The hostname is the runner's name (gitea-runner.service), not the DHCP server's.
UseHostname=no
@@ -4,6 +4,7 @@ enable systemd-resolved.service
enable nftables.service
enable podman.socket
enable gitea-runner-setup.service
enable etc-shadow.mount
enable gitea-runner.service
enable systemd-sysupdate-update.timer
enable systemd-sysupdate-reboot.timer
@@ -0,0 +1,14 @@
# The root password. /etc is read-only, so gitea-runner-setup writes the shadow file to /var and
# this mounts it over /etc/shadow.
[Unit]
Description=Root password from /var
ConditionPathExists=/var/lib/shadow/etc/shadow
RequiresMountsFor=/var
[Mount]
What=/var/lib/shadow/etc/shadow
Where=/etc/shadow
Options=bind
[Install]
WantedBy=local-fs.target
@@ -1,7 +1,7 @@
# First boot: asks for the root password and the runner's registration on the console (tty1).
[Unit]
Description=Gitea runner first-boot setup
ConditionPathExists=!/etc/gitea-runner/runner.env
ConditionPathExists=!/var/lib/gitea-runner/runner.env
Before=getty@tty1.service kmsconvt@tty1.service
[Service]
@@ -11,8 +11,10 @@ Requires=podman.socket
# never get the socket (see config.yaml).
User=gitea-runner
WorkingDirectory=/var/lib/gitea-runner
EnvironmentFile=/etc/gitea-runner/runner.env
EnvironmentFile=/var/lib/gitea-runner/runner.env
Environment=DOCKER_HOST=unix:///run/podman/podman.sock
# The hostname is the runner's name. /etc is read-only, so it is set on every start (as root: +).
ExecStartPre=+/usr/bin/hostnamectl hostname --transient ${GITEA_RUNNER_NAME}
# Register once; the result is kept in .runner.
ExecStartPre=/bin/sh -c '[ -f .runner ] || exec gitea-runner register --no-interactive --config /usr/lib/gitea-runner/config.yaml --instance "$GITEA_INSTANCE_URL"'
ExecStart=/usr/bin/gitea-runner daemon --config /usr/lib/gitea-runner/config.yaml
@@ -1,4 +1,4 @@
# Updates /usr: writes the next version to the unused /usr partition.
# Updates the root filesystem: writes the next version to the unused root partition.
# Verify=no: releases are unsigned (no secrets in the repo); SHA256SUMS still checks each download.
[Transfer]
ProtectVersion=%A
@@ -7,12 +7,12 @@ Verify=no
[Source]
Type=url-file
Path=https://git.plabble.org/Job79/git-runner-mkosi/releases/download/latest/
MatchPattern=git-runner_@v.usr-%a.@u.raw.zst
MatchPattern=git-runner_@v.root-%a.@u.raw.zst
[Target]
Type=partition
Path=auto
MatchPattern=git-runner_@v
MatchPartitionType=usr
MatchPartitionType=root
PartitionFlags=0
ReadOnly=1
@@ -1,4 +1,4 @@
# Updates the dm-verity hashes of /usr, next to 10-usr.transfer (which explains Verify=no).
# Updates the root filesystem's dm-verity hashes, next to 10-root.transfer (see it for Verify=no).
[Transfer]
ProtectVersion=%A
Verify=no
@@ -6,12 +6,12 @@ Verify=no
[Source]
Type=url-file
Path=https://git.plabble.org/Job79/git-runner-mkosi/releases/download/latest/
MatchPattern=git-runner_@v.usr-%a-verity.@u.raw.zst
MatchPattern=git-runner_@v.root-%a-verity.@u.raw.zst
[Target]
Type=partition
Path=auto
MatchPattern=git-runner_@v_verity
MatchPartitionType=usr-verity
MatchPartitionType=root-verity
PartitionFlags=0
ReadOnly=1
@@ -1,4 +1,4 @@
# Installs the next UKI, which systemd-boot boots by default. Verify=no: see 10-usr.transfer.
# Installs the next UKI, which systemd-boot boots by default. Verify=no: see 10-root.transfer.
[Transfer]
ProtectVersion=%A
Verify=no
+9 -4
View File
@@ -1,5 +1,7 @@
#!/bin/bash
# First boot: ask for the root password and the runner's registration.
# First boot: asks for the root password and the runner's registration on the console (tty1).
# /etc is read-only, so the answers go to /var: the password to /var/lib/shadow (etc-shadow.mount
# puts it over /etc/shadow), the rest to the runner's runner.env.
set -euo pipefail
echo "== Gitea runner setup =="
@@ -9,15 +11,18 @@ while :; do
[[ -n $pw && $pw == "$pw2" ]] && break
echo "Passwords do not match, try again."
done
echo "root:$pw" | chpasswd
install -d -m 0700 /var/lib/shadow/etc
cp /etc/passwd /etc/shadow /var/lib/shadow/etc/
echo "root:$pw" | chpasswd --prefix /var/lib/shadow
systemctl start etc-shadow.mount
read -rp "Hostname (also the runner name): " name
read -rp "Gitea URL (e.g. https://gitea.example.com): " url
read -rp "Runner registration token: " token
read -rp "Parallel jobs [1]: " capacity
[[ $capacity =~ ^[1-9][0-9]*$ ]] || capacity=1
hostnamectl hostname "$name"
install -D -m 0640 -g gitea-runner /dev/stdin /etc/gitea-runner/runner.env <<ENV
install -D -m 0640 -g gitea-runner /dev/stdin /var/lib/gitea-runner/runner.env <<ENV
GITEA_RUNNER_NAME=$name
GITEA_INSTANCE_URL=$url
GITEA_RUNNER_REGISTRATION_TOKEN=$token
GITEA_RUNNER_CAPACITY=$capacity