sector-f-linux

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

0008-install-by-receiving-the-system-as-a-zfs-stream.md (3984B)


      1 # 0008. Install by receiving the system as a ZFS stream, onto the whole disk
      2 
      3 Date: 2026-10-22
      4 
      5 ## Status
      6 
      7 Superseded by [ADR-0009](0009-seflos-a-fedora-bootc-image-on-btrfs.md): with no ZFS, the install is `bootc install to-disk` onto Btrfs. An installer image for other people is still to do.
      8 
      9 Before that: Proposed
     10 
     11 ## Context
     12 
     13 Patina OS is Ubuntu on a ZFS root (ADR-0007), so it needs an installer: Ubuntu's own doesn't make our pool, datasets and ZFSBootMenu, and the pool layout is ours.
     14 
     15 A Raspberry Pi is installed by writing an image to the SD card and growing it on first boot. Raspberry Pi OS, Armbian, ChromeOS and Steam Deck recovery, Apple's restores and Windows OEM images all work this way: every machine starts from the exact build that was tested, and installing takes minutes, not a package-by-package install. Desktop distros mostly don't, for three reasons:
     16 
     17 - **They share the disk**: dual boot, keeping an old `/home`, custom partitions. An image that takes the whole disk rules those out.
     18 - **Some things must differ per machine**: machine-id, SSH host keys, the ZFS host ID and pool GUID, and above all encryption keys. A cloned encrypted image gives every machine the same master key, and ZFS's `zfs change-key` changes only the key wrapping it, not the key itself.
     19 - **Something has to boot first to write the disk**, which on a laptop means a USB stick, an installer of sorts anyway.
     20 
     21 ZFS removes the second problem: rather than copy a disk image block for block, the system can be sent as a stream into a pool made on the machine. And an opinionated OS that owns the whole disk, as a Mac or a Chromebook does, doesn't have the first.
     22 
     23 ## Decision
     24 
     25 - **The system is built once, in CI**, from a recipe (the Containerfile, without bootc, or a debootstrap script) into a dataset, and kept as a ZFS stream: the image.
     26 - **The USB stick is Patina OS itself**, booting from that same system, so it can be tried before installing. It carries the stream.
     27 - **Installing takes the whole disk**, and says so. The installer:
     28   1. partitions the target: the ESP, a swap partition (ADR-0007: no swap on ZFS), and the rest for the pool;
     29   2. makes a **new pool** on the disk's stable name (`/dev/disk/by-id/...`) with `zgenhostid` and the layout of ADR-0007, so the pool GUID and host ID are this machine's, and the pool is the disk's full size, with nothing to grow;
     30   3. sets up **encryption on the machine**, if chosen, so its keys exist nowhere else;
     31   4. receives the system: `zfs send | zfs receive` into `patina/ROOT/default`;
     32   5. installs ZFSBootMenu on the ESP and sets the pool's `bootfs`;
     33   6. creates the first user, and their dataset `patina/home/<user>`.
     34 - **First boot makes what's per machine**: machine-id, SSH host keys, the hostname.
     35 - **From there it's ADR-0007**: apt, with a snapshot before every run. The machine starts from a known build; it isn't kept as one.
     36 
     37 ## Consequences
     38 
     39 - Installing is a few minutes of copying, the same on every machine, with no packages fetched or configured during it.
     40 - Every machine starts from exactly the build that was tested. A broken install is a broken build, found in CI, not on someone's laptop.
     41 - No duplicated pool GUIDs, host IDs or encryption keys between machines.
     42 - No dual boot, and no installing beside another OS. Patina OS is the whole disk.
     43 - The installer is ours to write and keep: a script first, a small Patina UI over it later. It's short, since the hard parts (packages, configuration) are done at build time.
     44 - The stream and the build recipe are the same pieces ADR-0006 would update with, should that stage come: installing becomes the first receive, and an update another.
     45 - Reinstalling or recovering is the same steps, and keeping a user's data through a reinstall is possible later: receive a new `patina/ROOT/default` and leave `patina/home` alone.
     46 - The CI build needs ZFS and a way to write a dataset (a VM or a machine with a pool), and the USB stick image needs building too.