Files
bikinibottom/TuringPi/zfs.md
T
2026-05-07 11:25:07 +02:00

3.6 KiB

ZFS

Update / Upgrade

sudo apt update && sudo apt upgrade -y

Enable the contrib repository

sudo nano /etc/apt/sources.list
#deb cdrom:[Debian GNU/Linux 13.3.0 _Trixie_ - Official amd64 NETINST with firmware 20260110-10:59]/ trixie contrib main non-free-firmware

deb http://deb.debian.org/debian/ trixie main contrib non-free-firmware
deb-src http://deb.debian.org/debian/ trixie main contrib non-free-firmware

deb http://security.debian.org/debian-security trixie-security main contrib non-free-firmware
deb-src http://security.debian.org/debian-security trixie-security main contrib non-free-firmware

# trixie-updates, to get updates before a point release is made;
# see https://www.debian.org/doc/manuals/debian-reference/ch02.en.html#_updates_and_backports
deb http://deb.debian.org/debian/ trixie-updates main contrib non-free-firmware
deb-src http://deb.debian.org/debian/ trixie-updates main contrib non-free-firmware

# This system was installed using removable media other than
# CD/DVD/BD (e.g. USB stick, SD card, ISO image file).
# The matching "deb cdrom" entries were disabled at the end
# of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.

Refresh package index and install ZFS

sudo apt update && sudo apt install linux-headers-6.12.85+deb13-amd64 zfsutils-linux -y

sudo modprobe zfs

sudo reboot

Verify ZFS Installation

lsmod | grep zfs
zfs --version
zpool --version

Creating and Using a ZFS Pool & Datasets

Once ZFS is installed, you can create pools (zpools) and datasets. Below is a typical example.

Identify disks / partitions

List available block devices:

lsblk
sudo blkid

Create a mirrored pool named tank using /dev/sda and /dev/sdb:

sudo zpool create \
  -o ashift=12 \
  -o autotrim=on \
  tank mirror /dev/sda /dev/sdb

Explanation:

ashift=12 sets a 4KiB sector alignment (useful for modern drives/SSDs).

autotrim=on enables automatic trimming (on SSDs).

mirror defines redundancy — you could also use raidz, raidz2, etc.

You can also check pool properties:

sudo zpool get all tank

Within the pool, create datasets:

sudo zfs create tank/cloud
# sudo zfs create tank/data
# sudo zfs create tank/data/projects
# sudo zfs create tank/data/backups

Datasets behave like sub-filesystems; you can set properties on each.

Example: enable compression and disable atime:

sudo zfs set compression=lz4 tank/data
sudo zfs set atime=off tank/data

Mountpoints

By default, datasets are mounted under /tank/..., but you can set mountpoint property:

sudo mkdir -p /mnt/cloud
sudo zfs set mountpoint=/mnt/cloud tank/cloud

To list datasets and their mountpoints:

zfs list

Using snapshots & rollbacks

sudo zfs snapshot tank/data@before-update

Roll back:

sudo zfs rollback tank/data@before-update

Send/receive snapshots for backups:

sudo zfs send tank/data@before-update | ssh user@backuphost "zfs receive backup/data"

Mounting, Autostart, and Integration

ZFS datasets are managed by ZFS itself; the mount/unmount is handled automatically by the ZFS service at boot (once ZFS is loaded). Ensure that ZFS mounting is enabled via systemd or init scripts:

sudo systemctl enable zfs-zed
sudo systemctl enable zfs-mount
sudo systemctl enable zfs-import-cache

PS : on Debian, the installation of zfs-zed may already set up the necessary services.

You can configure /etc/zfs/zfs-list.cache (automatically generated) for faster mounting.