sector-f-linux

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

commit 02c0424c1edb9075f2a6e034ad0fd04d544b010a
parent ba75ada2942870f1b424c43a300fc8eda6665cac
Author: Divan Visagie <me@divanv.com>
Date:   Fri, 16 Oct 2026 01:34:15 +0200

/home on ZFS: the image has the tools and imports pools at boot; vm/zfs-home.sh makes one

The module comes with Ubuntu's kernel; the image adds zfsutils-linux and
zfs-zed, enables the import and mount services, and holds no host ID or
pool cache, which belong to each machine. vm/zfs-home.sh stands in for
the installer: a host ID, the pool 'patina' on the data disk's stable
ID, patina/home at /var/home and a dataset per user, the existing homes
moved in. Checked in the VM: it comes back at boot, the desktop runs on
it, and a file there survives an upgrade and a rollback.

docs/notes.md starts the list of what the installer will do.

Diffstat:
MContainerfile | 14++++++++++++--
Mdocs/notes.md | 39+++++++++++++++++++++++++++++++--------
Mvm/README.md | 6+++++-
Mvm/common.sh | 3++-
Mvm/vm.sh | 3++-
Avm/zfs-home.sh | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 113 insertions(+), 13 deletions(-)

diff --git a/Containerfile b/Containerfile @@ -26,6 +26,12 @@ COPY --from=dpkg-state /var/lib/dpkg /var/lib/dpkg # PipeWire and WirePlumber (wpctl, for the volume keys), Mesa (EGL, GBM), # libinput, libseat, xkb's layouts, fonts, and foot as a terminal. The # libraries are what the binaries link or load (see desktop/build.sh). +# +# And ZFS's tools, for the pool /home lives on (ADR-0001); the module comes +# with Ubuntu's kernel. A pool belongs to its machine, so the image holds +# none, nor a host ID (zfsutils makes one as it installs, which every machine +# would then share) or a pool cache: the installer makes those +# (vm/zfs-home.sh stands in for it). RUN mkdir -p /var/cache/apt/archives/partial /var/lib/apt/lists/partial /var/log/apt \ /var/tmp /var/roothome && \ apt-get update && \ @@ -44,7 +50,9 @@ RUN mkdir -p /var/cache/apt/archives/partial /var/lib/apt/lists/partial /var/log libwayland-server0 libwayland-client0 libwayland-egl1 \ libinput10 libseat1 libxkbcommon0 xkb-data libpixman-1-0 libdrm2 \ fonts-dejavu-core fonts-ubuntu hicolor-icon-theme adwaita-icon-theme \ - xdg-user-dirs foot && \ + xdg-user-dirs foot \ + zfsutils-linux zfs-zed && \ + rm -f /etc/hostid /etc/zfs/zpool.cache && \ apt-get clean && \ rm -rf /var && mkdir /var @@ -54,7 +62,9 @@ COPY system/ / # The Patina desktop, and "Patina" as GDM's session. COPY build/desktop/ / -RUN systemctl enable gdm.service NetworkManager.service && \ +RUN systemctl enable gdm.service NetworkManager.service \ + zfs-import-cache.service zfs-mount.service zfs-zed.service \ + zfs-import.target zfs.target && \ systemctl set-default graphical.target RUN bootc container lint diff --git a/docs/notes.md b/docs/notes.md @@ -30,14 +30,37 @@ Research for Patina OS, and what's still open. Dated, since this moves quickly. ## ZFS -- Ubuntu ships the OpenZFS module built for its kernels (`zfs.ko` in linux-modules), and - zfsutils-linux. In the image: install zfsutils-linux, and make sure the module matches the - image's kernel (it should, if both come from Ubuntu's archive). -- The pool is for data: `/home` at least. Created once per machine, not by the image. -- Open: importing the pool at boot (zfs-import-cache or zfs-import-scan, and the cache file in - `/etc/zfs`, which bootc keeps), mounting `/home` from it, and native encryption: unlocking with - a passphrase at boot (an initramfs prompt, or a systemd unit before the display manager). -- Open: whether `/var` (containers, flatpaks, logs) also goes on the pool. +- **Done 2026-10-16**, in the VM: /home on a ZFS pool, imported and mounted at boot, through + upgrades and rollbacks. The module comes with Ubuntu's kernel package + (`ubuntu/dkms/zfs/zfs.ko.zst`, built for it); the image adds zfsutils-linux and zfs-zed and + enables zfs-import-cache, zfs-mount and zed. +- **The layout**: a pool `patina` (ashift=12, zstd, atime off, xattr=sa, POSIX ACLs, not + mounted itself); `patina/home` at `/var/home` (/home links there on bootc); one dataset per + user, `patina/home/<user>`, so each home snapshots and sends alone. +- **Machine, not image**: the host ID (`/etc/hostid`; zfsutils makes one as it installs, so the + image deletes it) and the pool cache (`/etc/zfs/zpool.cache`) are in `/etc`, which bootc + keeps per machine across updates; the pool is outside the image. vm/zfs-home.sh does the + per-machine part, standing in for the installer. +- **Mounting order**: zfs-mount runs before local-fs.target, so the homes are there before + tmpfiles, GDM or any login. +- Open: a dataset for each *new* user. useradd makes a plain folder inside `patina/home`; + whatever creates users (the installer, a settings app) should `zfs create` first. +- Open: native encryption, unlocked with the login password or at boot (an initramfs prompt, or + a unit before GDM). +- Open: whether more of `/var` (containers, flatpaks, logs) goes on the pool. + +## What the installer will do + +The Patina installer (our own; no existing one fits) is where a machine's own setup lives, so +nothing in the image may assume it. Collected as they come up: + +- Partition: EFI, the system partition for bootc, and the rest for the ZFS pool (or a second + disk). `bootc install to-disk` takes a whole disk, so the installer partitions itself and + uses `bootc install to-filesystem` (vm/disk.sh uses to-disk, with the pool on a second disk). +- `bootc install` with `--target-imgref` set to where this machine updates from. +- ZFS: `zgenhostid`, `zpool create` on a stable name (`/dev/disk/by-id/...`), the cache file, + `patina/home` and the first user's dataset, as vm/zfs-home.sh does. +- The first user: the real image has none (the dev stage's `patina` is for the VM). ## Apps in the home folder diff --git a/vm/README.md b/vm/README.md @@ -10,6 +10,7 @@ vm/disk.sh install the image onto out/disk.raw (and make out/data.qcow 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/zfs-home.sh put /home on a ZFS pool on the second disk, as the installer will (once) vm/vm.sh console boot it on this terminal instead (Ctrl-a x quits) vm/vm.sh view its screen in a VNC viewer (localhost:5901) vm/vm.sh screenshot its screen, saved to out/screen.png @@ -49,7 +50,7 @@ vm/vm.sh ssh bootc rollback # the previous one, at the next boot - **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`), SSH on localhost:2222 with the key in `out/id_ed25519`, a virtio GPU shown over VNC + (`/dev/disk/by-id/virtio-patina-data`, whichever `vdX` it gets), SSH on localhost:2222 with the key in `out/id_ed25519`, a virtio GPU shown over VNC (Mesa draws in software), a USB tablet and keyboard, and QEMU's monitor on `out/monitor.sock` (screenshots, and `sendkey` to type into it). @@ -67,5 +68,8 @@ vm/vm.sh ssh bootc rollback # the previous one, at the next boot session"). `system/etc/accountsservice/user-templates` makes it Patina. - Ubuntu's NetworkManager leaves wired interfaces to netplan, which isn't here; an empty `10-globally-managed-devices.conf` in `/etc` lets it manage them. +- The disks swap names between boots (the data disk was `vda` one time, `vdb` another), so the + pool is made on the data disk's serial (`/dev/disk/by-id/virtio-patina-data`); the system + disk is found by its UUID in the boot entry. - Docker here has only the legacy builder (no BuildKit), so the Containerfile uses `COPY --from` rather than `RUN --mount`. diff --git a/vm/common.sh b/vm/common.sh @@ -13,7 +13,8 @@ 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). +# A second, empty disk for the ZFS pool for /home (ADR-0001), which the VM sees +# as /dev/disk/by-id/virtio-patina-data. DATA="$OUT/data.qcow2" DATA_SIZE=10G KEY="$OUT/id_ed25519" diff --git a/vm/vm.sh b/vm/vm.sh @@ -20,7 +20,8 @@ qemu_args() { -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" \ + -drive "file=$DATA,format=qcow2,if=none,id=data" \ + -device virtio-blk-pci,drive=data,serial=patina-data \ -nic "user,model=virtio-net-pci,hostfwd=tcp:127.0.0.1:$SSH_PORT-:22" \ -device virtio-vga -vnc "127.0.0.1:$VNC_DISPLAY" \ -device qemu-xhci -device usb-tablet -device usb-kbd \ diff --git a/vm/zfs-home.sh b/vm/zfs-home.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +# Puts /home on ZFS in the running VM, as the Patina installer will on a real +# machine (ADR-0001); this stands in for it until there is one. On the VM's +# second disk: +# +# - a host ID for the machine (/etc/hostid), which the pool is tied to; +# - the pool, "patina", recorded in /etc/zfs/zpool.cache so it's imported at +# boot (the image enables zfs-import-cache and zfs-mount); +# - patina/home, mounted at /var/home (/home links there on a bootc system), +# and a dataset of its own for each user's home, so each can be +# snapshotted and sent alone. The homes there already are moved in. +# +# Both files are in /etc, which belongs to the machine and survives updates and +# rollbacks; the pool is outside the image entirely. Run it once; a second run +# does nothing. +source "$(dirname "$0")/common.sh" + +vm_running || die "not running; vm/vm.sh start" +vm_ssh bash -s <<'EOF' +set -euo pipefail +pool=patina +disk=/dev/disk/by-id/virtio-patina-data + +if zpool list "$pool" >/dev/null 2>&1; then + echo "the pool is there already:" + zfs list -r "$pool" + exit 0 +fi + +[ -s /etc/hostid ] || zgenhostid + +# 4K sectors whatever the disk says; zstd; no access times; extended +# attributes and ACLs as Linux keeps them; the pool itself isn't mounted. +zpool create -f -o ashift=12 -o cachefile=/etc/zfs/zpool.cache \ + -O compression=zstd -O atime=off -O xattr=sa -O acltype=posixacl \ + -O dnodesize=auto -O normalization=formD \ + -O mountpoint=none -O canmount=off \ + "$pool" "$disk" + +# Nobody may be using /var/home while it moves. +systemctl stop gdm.service +mv /var/home /var/home.old +mkdir /var/home +zfs create -o mountpoint=/var/home "$pool/home" +for old in /var/home.old/*; do + [ -d "$old" ] || continue + user=${old##*/} + zfs create "$pool/home/$user" + cp -a "$old/." "/var/home/$user/" + chown --reference="$old" "/var/home/$user" + chmod --reference="$old" "/var/home/$user" +done +rm -rf /var/home.old + +zfs list -r "$pool" +EOF +say "rebooting, to check the pool comes back by itself" +vm_ssh systemctl reboot || true +sleep 5 +"$ROOT/vm/vm.sh" wait +vm_ssh 'findmnt -t zfs -o TARGET,SOURCE; zpool status -x'