sector-f-linux

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

commit 9dafc03e9eb88095bb113ea04d3dbfd76d19fee1
parent 1cb71d3270c996d5d5b0b5c7666fbf6d5f5a52cc
Author: Divan Visagie <me@divanv.com>
Date:   Sat, 21 Nov 2026 03:17:45 +0100

live: patina-install and its polkit rule, tried on two blank drives (ADR-0014, step 2)

linux/live/usr/libexec/patina-install refuses anything but a whole, writable, unmounted disk of at least 12 GB that is not the live medium, checks the scratch memory, and runs bootc install to-disk from the payload in the disc's container storage, offline. The polkit action and rule let the greetd user run it through pkexec on the live disc only. The Containerfile's live stage records the payload and the target the installed machine follows (PAYLOAD / TARGET_IMGREF in live/build.sh); LIVE_DEBUG=1 adds an SSH key for testing; try.sh gets ssh and disk subcommands.

Tried from a 2.8 GB payload ISO in QEMU with two blank drives: bad targets refused, nobody refused by polkit, drive A installed and booted alone to the greeter's login, drive B untouched. bootc's scratch space turned out to be the live system's /var/tmp (its helper runs in the host mount namespace), so the command mounts a tmpfs there; the largest layer (1.53 GB) sets the RAM needed. Findings and what is not yet checked are in ADR-0014.

Diffstat:
Mdocs/adr/0014-the-live-disc-boots-straight-into-the-installer.md | 34++++++++++++++++++++++++++++++++++
Mlinux/Containerfile | 16++++++++++++++++
Mlinux/live/build.sh | 19+++++++++++++++----
Mlinux/live/try.sh | 26++++++++++++++++++++++----
Alinux/live/usr/libexec/patina-install | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Alinux/live/usr/share/polkit-1/actions/com.sectorflabs.patina.install.policy | 15+++++++++++++++
Alinux/live/usr/share/polkit-1/rules.d/50-patina-install.rules | 9+++++++++
7 files changed, 185 insertions(+), 8 deletions(-)

diff --git a/docs/adr/0014-the-live-disc-boots-straight-into-the-installer.md b/docs/adr/0014-the-live-disc-boots-straight-into-the-installer.md @@ -104,6 +104,40 @@ Found on the way: - Not yet: the installer, the payload, the drive picker, the privileged install command, Secure Boot and real hardware. +## Step 2 done (2026-11-21): `patina-install`, on two blank drives + +`linux/live/usr/libexec/patina-install <drive>` (in the live image only) refuses anything but a whole, +writable, unmounted disk of at least 12 GB that is not the drive the live system booted from, checks +that there is enough scratch memory, and runs `bootc install to-disk --wipe --filesystem btrfs` from +the payload in the disc's container storage, offline. A polkit action and rule +(`com.sectorflabs.patina.install`, in the live image only) let the `greetd` user run it through +`pkexec`, and nobody else. + +Tried in QEMU from the payload ISO (2.8 GB, with the development image as payload), 4 GB RAM, two blank +16 GB drives: the bad targets (the optical drive, a partition, a missing device) were refused; `nobody` +was refused by polkit; the install of drive A took about 5 minutes and ended with "Installation +complete"; drive B had no signature and nothing allocated on the host; drive A booted on its own, +without the ISO, to the greeter's login with the account of the payload image. + +Found on the way: +- **bootc's scratch space is the live system's `/var/tmp`, not the container's.** It reads the payload + through a helper in the host's mount namespace, so a bind mount into the container did nothing, and + the live disk (RAM, about 550 MB free) filled up: "no space left on device". The command mounts a + tmpfs on the live `/var/tmp` for the run, 70% of the RAM (it takes memory only as it is used). + Peak use seen: 1.5 GB, with the VM's free memory down to 1.6 GB of 3 GB. +- **The largest layer sets the memory the install needs.** The image's big `dnf install` layer is + 1.53 GB. The command checks the scratch size against the largest layer (with a quarter more) before + it wipes anything, and says so. About 4 GB of RAM works; **splitting that layer** into several + smaller ones, or rechunking the image, would lower it, and make updates smaller too (to do). +- **`podman history --human=false` still prints "797kB"**; the command converts the units itself. +- **The installed machine follows `TARGET_IMGREF`** (the published `sectorf-linux` by default; the + test build sets the development image). + +Not yet checked: SELinux labelling of the installed system (the live system runs with `selinux=0`; +the first boot of the installed drive was not logged in to), several drives and a USB stick as the +live medium, Secure Boot, a power cut half way, and the progress reporting for the app (the command +prints `STEP n/total` lines, but `bootc install` itself gives no percentage that was looked at). + ## Consequences - The live disc is one job, and the installer is the only new app. The greeter does not get a live mode. diff --git a/linux/Containerfile b/linux/Containerfile @@ -139,6 +139,22 @@ RUN dnf -y --setopt=install_weak_deps=False install \ RUN mkdir -p /boot/efi && cp -ra /usr/lib/efi/*/*/EFI /boot/efi/ COPY build/greeter/ / COPY live/etc/ /etc/ +COPY live/usr/ /usr/ +# What the install command installs, and what the installed machine then follows: the payload +# (an image in this disc's container storage, put there by image-builder) and the registry image the +# machine updates from. Set by live/build.sh. +ARG PAYLOAD_REF= +ARG TARGET_IMGREF=registry.example.com/sectorf-linux:latest +RUN mkdir -p /usr/lib/patina-install && echo "$PAYLOAD_REF" > /usr/lib/patina-install/payload && \ + echo "$TARGET_IMGREF" > /usr/lib/patina-install/target +# For testing only (LIVE_DEBUG=1 in live/build.sh): root can log in over SSH with the test rig's key. +# A real ISO has no SSH access. +ARG DEBUG_SSH_KEY= +RUN if [ -n "$DEBUG_SSH_KEY" ]; then \ + mkdir -p /var/roothome/.ssh && echo "$DEBUG_SSH_KEY" > /var/roothome/.ssh/authorized_keys && \ + chmod 700 /var/roothome/.ssh && chmod 600 /var/roothome/.ssh/authorized_keys && \ + systemctl enable sshd.service; \ + else systemctl disable sshd.service 2>/dev/null || true; fi COPY system/usr/lib/tmpfiles.d/patina-greeter.conf /usr/lib/tmpfiles.d/ COPY system/usr/share/pixmaps/seflos-logo.svg /usr/share/pixmaps/ COPY --from=plymouth-theme /sectorf /usr/share/plymouth/themes/sectorf diff --git a/linux/live/build.sh b/linux/live/build.sh @@ -9,8 +9,11 @@ # # linux/live/build.sh # -# The ISO lands in linux/out/iso/. PAYLOAD=<image ref in the VM's podman> adds that image to the -# ISO as the offline install payload (ADR-0010). +# The ISO lands in linux/out/iso/. PAYLOAD (default the development image, +# registry.example.com/sectorf-linux-dev:latest) is the image the ISO carries as the offline +# install payload (ADR-0010); the VM pulls it. TARGET_IMGREF is what installed machines follow +# (default the published sectorf-linux, as a real installer would; a test sets it to the payload). +# LIVE_DEBUG=1 lets root log in over SSH with the test rig's key. set -euo pipefail ROOT=$(cd "$(dirname "$0")/.." && pwd) @@ -22,7 +25,12 @@ say() { printf '==> %s\n' "$*"; } "$ROOT/greeter-build.sh" say "building the live image" -docker build -q --target live -t sectorf-live-installer -f "$ROOT/Containerfile" "$ROOT" >/dev/null +PAYLOAD=${PAYLOAD:-registry.example.com/sectorf-linux-dev:latest} +TARGET_IMGREF=${TARGET_IMGREF:-registry.example.com/sectorf-linux:latest} +debug_key="" +[[ -z "${LIVE_DEBUG:-}" ]] || debug_key=$(cat "$ROOT/out/id_ed25519.pub") +docker build -q --target live -t sectorf-live-installer -f "$ROOT/Containerfile" \ + --build-arg PAYLOAD_REF="$PAYLOAD" --build-arg TARGET_IMGREF="$TARGET_IMGREF" --build-arg DEBUG_SSH_KEY="$debug_key" "$ROOT" >/dev/null say "the build VM" pid="$ROOT/out/qemu.pid" @@ -42,6 +50,9 @@ if [[ -f "$pid" ]] && kill -0 "$(cat "$pid")" 2>/dev/null; then :; else "$VM" st say "sending the live image to the VM" docker save sectorf-live-installer | "$VM" ssh 'podman load -q >/dev/null && podman tag docker.io/library/sectorf-live-installer:latest localhost/sectorf-live-installer:latest' +say "pulling the payload $PAYLOAD into the VM" +"$VM" ssh "podman pull -q $PAYLOAD >/dev/null && df -h /var/builder | tail -1" + say "building the ISO (in the VM)" "$VM" ssh " rm -rf /var/builder/out/* @@ -51,7 +62,7 @@ say "building the ISO (in the VM)" -v /var/builder/out:/output $FEDORA sh -c ' dnf -y -q install image-builder podman >/dev/null 2>&1 image-builder build --output-dir /output --bootc-ref localhost/sectorf-live-installer \ - --bootc-default-fs btrfs ${PAYLOAD:+--bootc-installer-payload-ref $PAYLOAD} bootc-generic-iso' 2>&1 | tail -25 + --bootc-default-fs btrfs --bootc-installer-payload-ref $PAYLOAD bootc-generic-iso' 2>&1 | tail -25 find /var/builder/out -name '*.iso' -exec ls -lh {} \;" say "copying the ISO out" diff --git a/linux/live/try.sh b/linux/live/try.sh @@ -6,6 +6,8 @@ # linux/live/try.sh start boot it (in the background) # linux/live/try.sh screenshot save the screen to out/iso/screen.png # linux/live/try.sh type 'text' type into it (\t Tab, \n Enter) +# linux/live/try.sh ssh [cmd] root over SSH (a LIVE_DEBUG=1 ISO only), localhost:2223 +# linux/live/try.sh disk [a|b] boot an installed drive on its own, without the ISO # linux/live/try.sh stop power it off # linux/live/try.sh reset also delete the blank drives set -euo pipefail @@ -24,14 +26,14 @@ case "${1:-}" in for d in a b; do [[ -f "$OUT/drive-$d.qcow2" ]] || qemu-img create -q -f qcow2 "$OUT/drive-$d.qcow2" 16G; done cp -n /usr/share/OVMF/OVMF_VARS_4M.fd "$VARS" rm -f "$MON" - qemu-system-x86_64 -enable-kvm -cpu host -m 3072 -smp 2 -machine q35 \ + qemu-system-x86_64 -enable-kvm -cpu host -m 4096 -smp 2 -machine q35 \ -drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.fd \ -drive if=pflash,format=raw,file="$VARS" \ -drive file="$ISO",media=cdrom,readonly=on \ -drive file="$OUT/drive-a.qcow2",if=none,id=a -device virtio-blk-pci,drive=a,serial=DRIVE-A \ -drive file="$OUT/drive-b.qcow2",if=none,id=b -device virtio-blk-pci,drive=b,serial=DRIVE-B \ -device virtio-vga -vnc 127.0.0.1:2 -monitor "unix:$MON,server,nowait" \ - -netdev user,id=n0 -device virtio-net-pci,netdev=n0 \ + -netdev user,id=n0,hostfwd=tcp:127.0.0.1:2223-:22 -device virtio-net-pci,netdev=n0 \ -daemonize -pidfile "$PID" echo "booting: VNC localhost:5902; $0 screenshot" ;; @@ -56,9 +58,25 @@ for ch in sys.argv[1].encode().decode("unicode_escape"): except Exception: pass PY ;; + ssh) + shift; exec ssh -i "$ROOT/out/id_ed25519" -p 2223 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR root@127.0.0.1 "$@" ;; + disk) + running && { echo "already running"; exit 0; } + d=${2:-a} + cp -n /usr/share/OVMF/OVMF_VARS_4M.fd "$OUT/OVMF_VARS_disk.fd" 2>/dev/null || true + rm -f "$MON" + qemu-system-x86_64 -enable-kvm -cpu host -m 4096 -smp 2 -machine q35 \ + -drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.fd \ + -drive if=pflash,format=raw,file="$OUT/OVMF_VARS_disk.fd" \ + -drive file="$OUT/drive-$d.qcow2",if=none,id=a -device virtio-blk-pci,drive=a,serial=DRIVE-A \ + -device virtio-vga -vnc 127.0.0.1:2 -monitor "unix:$MON,server,nowait" \ + -netdev user,id=n0,hostfwd=tcp:127.0.0.1:2223-:22 -device virtio-net-pci,netdev=n0 \ + -daemonize -pidfile "$PID" + echo "booting drive $d alone: VNC localhost:5902" + ;; stop) running && kill "$(cat "$PID")"; rm -f "$PID" ;; reset) - "$0" stop; rm -f "$OUT"/drive-*.qcow2 "$OUT/OVMF_VARS.fd" ;; - *) sed -n 2,11p "$0" | sed 's/^# \{0,1\}//'; exit 2 ;; + "$0" stop; rm -f "$OUT"/drive-*.qcow2 "$OUT"/OVMF_VARS*.fd ;; + *) sed -n 2,13p "$0" | sed 's/^# \{0,1\}//'; exit 2 ;; esac diff --git a/linux/live/usr/libexec/patina-install b/linux/live/usr/libexec/patina-install @@ -0,0 +1,74 @@ +#!/usr/bin/bash +# Installs Sector F Linux onto a whole drive, from the payload on the live disc (ADR-0014, ADR-0011): +# +# patina-install /dev/vda +# +# Run as root, through pkexec (the polkit rule lets the installer's user do that on the live disc, +# and only there). The installer app calls it after the person has chosen the drive and confirmed. +# +# It refuses anything but a whole, unmounted, writable disk that is not the one the live system +# booted from, and wipes it: the picker in the app is the first line of defence, this is the second, +# since a bug in an app must not be able to erase the wrong drive. +# +# Progress goes to stdout as lines "STEP <n>/<total> <what>", then bootc's own output. +set -euo pipefail + +die() { echo "patina-install: $*" >&2; exit 1; } + +drive=${1:-} +[[ -n "$drive" ]] || die "usage: patina-install /dev/<drive>" +[[ $EUID -eq 0 ]] || die "must run as root (through pkexec)" +[[ -b "$drive" ]] || die "$drive is not a block device" +drive=$(readlink -f "$drive") + +[[ "$(lsblk -dno TYPE "$drive")" == disk ]] || die "$drive is not a whole disk" +[[ "$(lsblk -dno RO "$drive")" == 0 ]] || die "$drive is read-only" +size=$(lsblk -bdno SIZE "$drive") +(( size >= 12 * 1024**3 )) || die "$drive is smaller than 12 GB" + +# Not the drive the live system booted from (the ISO's drive, or the USB stick it was written to). +live=$(findmnt -no SOURCE /run/initramfs/live 2>/dev/null || true) +if [[ -n "$live" ]]; then + live_disk=$(lsblk -no PKNAME "$live" 2>/dev/null | head -1) + [[ -z "$live_disk" ]] && live_disk=$(basename "$live") + [[ "$(basename "$drive")" != "$live_disk" ]] || die "$drive is the drive this system booted from" +fi + +# Nothing on it may be in use. +if lsblk -nro MOUNTPOINTS "$drive" | grep -q .; then die "$drive has mounted partitions"; fi + +payload=$(cat /usr/lib/patina-install/payload) +target=$(cat /usr/lib/patina-install/target) +[[ -n "$payload" && -n "$target" ]] || die "this disc has no payload" +podman image exists "$payload" || die "the payload $payload is not on this disc" + +# bootc unpacks the image into scratch space, and the live system's disk is RAM. It reads the payload +# through a helper that runs in the live system's own mount namespace, so the scratch that fills is +# the live system's /var/tmp (a bind mount into the container does not reach it): a tmpfs is +# mounted there, of 70% of the RAM (it takes memory only as it is used). It must hold the largest +# layer with room to spare; better to say so now than to fail half way through, with the drive +# already wiped. (podman prints sizes as 797kB, 1.53GB, ...: converted to bytes.) +largest=$(podman history --format '{{.Size}}' "$payload" | + awk '{ v = $1 + 0; u = $1; sub(/^[0-9.]+/, "", u); + m = (u == "GB") ? 1e9 : (u == "MB") ? 1e6 : (u == "kB") ? 1e3 : 1; printf "%d\n", v * m }' | + sort -n | tail -1) +[[ -n "$largest" ]] || die "cannot read the payload's layer sizes" +scratch_mb=$(( $(awk '/^MemTotal:/ { print $2 }' /proc/meminfo) * 7 / 10 / 1024 )) +need=$(( largest * 5 / 4 )) +if (( scratch_mb * 1024 * 1024 < need )); then + die "not enough memory to install: needs $(( need / 1024**2 )) MB of scratch space, can have $scratch_mb MB (this computer needs more RAM)" +fi +mount -t tmpfs -o size="${scratch_mb}m" tmpfs /var/tmp +trap 'umount /var/tmp' EXIT + +echo "STEP 1/2 Writing the system to $drive" +# bootc runs from inside the image it installs, as its docs have it: the host's /dev, and the +# payload from the live system's container storage. +podman run --rm --privileged --pid=host --network none \ + -v /dev:/dev -v /var/lib/containers:/var/lib/containers \ + "$payload" \ + bootc install to-disk --wipe --filesystem btrfs \ + --source-imgref "containers-storage:$payload" --target-imgref "$target" \ + "$drive" + +echo "STEP 2/2 Done" diff --git a/linux/live/usr/share/polkit-1/actions/com.sectorflabs.patina.install.policy b/linux/live/usr/share/polkit-1/actions/com.sectorflabs.patina.install.policy @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE policyconfig PUBLIC "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN" + "http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd"> +<policyconfig> + <action id="com.sectorflabs.patina.install"> + <description>Install Sector F Linux onto a drive</description> + <message>Authentication is required to erase a drive and install Sector F Linux</message> + <defaults> + <allow_any>no</allow_any> + <allow_inactive>no</allow_inactive> + <allow_active>auth_admin</allow_active> + </defaults> + <annotate key="org.freedesktop.policykit.exec.path">/usr/libexec/patina-install</annotate> + </action> +</policyconfig> diff --git a/linux/live/usr/share/polkit-1/rules.d/50-patina-install.rules b/linux/live/usr/share/polkit-1/rules.d/50-patina-install.rules @@ -0,0 +1,9 @@ +// On the live disc (this file is in the live image only, never the installed system), the installer +// runs as the greeter user, and may run patina-install, which erases a drive and installs. Nothing +// else may, and nobody on an installed system: the policy's default there is an administrator's +// password, and the action does not exist. +polkit.addRule(function(action, subject) { + if (action.id === "com.sectorflabs.patina.install" && subject.user === "greetd") { + return polkit.Result.YES; + } +});