30.1. Planning and Installing ZFS on Debian
ZFS is not an add-on filesystem that sits on top of an existing partition scheme in the way ext4 or XFS does. It expects to own the block devices that form its vdevs, and it manages redundancy, checksums, and allocation itself. That difference shapes both the installation plan and the recovery plan.
30.1.1. Pools, Vdevs, Datasets, and Zvols
A pool is the unit of space allocation and health. It is built from one or more virtual devices (vdevs). A vdev can be a single disk, a mirror of two or more disks, or a RAIDZ group of disks. The pool stripes data across its top-level vdevs; losing a top-level vdev loses the pool, so redundancy is configured inside each vdev, not across the pool as a whole. A pool made of two mirrors is not equivalent to a four-disk RAIDZ2: the failure domain is one mirror, not the whole set.
Inside a pool, ZFS creates datasets. A filesystem dataset behaves like a
POSIX filesystem with a mountpoint, but it also has properties, snapshots,
clones, quotas, and optional encryption. Datasets form a hierarchy: tank/data
can have a child tank/data/docs, and a property set on the parent is inherited
by children unless a child overrides it. A zvol is a dataset that exposes a
block device under /dev/zvol/<pool>/<name> instead of a mountable filesystem.
Virtual machines, iSCSI targets, and filesystem layers such as LUKS can consume
a zvol as a disk.
Figure 30.2. Conceptual ZFS object model. Whole disks or partitions form vdevs, vdevs form a pool, and datasets and zvols consume pool space. A dataset is not a partition: its size is bounded by quotas and pool free space, not a fixed slice of the disk.
ZFS is a copy-on-write design. New data is written to free blocks, checksummed, and then linked into the tree; the old blocks remain readable until the snapshot or transaction that references them is released. This is why snapshots are nearly free at creation and why deleting a file does not immediately free space if a snapshot still references its blocks. The adaptive replacement cache (ARC) caches data and metadata in memory, and the ZFS Intent Log (ZIL) records synchronous writes so that a crash does not lose acknowledged data.
The choice between ZFS and the filesystems covered earlier in this book is a design decision, not a ranking:
| Property | ZFS | ext4 | XFS | Btrfs | LVM + md RAID |
|---|---|---|---|---|---|
| Volume management | Built into the pool | Needs partitions or LVM | Needs partitions or LVM | Built in, with profiles | LVM and md provide it |
| Data checksums and repair | Per-block checksums; repaired from redundant vdevs | No data checksums | Metadata checksums only | Per-block checksums; repair depends on profile | md scrub can repair mirrors/parity; no end-to-end data checksums |
| Snapshots and clones | Native, cheap, writable clones | None | None | Native | LVM snapshots, not filesystem-aware |
| Send and receive | Native full/incremental streams | External tools | External tools | Native btrfs send |
External tools |
| Native encryption | Dataset-level, key loaded separately | Not native; use LUKS | Not native; use LUKS | Not native; use LUKS | LUKS below LVM |
| Growth | Add vdevs, replace disks, expand RAIDZ | Grow online; shrink offline | Grow only | Add/remove devices, grow or shrink | Add PVs, grow or shrink LVs |
| Typical fit | Large pools, file servers, VM images, integrity-sensitive data | General-purpose Linux root and data | Large files and parallel I/O | Filesystems needing snapshots on one host | Flexible block layout with conventional filesystems |
Device discovery and persistent naming are covered in Chapter 11; filesystem alternatives in Chapter 12; and LVM, md RAID, and LUKS in Chapter 13. ZFS is not a universal replacement for LVM. LVM is a better fit when you need flexible block devices for many filesystems, online resizing, or interoperability with tools that expect ordinary block devices. ZFS is a better fit when you want the filesystem and redundancy layer to verify data, snapshot consistently, and replicate without external volume management. Do not layer ZFS on top of LVM or md RAID in a new design: it hides the devices ZFS needs to manage and adds a second redundancy layer that complicates recovery. Put LUKS below ZFS only when you need whole-device encryption that ZFS itself cannot provide, and accept that ZFS will see the mapper devices rather than the physical disks.
A dataset hierarchy is also an administrative boundary. Put independent workloads in separate datasets so that quotas, compression, recordsize, snapshots, and encryption can differ. A common layout is:
| Dataset | Purpose | Examples of local properties |
|---|---|---|
tank/data |
Shared parent and policy holder | compression=lz4, atime=off |
tank/data/docs |
Large sequential documents | recordsize=1M |
tank/vm |
Parent for virtual-machine zvols | recordsize=64K, compression=off for already-compressed images |
tank/secure |
Encrypted data | encryption=on, keylocation=file://... |
tank/backup |
Replication target | atime=off, readonly=on after validation |
Do not create one dataset per file or one pool per application unless the workload actually needs separate policy. Each dataset has small metadata and snapshot bookkeeping costs, and deeply nested hierarchies become hard to reason about during recovery.
30.1.2. Debian Archive Components, Packages, and Kernel Module Builds
OpenZFS userspace and kernel module packages are in Debian contrib, not
main (Chapter 6 covers archive components and
backports). If a system was installed with only main, add contrib to the
appropriate deb lines in /etc/apt/sources.list or to the Deb822 source
files under /etc/apt/sources.list.d/, then refresh the package indexes.
On a Debian 13 system the relevant source line commonly looks like:
deb https://deb.debian.org/debian trixie main contrib
deb https://deb.debian.org/debian trixie-updates main contrib
The security archive normally carries main; ZFS packages come from
trixie/contrib. Keeping contrib on the main and updates lines is enough for
the packages used here. After editing, run apt update. The package set is small:
| Package | Role |
|---|---|
zfsutils-linux |
zpool, zfs, zdb, zgenhostid, and the userspace libraries |
zfs-dkms |
OpenZFS source and DKMS hooks that build the kernel module for each installed kernel |
zfs-zed |
ZFS Event Daemon, which consumes zpool events and can run scripts for health events |
zfs-initramfs |
Initramfs integration for importing and mounting a ZFS root; not needed for data-only pools |
linux-headers-amd64 |
Headers for the running kernel, required by DKMS |
Install the data-pool packages with the ordinary interactive package manager:
# apt install zfsutils-linux zfs-dkms zfs-zed
On a normal terminal apt prints the packages it will install, their sizes, and
a confirmation prompt; answer it yourself. The command above does not select
zfs-initramfs, which is only needed when the system boots from ZFS. If the
running kernel has no matching headers, install linux-headers-amd64 before
or with zfs-dkms; DKMS cannot build a module without them.
Check what is installed and where APT would get a replacement:
$ dpkg-query -W zfsutils-linux zfs-dkms zfs-zed
zfs-dkms 2.3.9-0+deb13u1
zfs-zed 2.3.9-0+deb13u1
zfsutils-linux 2.3.9-0+deb13u1
The three packages are from the same OpenZFS release, which matters because
the kernel module and userspace tools share an on-disk format and an ioctl
interface. Mixing versions across a major upgrade can produce confusing
zpool or zfs failures. The package policy shows the archive component and
the available backports candidate:
$ apt-cache policy zfs-dkms zfsutils-linux zfs-initramfs
zfs-dkms:
Installed: 2.3.9-0+deb13u1
Candidate: 2.3.9-0+deb13u1
Version table:
2.4.4-1~bpo13+1 100
100 https://deb.debian.org/debian trixie-backports/contrib amd64 Packages
*** 2.3.9-0+deb13u1 500
500 https://deb.debian.org/debian trixie/contrib amd64 Packages
100 /var/lib/dpkg/status
2.3.5-2~bpo13+1 100
100 https://deb.debian.org/debian trixie-backports/contrib amd64 Packages
zfsutils-linux:
Installed: 2.3.9-0+deb13u1
Candidate: 2.3.9-0+deb13u1
Version table:
2.4.4-1~bpo13+1 100
100 https://deb.debian.org/debian trixie-backports/contrib amd64 Packages
*** 2.3.9-0+deb13u1 500
500 https://deb.debian.org/debian trixie/contrib amd64 Packages
100 /var/lib/dpkg/status
zfs-initramfs:
Installed: (none)
Candidate: 2.3.9-0+deb13u1
Version table:
2.4.4-1~bpo13+1 100
100 https://deb.debian.org/debian trixie-backports/contrib amd64 Packages
2.3.9-0+deb13u1 500
500 https://deb.debian.org/debian trixie/contrib amd64 Packages
2.3.5-2~bpo13+1 100
100 https://deb.debian.org/debian trixie-backports/contrib amd64 Packages
The 500 priority on trixie/contrib keeps the stable package as the default.
Backports have priority 100, so they are only selected when explicitly
requested or when the stable candidate is unavailable. Do not mix a
backports zfsutils-linux with a stable zfs-dkms, or upgrade one without
the other. If you need a newer OpenZFS feature, upgrade the complete
zfs-dkms and zfsutils-linux pair from backports and keep a compatible
rescue environment.
The userland tools report the module and userspace versions independently:
# zpool version
zfs-2.3.9-0+deb13u1
zfs-kmod-2.3.9-0+deb13u1
# zfs version
zfs-2.3.9-0+deb13u1
zfs-kmod-2.3.9-0+deb13u1
Matching lines are the normal state. If the userspace line is newer than the kernel module line, the running kernel is still using an older module; reboot after the DKMS build, or unload and reload the module if the pools are exported. A module that is older than the userspace tools may reject newer properties and features.
30.1.3. Kernel Updates, DKMS, and Secure Boot Module Signing
The ZFS kernel module is not part of the Debian kernel image. DKMS builds it
for each installed kernel from the zfs-dkms source package
(Chapter 7 covers kernel and DKMS administration). A
kernel upgrade therefore triggers a module build during package configuration. The build
needs the matching linux-headers-<version> package and a compiler; the
linux-headers-amd64 metapackage keeps headers installed for the current
kernel. If the build fails, the new kernel may boot without ZFS support, so
keep at least one older kernel and a rescue plan.
DKMS records the module version and kernel for which it was built:
# dkms status
zfs/2.3.9, 6.12.118+deb13-amd64, x86_64: installed
The installed state means the module exists for that kernel, not that it is
currently loaded. The running module's location, version, and signature come
from modinfo:
# modinfo zfs | grep -E '^(version|license|filename|signer|vermagic):'
filename: /lib/modules/6.12.118+deb13-amd64/updates/dkms/zfs.ko.xz
version: 2.3.9-0+deb13u1
license: CDDL
license: Dual BSD/GPL
license: Dual MIT/GPL
vermagic: 6.12.118+deb13-amd64 SMP preempt mod_unload modversions
signer: DKMS module signing key
The filename under updates/dkms confirms that this is a DKMS-built module,
not one shipped inside the kernel package. vermagic must match the running
kernel's version and build options; a mismatch means the module will not load.
The signer line is present because DKMS signs modules with a machine-generated
key.
DKMS uses a MOK (Machine Owner Key) pair for that signature. The configuration names the default paths even when the lines are commented out:
# grep -n -A5 -B2 -E 'mok_signing_key|mok_certificate' /etc/dkms/framework.conf
35-# can be used in path to represent the target kernel version.
36-#
37:# NOTE: If any of the files specified by `mok_signing_key` and `mok_certificate`
38-# are non-existent, dkms will re-create both files.
39-#
40:# mok_signing_key can also be a "pkcs11:..." string for PKCS#11 engine, as
41-# long as the sign_file program supports it.
42-# (default: /var/lib/dkms):
43:# mok_signing_key=/var/lib/dkms/mok.key
44:# mok_certificate=/var/lib/dkms/mok.pub
45-
46-# Automatically modprobe the built modules upon successful installation:
47-# modprobe_on_install="true"
48-
49-# Limit the number of jobs run in parallel (default is the number of CPUs)
The default key and certificate are created on first use:
# ls -l /var/lib/dkms/mok.key /var/lib/dkms/mok.pub
-rw------- 1 root root 1704 Nov 24 11:25 /var/lib/dkms/mok.key
-rw-r--r-- 1 root root 832 Nov 24 11:25 /var/lib/dkms/mok.pub
The private key is readable only by root. The certificate identifies the signing key:
# openssl x509 -in /var/lib/dkms/mok.pub -noout -subject -fingerprint -sha256
subject=CN=DKMS module signing key
sha256 Fingerprint=EB:99:B4:C4:15:EC:FE:46:31:8A:6C:46:1E:C2:83:F1:34:C0:09:73:50:23:51:05:24:E8:4A:9B:E7:75:E8:F4
On a system with Secure Boot enabled in firmware, the kernel refuses to load a
module whose signing certificate is not trusted. Enrolling the DKMS public
certificate in the firmware MOK database authorizes modules signed by that key.
The firmware state is visible through mokutil:
# mokutil --sb-state
EFI variables are not supported on this system
This output means the machine booted with legacy BIOS firmware, not that Secure
Boot is broken. On a UEFI machine with Secure Boot, the same command reports
SecureBoot enabled or SecureBoot disabled. The usual enrollment sequence is:
| Step | Command or action | Purpose |
|---|---|---|
| 1 | mokutil --import /var/lib/dkms/mok.pub |
Queue the DKMS certificate for enrollment; you set a one-time password |
| 2 | Reboot | Firmware opens the MOK manager before the boot loader |
| 3 | Enroll MOK, choose the certificate, enter the password | Add the key to the firmware's trusted list |
| 4 | mokutil --list-enrolled |
Verify that the certificate is present |
| 5 | dmesg or journalctl -k after a module load |
Check for signature or key-rejection messages |
Enrollment is an interactive firmware step. It cannot be completed over SSH
alone, and it must be repeated if the DKMS key pair is regenerated. If the
private key is replaced, modules signed with the old key remain trusted but new
builds are not; enroll the new mok.pub or remove the old entry with
mokutil --delete. On a UEFI host with Secure Boot, use the enrollment
sequence above.
A kernel update on a ZFS system follows this order:
- Install the new kernel and matching headers. APT usually does both, but a manually installed kernel may not pull headers.
- Let DKMS build and sign the ZFS module. Watch the package output for a
dkmsfailure rather than assuming success. - If the system boots from ZFS, rebuild the initramfs for the new kernel after the module is installed.
- Reboot into the new kernel and check
dkms status,modinfo zfs, andzpool status. - Keep the previous kernel installed until the new one has imported and mounted every pool successfully.
If the new module is missing, boot the previous kernel, investigate the DKMS
build log, fix the headers or compiler problem, and run dkms autoinstall
again. Do not run zpool upgrade while the only working module is the old one;
the pool may gain features that the old module cannot read.
30.1.4. Selecting Mirrors or RAIDZ and Planning Failure Domains
The vdev layout determines how many devices can fail, how much capacity is lost to parity, and how expensive a rebuild is. The main choices are mirrors and RAIDZ groups:
| Layout | Minimum devices | Usable capacity | Failures tolerated | Rebuild behavior | Best fit |
|---|---|---|---|---|---|
| Two-way mirror | 2 | About 50% | 1 per mirror vdev | Copies from the surviving mirror; relatively fast | Boot pools, small pools, write-heavy virtual machines |
| Three-way mirror | 3 | About 33% | 2 per mirror vdev | Copies from two survivors | High-value small pools, low-latency workloads |
| RAIDZ1 | 3 (production) | N-1 devices | 1 per RAIDZ vdev | Reconstructs from parity; reads every surviving disk | Bulk data where capacity matters more than IOPS |
| RAIDZ2 | 4 (production) | N-2 devices | 2 per RAIDZ vdev | Reconstructs from two parity blocks | Large disks and longer rebuild windows |
| RAIDZ3 | 5 (production) | N-3 devices | 3 per RAIDZ vdev | Reconstructs from three parity blocks | Very large or high-availability bulk pools |
A pool's fault tolerance is per top-level vdev. Two mirrored vdevs in one pool tolerate one disk failure in each mirror, but not the loss of an entire mirror. A pool with one RAIDZ1 vdev tolerates one disk failure; a second failure in the same vdev loses the pool. If the data matters, use RAIDZ2 or mirrors, and keep a cold spare or a documented replacement disk.
Failure domains are physical as well as logical. Two disks in the same enclosure, on the same power supply, or behind the same controller can fail together. Spread mirror legs and RAIDZ members across controllers and enclosures where the hardware allows it. A pool of two disks in one USB enclosure is a mirror in name only if the enclosure fails. For virtual machines, ensure the underlying datastore does not place all member disks on the same failing host or LUN.
ashift records the minimum allocation alignment. Modern 512e and 4K-native
disks perform best with ashift=12 (4 KiB). Set it at pool creation; it cannot
be changed later without recreating the vdev. A pool created without an
explicit ashift may inherit a smaller value from the device's reported sector
size, which can cause read-modify-write penalties on 4K media. The setting is
visible after creation:
# zpool get ashift tank
NAME PROPERTY VALUE SOURCE
tank ashift 12 local
Use whole disks or properly aligned partitions, not files on another filesystem, for production vdevs. File-backed vdevs are useful for testing but add a second allocation layer and hide the physical failure domain. Avoid putting swap on a ZFS zvol on a pool that can become full or degraded; use a separate swap partition or a swap file on a conventional filesystem when hibernation or reliable swap is required.
RAIDZ is not a substitute for backups. It protects against device failure, not against accidental deletion, application corruption, ransomware, or a lost pool. Snapshots protect against some logical errors but live in the same pool; replication to another host or media protects against pool loss. Section 30.5.4 returns to this distinction.
30.1.5. Memory, Capacity Headroom, and Feature Compatibility
ZFS uses free memory for the ARC. The cache improves read performance and
metadata lookup, but it must yield memory to applications under pressure. On
Linux the default maximum is derived from physical memory; the tunable
zfs_arc_max is 0 when the default is in effect:
# cat /sys/module/zfs/parameters/zfs_arc_max
0
The current ARC size and its breakdown are visible in /proc:
# grep -E '^(size|hdr_size|data_size|metadata_size)' /proc/spl/kstat/zfs/arcstats
size 4 26976
hdr_size 4 2400
data_size 4 0
metadata_size 4 24576
The numbers are bytes reported by the kernel. A small ARC after boot is normal;
it grows as workloads read data. Do not size ZFS by permanently subtracting a
large ARC reservation from the host's memory. Let the ARC use available memory
and monitor application pressure with free, vmstat, and the ARC statistics.
On a dedicated file server, a larger ARC is useful; on a hypervisor running
many guests, cap it if the guests need predictable memory. A temporary cap can
be set in /sys/module/zfs/parameters/zfs_arc_max, but persistent tuning belongs
in a module configuration file such as /etc/modprobe.d/zfs.conf and takes
effect after a module reload or reboot. The exact default fraction and minimum
are OpenZFS version details; check zfs-module-parameters(5) on the installed
system rather than copying a number from another distribution.
Capacity planning needs headroom. ZFS writes metadata, retains copy-on-write
blocks, and keeps pool-wide slop space; a pool that is 100% full can fail writes
even when df shows a little space. Keep at least 20% free for ordinary
filesystems, and more for pools with frequent snapshots, zvols, or databases.
Snapshots consume space as the live dataset changes; a snapshot of a busy
dataset can grow until the old blocks are no longer referenced. Quotas limit a
dataset but do not create free space; reservations guarantee space but reduce
what other datasets can allocate. Section 30.3.3 shows the accounting.
Feature compatibility is the other long-lived constraint. Modern OpenZFS uses feature flags rather than a single pool version number. A pool records which features are enabled; some are read-only compatible, meaning an older implementation can import the pool read-only but not write it, while others prevent import entirely. A pool created on Debian 13 may therefore be unreadable by an older rescue image or by a host running an older OpenZFS release. Check the supported features and the pool's status before upgrading. The following is selected output from the start of the feature list:
# zpool upgrade -v
This system supports ZFS pool feature flags.
The following features are supported:
FEAT DESCRIPTION
-------------------------------------------------------------
async_destroy (read-only compatible)
Destroy filesystems asynchronously.
empty_bpobj (read-only compatible)
Snapshots use less space.
lz4_compress
LZ4 compression algorithm support.
multi_vdev_crash_dump
Crash dumps to multiple vdev pools.
spacemap_histogram (read-only compatible)
Spacemaps maintain space histograms.
enabled_txg (read-only compatible)
Record txg at which a feature is enabled
hole_birth
Retain hole birth txg for more precise zfs send
extensible_dataset
Enhanced dataset functionality, used by other features.
embedded_data
Blocks which compress very well use even less space.
bookmarks (read-only compatible)
"zfs bookmark" command
filesystem_limits (read-only compatible)
Filesystem and snapshot limits.
large_blocks
Support for blocks larger than 128KB.
large_dnode
Variable on-disk size of dnodes.
sha512
SHA-512/256 hash algorithm.
skein
Skein hash algorithm.
edonr
Edon-R hash algorithm.
The list continues beyond the selected output shown here. zpool upgrade -v
prints the features this module knows; zpool get all <pool> shows the state of
each feature on a specific pool. zfs upgrade -v lists the older filesystem
version numbers, which are mostly relevant to very old pools; new pools use
feature flags and report version -. Section 30.6.4 covers upgrades and
recovery-media compatibility in detail.
A practical installation plan records the Debian release, the OpenZFS package versions, the kernel and headers, the pool layout, the device identifiers, the intended dataset hierarchy, the backup target, and the rescue media version. Without that record, a future administrator cannot tell whether a pool can be imported by the rescue system or which disk was held in reserve.