sector-f-linux

Sector F Linux
git clone https://git.sectorflabs.com/sector-f-linux.git
Log | Files | Refs | README | LICENSE

commit f5b0eeafe01065f4696194158238feb188bf416d
parent ed770849b777ed61bed791a91751400a37d96d79
Author: Divan Visagie <me@divanv.com>
Date:   Fri, 16 Oct 2026 00:27:49 +0200

A Containerfile and a test VM: build, install, boot, upgrade, roll back

vm/ builds the image with Docker, pushes it to a local registry, installs
it onto a disk file with the image's own bootc (composefs, systemd-boot),
and boots it in QEMU with KVM and UEFI, a second disk for ZFS and SSH on
localhost:2222. The VM upgrades from the registry and rolls back.

The base's kernel 7.0.0-15 can't boot composefs (the fs-verity
regression in 7.0); the image takes the archive's 7.0.0-38, which
does. The minimal base has no network configuration, so system/ adds
DHCP with systemd-networkd.

Diffstat:
A.dockerignore | 2++
A.gitignore | 1+
AContainerfile | 45+++++++++++++++++++++++++++++++++++++++++++++
MREADME.md | 2+-
Mdocs/notes.md | 6+++---
Asystem/usr/lib/systemd/network/80-wired.network | 8++++++++
Avm/README.md | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Avm/build.sh | 11+++++++++++
Avm/common.sh | 39+++++++++++++++++++++++++++++++++++++++
Avm/disk.sh | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avm/registries.conf | 9+++++++++
Avm/registry.sh | 17+++++++++++++++++
Avm/vm.sh | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13 files changed, 332 insertions(+), 4 deletions(-)

diff --git a/.dockerignore b/.dockerignore @@ -0,0 +1,2 @@ +out/ +.git/ diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +/out/ diff --git a/Containerfile b/Containerfile @@ -0,0 +1,45 @@ +# Patina OS: the system image. For now just the Ubuntu 26.04 bootc base with a +# current kernel, set up to update from the development registry, to try out +# booting, upgrading and rolling back in a VM (see vm/README.md). Patina's +# desktop comes later. + +# apt's database as a fresh Ubuntu has it: the base image empties /var, so +# derived images restore it to use apt (as the base's AGENTS.md describes). +FROM docker.io/library/ubuntu@sha256:f144425ff09be612d6d9ad965196e9cdc23dae1f42110a8a11a3e9a8198759f7 AS dpkg-state + +# ubuntu-bootc's minimal 26.04 base, pinned by digest (docs/notes.md). +FROM ghcr.io/ubuntu-bootc/ubuntu-26.04-bootc@sha256:d50ac19557f0b5bc56a980178aa68e3675735ad06b3750b4c9af967901e966f4 + +COPY --from=dpkg-state /var/lib/dpkg /var/lib/dpkg + +# The base's kernel (7.0.0-15) has the fs-verity regression that stops a +# composefs system booting ("Failed to execute /sbin/init: Input/output error", +# bootc issue 2174, fixed from 7.0.7). Take the archive's current kernel, keep +# only it, and build its initramfs with the base's dracut settings. Kernel hooks +# are stubbed by the base, and /boot is emptied: bootc boots from /usr/lib/modules. +RUN mkdir -p /var/cache/apt/archives/partial /var/lib/apt/lists/partial /var/log/apt \ + /var/tmp /var/roothome && \ + apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + dracut linux-image-generic && \ + kver=$(ls /usr/lib/modules | sort -V | tail -1) && \ + for k in /usr/lib/modules/*; do [ "${k##*/}" = "$kver" ] || rm -rf "$k"; done && \ + cp "/boot/vmlinuz-$kver" "/usr/lib/modules/$kver/vmlinuz" && \ + dracut --force --kver "$kver" "/usr/lib/modules/$kver/initramfs.img" && \ + rm -rf /boot/* && \ + apt-get clean && \ + rm -rf /var && mkdir /var + +# Files the system adds to the base, as laid out under system/. +COPY system/ / +RUN systemctl enable systemd-networkd.service + +# Trust the development registry: localhost:5000 on the host, which is 10.0.2.2 +# from inside a QEMU VM. Development builds only. +COPY vm/registries.conf /etc/containers/registries.conf.d/50-patina-dev.conf + +# Which build this is, so an upgrade can be seen to have happened. +ARG BUILD_ID=unknown +RUN mkdir -p /usr/lib/patina-os && echo "$BUILD_ID" > /usr/lib/patina-os/build + +RUN bootc container lint diff --git a/README.md b/README.md @@ -1,6 +1,6 @@ # Patina OS -An operating system image for the Patina desktop: Ubuntu as a bootc image, so a machine boots +A Linux based operating system image for the Patina desktop: Ubuntu as a bootc image, so a machine boots one known-good build, updates by moving to the next one whole, and rolls back if it breaks. The user's data lives on a ZFS pool beside it. diff --git a/docs/notes.md b/docs/notes.md @@ -11,9 +11,9 @@ Research for Patina OS, and what's still open. Dated, since this moves quickly. desktop, no flatpak, no ZFS), plus desktop and server variants. Updated May 2026. - **Canonical** doesn't support bootc; its own image-based system is Ubuntu Core (snaps). A talk at Ubuntu Summit 26.04 argued for officially packaged bootc components and base images. -- One guide (jmarrero/ubuntu-bootc) says Ubuntu 26.04's kernel 7.0 has a regression that breaks - composefs boot, and works around it with kernel 6.17. **Check this**: nifl and huginn are - both Ubuntu 26.04.1 on 7.0.0-38-generic. Single source. +- **Confirmed 2026-10-16**: the minimal base's kernel (7.0.0-15) can't boot composefs (fs-verity + regression in 7.0, bootc issue 2174, fixed from 7.0.7). The archive's 7.0.0-38 (nifl's and + huginn's) boots; the Containerfile installs it. vm/README.md has the rest of what the VM found. ## ZFS diff --git a/system/usr/lib/systemd/network/80-wired.network b/system/usr/lib/systemd/network/80-wired.network @@ -0,0 +1,8 @@ +# Wired interfaces by DHCP, with systemd-networkd. Enough for the VM and a +# headless machine; the desktop will bring NetworkManager (patina-wifi) instead. +[Match] +Type=ether +Kind=!* + +[Network] +DHCP=yes diff --git a/vm/README.md b/vm/README.md @@ -0,0 +1,53 @@ +# The test VM + +Builds the image, installs it onto a disk file the way it would go onto a real disk, and boots it +in QEMU, then lets the VM upgrade from a local registry and roll back. Needs Docker, QEMU with KVM, +and OVMF (`apt install qemu-system-x86 ovmf`); no root, no podman on the host. + +``` +vm/build.sh build the Containerfile, push it to the registry on localhost:5000 +vm/disk.sh install the image onto out/disk.raw (and make out/data.qcow2, the SSH key) +vm/vm.sh start boot it in the background (serial console in out/serial.log) +vm/vm.sh wait wait until SSH answers +vm/vm.sh ssh [cmd] a root shell, or a command +vm/vm.sh console boot it on this terminal instead (Ctrl-a x quits) +vm/vm.sh log follow the serial console +vm/vm.sh stop power it off +``` + +Trying an update: + +``` +vm/build.sh # a new build, pushed +vm/vm.sh ssh bootc upgrade # the VM fetches and stages it +vm/vm.sh ssh systemctl reboot # boots into it +vm/vm.sh ssh cat /usr/lib/patina-os/build # which build is running +vm/vm.sh ssh bootc rollback # the previous one, at the next boot +``` + +## How it works + +- **The registry** (`vm/registry.sh`, started by the others) is Docker's `registry:2` on + localhost:5000, which the VM reaches as 10.0.2.2:5000 (QEMU's user network). The image + trusts it over plain HTTP (`vm/registries.conf`); that's for development builds only. +- **The install** runs the image itself, privileged, with the host's `/dev` for a loop device: + its own podman pulls it from the registry, and its own `bootc install to-disk` writes the + disk, with the composefs backend and systemd-boot, as ubuntu-bootc's CI does. The installed + system follows `10.0.2.2:5000/patina-os:dev`. +- **After the install**, the boot entry gets `root=UUID=...` (systemd 259 on 26.04 doesn't always + find the root by itself) and root's `authorized_keys` goes straight into the installed `/var`. +- **The VM** has 4 CPUs, 4 GB, UEFI, the system disk, an empty 10 GB second disk for the ZFS pool + (`vdb`), and SSH on localhost:2222 with the key in `out/id_ed25519`. + +## Found along the way + +- The base image's kernel (7.0.0-15) can't boot composefs: "Failed to execute /sbin/init: + Input/output error", fs-verity's regression in 7.0 (bootc issue 2174, fixed from 7.0.7). + The Containerfile installs the archive's current kernel (7.0.0-38), which boots. +- bootc's composefs backend can't install straight from a registry ("Invalid splitstream + content type"), only from podman's storage, hence the pull inside the install container. +- `--root-ssh-authorized-keys` leaves `/root/.ssh` empty with the composefs backend. +- The minimal base has no network configuration; `system/` adds DHCP on wired interfaces + with systemd-networkd. +- Docker here has only the legacy builder (no BuildKit), so the Containerfile uses + `COPY --from` rather than `RUN --mount`. diff --git a/vm/build.sh b/vm/build.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# Builds the image from the Containerfile and pushes it to the development +# registry, where a VM's `bootc upgrade` finds it. +source "$(dirname "$0")/common.sh" + +"$ROOT/vm/registry.sh" +build_id=$(date -u +%Y-%m-%dT%H:%M:%SZ) +say "building $IMAGE ($build_id)" +docker build -f "$ROOT/Containerfile" --build-arg BUILD_ID="$build_id" -t "$IMAGE" "$ROOT" +say "pushing $IMAGE" +docker push -q "$IMAGE" diff --git a/vm/common.sh b/vm/common.sh @@ -0,0 +1,39 @@ +# Shared by the vm/ scripts; sourced, not run. + +set -euo pipefail + +ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) +OUT="$ROOT/out" + +# The development registry, on the host and as the VM sees it. +REGISTRY_NAME=patina-os-registry +REGISTRY_PORT=5000 +IMAGE="localhost:$REGISTRY_PORT/patina-os:dev" +VM_IMAGE="10.0.2.2:$REGISTRY_PORT/patina-os:dev" + +DISK="$OUT/disk.raw" +DISK_SIZE=20G +# A second, empty disk for the ZFS pool for /home (ADR-0001). +DATA="$OUT/data.qcow2" +DATA_SIZE=10G +KEY="$OUT/id_ed25519" +SSH_PORT=2222 +SERIAL_LOG="$OUT/serial.log" +PIDFILE="$OUT/qemu.pid" + +OVMF_CODE=/usr/share/OVMF/OVMF_CODE_4M.fd +OVMF_VARS_TEMPLATE=/usr/share/OVMF/OVMF_VARS_4M.fd +OVMF_VARS="$OUT/OVMF_VARS.fd" + +mkdir -p "$OUT" + +say() { printf '==> %s\n' "$*"; } +die() { printf 'error: %s\n' "$*" >&2; exit 1; } + +vm_running() { [[ -f "$PIDFILE" ]] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null; } + +vm_ssh() { + ssh -i "$KEY" -p "$SSH_PORT" \ + -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR \ + root@127.0.0.1 "$@" +} diff --git a/vm/disk.sh b/vm/disk.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +# Installs the image onto a fresh disk file, out/disk.raw, the way it would go +# onto a real disk: the image runs its own `bootc install to-disk` through a loop +# device. The installed system follows the development registry, so `bootc +# upgrade` in the VM fetches what vm/build.sh pushed. Also makes the SSH key and +# the empty second disk for ZFS. +source "$(dirname "$0")/common.sh" + +vm_running && die "the VM is running; vm/vm.sh stop first" +docker image inspect "$IMAGE" >/dev/null 2>&1 || die "no $IMAGE; vm/build.sh first" +"$ROOT/vm/registry.sh" + +[[ -f "$KEY" ]] || ssh-keygen -q -t ed25519 -N '' -C patina-os-vm -f "$KEY" + +say "installing $IMAGE onto $DISK" +rm -f "$DISK" "$OVMF_VARS" +truncate -s "$DISK_SIZE" "$DISK" +# Privileged with the host's /dev, for the loop device. bootc installs from +# podman's storage, normally the host's; there's no podman here, so the image's +# own podman pulls it from the registry into a storage folder of its own first +# (bootc's composefs backend can't read it straight from the registry). The +# target is the same image as the VM will see it. +mkdir -p "$OUT/containers" +docker run --rm --privileged --network host \ + -v /dev:/dev -v "$OUT:/data" -v "$OUT/containers:/var/lib/containers" \ + "$IMAGE" bash -euc ' + mkdir -p /var/tmp # /var in the image is empty until it boots + podman pull -q "$1" >/dev/null + bootc install to-disk \ + --via-loopback /data/disk.raw \ + --wipe \ + --filesystem ext4 \ + --composefs-backend \ + --bootloader systemd \ + --source-imgref "containers-storage:$1" \ + --target-imgref "$2" \ + --karg console=tty0 \ + --karg console=ttyS0,115200 \ + --karg systemd.firstboot=no +' install "$IMAGE" "$VM_IMAGE" + +# systemd 259 on 26.04 doesn't always find the root partition by itself; name it +# in the boot entries, as ubuntu-bootc's own CI does. And let root in by the SSH +# key: bootc's --root-ssh-authorized-keys leaves /root/.ssh empty with the +# composefs backend, so the key goes straight into the installed /var. +say "naming the root partition, adding the SSH key" +docker run --rm --privileged -v /dev:/dev -v "$OUT:/data" "$IMAGE" bash -euc ' + loop=$(losetup -f --show --partscan /data/disk.raw) + trap "losetup -d $loop" EXIT + udevadm settle 2>/dev/null || sleep 1 + for p in ${loop}p*; do + case $(blkid -s TYPE -o value "$p") in + ext4|xfs) root=$p ;; + vfat) esp=$p ;; + esac + done + uuid=$(blkid -s UUID -o value "$root") + type=$(blkid -s TYPE -o value "$root") + mnt=$(mktemp -d) && mount "$esp" "$mnt" + for conf in "$mnt"/loader/entries/*.conf; do + grep -q "^options.*root=" "$conf" || + sed -i "s|^options |options root=UUID=$uuid rootfstype=$type |" "$conf" + grep "^options" "$conf" + done + umount "$mnt" + mount "$root" "$mnt" + ssh=$mnt/state/os/default/var/roothome/.ssh + install -d -m 700 "$ssh" + install -m 600 /data/id_ed25519.pub "$ssh/authorized_keys" + umount "$mnt" +' + +[[ -f "$DATA" ]] || qemu-img create -q -f qcow2 "$DATA" "$DATA_SIZE" +say "done: vm/vm.sh start" diff --git a/vm/registries.conf b/vm/registries.conf @@ -0,0 +1,9 @@ +# The development registry (vm/registry.sh), over plain HTTP: localhost:5000 on +# the host, 10.0.2.2:5000 from inside a QEMU VM. +[[registry]] +location = "localhost:5000" +insecure = true + +[[registry]] +location = "10.0.2.2:5000" +insecure = true diff --git a/vm/registry.sh b/vm/registry.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Starts the development registry on localhost:5000, if it isn't running. Images +# are kept in a Docker volume, so they survive restarts. +source "$(dirname "$0")/common.sh" + +if [[ "$(docker inspect -f '{{.State.Running}}' "$REGISTRY_NAME" 2>/dev/null)" == true ]]; then + exit 0 +fi +if docker inspect "$REGISTRY_NAME" >/dev/null 2>&1; then + docker start "$REGISTRY_NAME" >/dev/null +else + say "starting the registry on localhost:$REGISTRY_PORT" + docker run -d --name "$REGISTRY_NAME" --restart unless-stopped \ + -p "127.0.0.1:$REGISTRY_PORT:5000" \ + -v patina-os-registry:/var/lib/registry \ + docker.io/library/registry:2 >/dev/null +fi diff --git a/vm/vm.sh b/vm/vm.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +# The test VM: QEMU with KVM and UEFI, booting out/disk.raw, with the empty +# out/data.qcow2 as a second disk and SSH on localhost:2222. +# +# vm/vm.sh start boot it in the background; the serial console goes to out/serial.log +# vm/vm.sh console boot it in the foreground on this terminal (Ctrl-a x quits) +# vm/vm.sh ssh [cmd] a shell (or a command) as root +# vm/vm.sh wait wait until SSH answers +# vm/vm.sh log follow the serial console +# vm/vm.sh stop power it off +source "$(dirname "$0")/common.sh" + +qemu_args() { + [[ -f "$OVMF_VARS" ]] || cp "$OVMF_VARS_TEMPLATE" "$OVMF_VARS" + printf '%s\n' \ + -enable-kvm -cpu host -m 4096 -smp 4 \ + -machine q35 \ + -drive "if=pflash,format=raw,readonly=on,file=$OVMF_CODE" \ + -drive "if=pflash,format=raw,file=$OVMF_VARS" \ + -drive "file=$DISK,format=raw,if=virtio" \ + -drive "file=$DATA,format=qcow2,if=virtio" \ + -nic "user,model=virtio-net-pci,hostfwd=tcp:127.0.0.1:$SSH_PORT-:22" +} + +need_disk() { [[ -f "$DISK" ]] || die "no $DISK; vm/disk.sh first"; } + +case "${1:-}" in + start) + need_disk + vm_running && die "already running" + mapfile -t args < <(qemu_args) + qemu-system-x86_64 "${args[@]}" \ + -display none -serial "file:$SERIAL_LOG" \ + -daemonize -pidfile "$PIDFILE" + say "started; vm/vm.sh wait, then vm/vm.sh ssh" + ;; + console) + need_disk + vm_running && die "already running" + mapfile -t args < <(qemu_args) + exec qemu-system-x86_64 "${args[@]}" -nographic + ;; + ssh) + shift + vm_ssh "$@" + ;; + wait) + vm_running || die "not running" + for _ in $(seq 1 120); do + vm_ssh true 2>/dev/null && { say "up"; exit 0; } + vm_running || die "QEMU exited; see $SERIAL_LOG" + sleep 2 + done + die "no SSH after 4 minutes; see $SERIAL_LOG" + ;; + log) + exec tail -f "$SERIAL_LOG" + ;; + stop) + vm_running || exit 0 + kill "$(cat "$PIDFILE")" + rm -f "$PIDFILE" + say "stopped" + ;; + *) + sed -n '2,10p' "$0" | sed 's/^# \{0,1\}//' + exit 1 + ;; +esac