0007-ubuntu-without-snaps-on-a-zfs-root.md (8520B)
1 # 0007. Ubuntu without snaps, on a ZFS root, snapshotted before every apt run 2 3 Date: 2026-10-22 4 5 ## Status 6 7 Superseded by [ADR-0009](0009-seflos-a-fedora-bootc-image-on-btrfs.md): the system is a Fedora bootc image on Btrfs, updated as an image. 8 9 Before that: Accepted. Defers ADR-0006 to a later stage; supersedes ADR-0001. 10 11 ## Context 12 13 ADR-0006 settled on boot environments shipped as ZFS streams, on FreeBSD or Ubuntu, with the system read-only and the user's software somewhere else. Working out the "somewhere else" kept adding parts: a jail or pkgsrc for command-line tools, our own build of packages, wrappers to run them, an updater, a way to keep `/etc`. FreeBSD made most of that simplest, but not the hardware: graphics, Wi-Fi and sleep on laptops trail Linux, and the workstation the Patina desktop is used on every day needs Ubuntu for CUDA. 14 15 Plain Ubuntu, kept from snaps, answers what matters most in practice: 16 17 - One OS on the laptop and the workstation, with Ubuntu's support for lids, batteries, suspend, NVIDIA and CUDA. 18 - Debian's packages: the software people expect, installed the way they expect, for every user on the machine. 19 - Ubuntu's LTS releases are stable; 26.04 is supported to April 2031. 20 21 It gives up the system as one locked unit, built and shipped whole and kept apart from what the user installs. Most of what that was for (a bad upgrade never leaves the machine broken) a ZFS root gives back: snapshot before every apt run, boot the snapshot if the upgrade breaks something. 22 23 ## Decision 24 25 - **Patina OS is Ubuntu LTS (26.04) with the Patina desktop**, installed from Ubuntu's archive with apt. No from-scratch distro, no image pipeline for now. 26 - **No snaps.** `snapd` is pinned so apt never installs it (as Linux Mint's `nosnap.pref` does). What Ubuntu ships only as a snap comes from elsewhere: Firefox and Thunderbird from Mozilla's apt repository, Chromium as a Flatpak or Google Chrome's `.deb`. 27 - **The root is on ZFS**, in the pool laid out as before: `patina/ROOT/<name>` for the system, `patina/home/<user>` for each user, so rolling the system back never touches anyone's data. 28 - **Every apt run is snapshotted first**, by an apt hook (`DPkg::Pre-Invoke`), and old snapshots are pruned. ZFSBootMenu, on the ESP, boots the system or any of its snapshots, so a broken upgrade is undone at the next boot. 29 - **Swap is its own partition**, not a ZFS volume (swap on a zvol can deadlock under memory pressure, and can't take a hibernation image). 30 - **Suspend, not hibernate.** Checked 2026-10-22: hibernation with ZFS is possible but not safe enough to ship. OpenZFS's freeze before hibernating is known to let a little I/O through after the memory image is taken, so the disk ends up ahead of what the resumed kernel believes, which can corrupt a pool (OpenZFS issue 12842); this holds wherever swap is. NixOS turns hibernation off whenever ZFS is in use (`nohibernate`), behind an option named `unsafeAllowHibernation`. Swap on a zvol deadlocks instead. ZFSBootMenu adds its own problem: it starts the kernel with kexec, and kernels from 6.8 fail to resume from hibernation when kexec-booted (a regression reported in March 2025). People do run it, for example Kubuntu on ZFS with LUKS-encrypted swap on a Framework laptop, booted by GRUB with Secure Boot off; and Ubuntu's kernel refuses to hibernate under Secure Boot's lockdown whatever the filesystem. So the machine suspends; hibernation can be reconsidered if OpenZFS fixes the freeze and kexec resume works. 31 - **Nothing is lost by this: Ubuntu doesn't hibernate by default either.** A default install has no `resume=` target and a swap file smaller than RAM, and logind reports that it can't hibernate. Checked on nifl (a ThinkPad X1 Carbon Gen 9, Ubuntu 26.04 as installed, ext4 on LVM, no ZFS, Secure Boot off): `CanHibernate` is `no`, swap is a 4 GB file against 14 GB of RAM, and it has never hibernated. Hibernating on stock Ubuntu is something a user sets up by hand; with a ZFS root it's the one thing they can't safely set up. 32 - **Suspend is the firmware's default, modern standby (s2idle)**, not S3 where the firmware offers it. It wakes at once, which matters more than the drain for a laptop opened and closed through the day; what matters then is that it reaches its deepest state (S0ix). nifl manages that for only about 7% of the time it's suspended, losing about 0.8% of its battery an hour; finding what keeps it awake, and making that a default, is the work. 33 - **ZFS's cache is capped** at a quarter of RAM by default (`zfs_arc_max`), since on Linux it gives memory back to programs more slowly than the kernel's own cache does. **Dedup is never on by default**: its table lives in RAM (602 MB for 1.18x on the workstation's `tank/Src`), which ZFS otherwise doesn't need much of. 34 - **doas, not sudo, for admin work** (`opendoas`, in universe; nifl uses it today). Its whole configuration is a line or two in `/etc/doas.conf` (`permit persist :sudo`, so the admin group is the same one Ubuntu's installer uses), against sudo's policy language, and it's what OpenBSD and many FreeBSD users use. sudo-rs (Ubuntu's sudo since 25.10) stays installed for scripts and installers that call `sudo` by name; whether to drop it, or make `sudo` a small shim that runs doas, is open. Polkit (pkexec, the desktop's password prompts) is separate and unaffected. *(Check that Ubuntu's opendoas build supports `persist`.)* 35 - **Ubuntu's own kernels only**, which come with the ZFS module built for them. 36 - **Apps**: apt and Flatpak for most software; `~/Apps` folders (ADR-0002, ADR-0004, ADR-0005) stay as the simplest way, for people who want to copy an app in and delete it to remove it. 37 38 ## Considered: an ext4 root with ZFS only for data 39 40 The workstation is set up this way: Ubuntu on ext4 on the NVMe drive, and a ZFS pool on other disks for the data that matters (`~/Src`, photographs, games, backups). It was weighed against a ZFS root: 41 42 | | ext4 root + ZFS for data | Root on ZFS | 43 |---|---|---| 44 | Always boots | Yes: ZFS isn't needed to boot; if its module breaks only the pool is lost | ZFS is in the boot path (low risk: Ubuntu builds the module with each kernel) | 45 | Undo a bad apt upgrade | No (only with a btrfs root and its snapshots) | Yes: snapshot first, boot it from ZFSBootMenu | 46 | Hibernation | Possible (with ZFS's pools imported, still exposed to its freeze bug) | No (above) | 47 | Installer | Ubuntu's own | Ours | 48 | Install from a ZFS stream (ADR-0008) | No (a Pi-style ext4 image, written and grown, would do for the root) | Yes | 49 | One-disk laptop | Two partitions, the root's size guessed | One pool, nothing to size | 50 | RAM | Two caches compete, ext4's and ZFS's | One cache, ZFS's | 51 52 RAM isn't the difference it's often taken to be: ZFS runs well in a few GB, the pool's cache is shared either way, and what costs RAM is dedup, not a ZFS root. The ext4 root is the sturdier choice for a workstation with several drives. For Patina OS, on one-disk laptops, it's the ZFS root: undoing a bad upgrade is what ADR-0007 relies on in place of images, and installing from a stream needs it. 53 54 ## Consequences 55 56 - Little to build: an install script (partitions, pool, datasets, ZFSBootMenu, the no-snaps pin, the apt hook, the desktop), and the Patina desktop as `.deb` packages, ideally from our own apt repository. 57 - Usable now, on both the laptop and the workstation, CUDA included. 58 - The line between the system's software and the user's is Ubuntu's usual one: both live in `/usr`, installed with apt. Snapshots make upgrades safe to undo, but each machine's system is its own, assembled package by package, not a build we tested. 59 - An apt run that fails halfway leaves the running system half upgraded until it's fixed or rolled back; with an image it would never have been touched. 60 - ADR-0006 stays possible as a later stage: the pool and the boot loader are the same, so moving to built boot environments changes only how `patina/ROOT` is filled. 61 - No hibernation on laptops (above); suspend only, as on a default Ubuntu install. A laptop left closed for days drains its battery (about 18% a day on nifl today), so how deeply it suspends matters. 62 - ZFS as the root means the system can't boot without the CDDL module Canonical ships with its GPL kernel; a product sold on it inherits that question (docs/comparison.md). 63 - ZFSBootMenu is a third-party project, and Ubuntu's own installer isn't used. 64 - The FreeBSD work (freebsd/) and the bootc VM (linux/vm/) stay as the record of what was tried.