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
2.8 KiB
git-runner-mkosi
A Gitea Actions runner packaged as a minimal Fedora VM image, built with mkosi. It builds and publishes its own OS image, and keeps itself up to date.
- Small: Fedora with podman, networking and zram swap, for VMs only: no firmware or drivers for real hardware, no package manager or sshd. About 300 MB of RAM idle; boots in 512 MB.
- Stateless: container storage is wiped on every boot.
- Isolated jobs: each job runs in a container of its own (privileged, so it can build OS images), with its own podman; jobs never get the runner's podman. The job image ships with the OS, and common base images are shared read-only, so jobs don't download them. A job that runs the VM out of memory is killed (systemd-oomd); the runner keeps running.
- Self-updating: images are rebuilt weekly and on every push. Hosts download updates with systemd-sysupdate into a second root partition (A/B) and reboot into them daily at about 04:10, after letting running jobs finish.
- Read-only system: systemd-boot starts a UKI that mounts the root filesystem, /etc and /usr included, from a read-only erofs partition checked by dm-verity. Updates replace it whole, so nothing drifts. All state (the runner registration, the root password, logs) lives on /var, its own partition.
- Hardened: a firewall that drops all incoming traffic, and KSPP sysctls and kernel arguments.
Install
Download the disk image (built weekly by the os workflow), resize it to the disk size you want (/var grows to fill it) and boot it with UEFI. The console asks for a root password, hostname, Gitea URL, registration token and number of parallel jobs; the runner then registers itself.
Images
runs-on |
Image |
|---|---|
linux |
Our job image (mkosi.images/job/): git, Node.js, skopeo, dnf and podman (also as docker) |
fedora |
Plain Fedora, used by our own build so a broken job image can't block its fix |
Development
mkosi.conf defines the OS (mkosi.extra/ is copied to /, mkosi.repart/ is the disk layout), mkosi.images/job/ the job image.
mkosi build
mkosi.output/ then holds the disk image (git-runner_<version>.raw), and the UKI and root partitions that the os workflow publishes as an update. To boot the disk image (needs qemu-kvm-core edk2-ovmf):
qemu-img convert -O qcow2 mkosi.output/git-runner_<version>.raw test.qcow2 && qemu-img resize test.qcow2 40G
cp /usr/share/edk2/ovmf/OVMF_VARS.fd vars.fd
qemu-kvm -m 8G -smp 4 -cpu host -nic user,model=virtio-net-pci -drive file=test.qcow2,if=virtio \
-drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2/ovmf/OVMF_CODE.fd -drive if=pflash,format=raw,file=vars.fd