How to Set Up OpenZFS on AlmaLinux 9 or Rocky Linux 9
Install OpenZFS on AlmaLinux 9 or Rocky Linux 9 with kABI-tracking kmod or DKMS packages, then create a pool, datasets and snapshots and keep them healthy.
OpenZFS combines a volume manager and a file system: it pools disks, checksums every block, compresses data transparently and takes instant snapshots. This guide installs OpenZFS on AlmaLinux 9 or Rocky Linux 9 from the OpenZFS project's own repository, creates a storage pool on an extra disk, and walks through datasets, snapshots and routine maintenance. It applies to RHEL 9 as well, and to CentOS Stream 9 with one difference described below.
CentOS 7 reached end of life in June 2024, and the old archive.zfsonlinux.org repository URLs used by older tutorials are no longer the documented ones. The RHEL kernel does not include ZFS, so the modules come from the OpenZFS repository, which publishes packages for x86_64 only.
Requirements
- AlmaLinux 9, Rocky Linux 9 or RHEL 9 on x86_64, fully updated and rebooted into the newest kernel.
- A user with
sudorights. - At least one unused disk or block storage volume for the pool. The examples use
/dev/vdband/dev/vdc. Everything on these disks is erased.
OpenZFS only updates the repository for the current minor version of each major release, so keep the system on the latest 9.x minor release.
Step 1: Add the OpenZFS repository
Install the zfs-release package, which adds the repository definition and the signing key:
sudo dnf install https://zfsonlinux.org/epel/zfs-release-3-0$(rpm --eval "%{dist}").noarch.rpm
The key is stored under /etc/pki/rpm-gpg/. Display its fingerprint:
gpg --show-keys --fingerprint /etc/pki/rpm-gpg/RPM-GPG-KEY-openzfs*
For EL 9 the OpenZFS documentation lists this fingerprint:
7DC7 299D CF7C 7FD9 CD87 701B A599 FD5E 9DB8 4141
Compare it with the value on the OpenZFS page for RHEL-based distributions before you install packages signed with it. The package may also ship the older key used for EL 8; it is the EL 9 fingerprint that has to match.
Step 2: Choose kABI-tracking kmod or DKMS packages
The repository offers the kernel modules in two forms.
| kABI-tracking kmod | DKMS | |
|---|---|---|
| How modules are delivered | Pre-built for the distribution kernel | Compiled on your server for each installed kernel |
| Kernel updates | No rebuild needed | Rebuilt automatically, needs a compiler and matching kernel-devel |
| Use it for | AlmaLinux, Rocky Linux and RHEL with the stock kernel | CentOS Stream 9, custom or third-party kernels, local patches |
OpenZFS recommends the kABI-tracking kmod packages for most users. They are only verified against the distribution-provided, non-Stream kernel, so use DKMS on CentOS Stream 9.
Option A: kABI-tracking kmod (recommended)
The release package enables the DKMS repository by default. Switch to the kmod repository and install:
sudo dnf config-manager --disable zfs
sudo dnf config-manager --enable zfs-kmod
sudo dnf install zfs
Option B: DKMS
DKMS comes from EPEL and needs the kernel headers that match the running kernel:
sudo dnf install -y epel-release
sudo dnf install -y kernel-devel
sudo dnf install -y zfs
If uname -r shows an older kernel than the installed kernel-devel version, reboot into the current kernel first; otherwise the module is built for a kernel you are not running. To change from DKMS to kmod packages later, uninstall the DKMS packages before installing the kmod ones.
Step 3: Load the module
Load the module and confirm the versions of the userland tools and the kernel module:
sudo modprobe zfs
zfs version
The modules are loaded automatically at boot when a pool is detected. If you want them loaded on every boot regardless, add a modules-load entry:
echo zfs | sudo tee /etc/modules-load.d/zfs.conf
Step 4: Create a pool
Identify the empty disks:
lsblk
Create a pool named tank on a single disk:
sudo zpool create tank /dev/vdb
A single-disk pool detects corruption but cannot repair it. With two disks, create a mirror instead:
sudo zpool create tank mirror /dev/vdb /dev/vdc
With three or more disks you can replace mirror with raidz (one disk of parity) or raidz2 (two). On hardware where device names can change between boots, use the stable names from /dev/disk/by-id/ instead of /dev/vdb. Check the result:
zpool status tank
zpool list
The pool is mounted at /tank and is ready to use. No /etc/fstab entry is needed; ZFS mounts its own file systems.
Step 5: Create datasets and set properties
Datasets are file systems inside the pool. They share its free space and each has its own properties. Create two, enable compression on the pool so that new datasets inherit it, and limit one dataset to 20 GB:
sudo zfs create tank/data
sudo zfs create tank/backups
sudo zfs set compression=lz4 tank
sudo zfs set quota=20G tank/backups
zfs list
To mount a dataset somewhere else, change its mountpoint property:
sudo zfs set mountpoint=/srv/data tank/data
zfs get compression,quota,mountpoint tank/data tank/backups
Step 6: Work with snapshots
A snapshot is a read-only, point-in-time copy of a dataset. It is created instantly and only consumes space as the live data diverges from it:
sudo zfs snapshot tank/data@before-upgrade
zfs list -t snapshot
Individual files can be copied back from the hidden .zfs/snapshot/before-upgrade/ directory inside the dataset's mount point. To return the whole dataset to the snapshot, discarding every later change, roll it back:
sudo zfs rollback tank/data@before-upgrade
Delete a snapshot you no longer need:
sudo zfs destroy tank/data@before-upgrade
Step 7: Import and export a pool
To move the disks to another server, or to attach an existing pool to a freshly installed system, export the pool on the old system and import it on the new one:
sudo zpool export tank
sudo zpool import
sudo zpool import tank
Running zpool import without a name lists the pools found on the attached disks. If a pool was not exported cleanly because the old system died, sudo zpool import -f tank forces the import.
Maintenance
Run a scrub regularly, for example once a month. It reads all data and repairs any block whose checksum does not match, provided the pool has redundancy:
sudo zpool scrub tank
zpool status tank
Confirm that the services that import and mount pools at boot are enabled:
systemctl is-enabled zfs-import-cache zfs-mount zfs.target
Enable any that are reported as disabled with sudo systemctl enable, then reboot once and check that /tank is mounted.
Take care with minor release upgrades, for example from 9.x to the next 9.x. The new kernel can change the kABI, and the existing kmod-zfs package may not work with it. After such an upgrade, and before rebooting if possible, check that dnf has installed a kmod-zfs build for the new minor release; reinstall the package if the modules do not load. With DKMS, check dkms status after every kernel update.
Frequently asked questions
How much memory does ZFS need?
ZFS caches file data in memory in its Adaptive Replacement Cache (ARC) and releases it when applications need the memory. It runs on small servers, but more memory means more cache and better read performance. Tools such as free can make a ZFS server look fuller than it is, because the ARC is not always counted as reclaimable cache.
Which OpenZFS version will I get?
The default zfs and zfs-kmod repositories carry the release the project has chosen for EL 9. The release package also defines zfs-latest and zfs-legacy repositories, each with a -kmod variant, if you want the newest release or want to stay on the previous one. Switch with dnf config-manager as in step 2.
Can the root file system be on ZFS?
It is possible, and the OpenZFS documentation has a separate Root on ZFS guide for Rocky Linux, but the installer does not support it and the setup is manual. For most servers it is simpler to keep the operating system on XFS or ext4 and use ZFS for the data disks.
Why does the module fail to load after a kernel update?
With kmod packages, the kernel is usually from a newer minor release than the installed kmod-zfs supports; update or reinstall kmod-zfs. With DKMS, the build probably failed because kernel-devel for the new kernel was missing; install it and run sudo dkms autoinstall.