Installing and Configuring OpenZFS on Fedora: Managing Zpools, Datasets, and Snapshots with DKMS

Fedora tutorial - IT technology blog
Fedora tutorial - IT technology blog

Background: Why Use OpenZFS on Fedora?

Conventional filesystems (like ext4 or NTFS) are like locking files away in a cabinet and assuming they will stay intact forever. In reality, hard drives running over long periods are prone to silent data corruption (bit rot), which can flip a few bits of data. The operating system usually has no idea this happened until you open the file and find it corrupted.

OpenZFS solves this problem by attaching a mathematical fingerprint (checksum) to every block of data as it is written. When you read a file, ZFS verifies that checksum. If it detects a mismatch, it automatically pulls a healthy copy from another drive in the array to heal the error on the fly. Beyond that, OpenZFS pools multiple drives into a single storage space, lets you carve out flexible partitions, and creates near-instantaneous snapshots.

On a Fedora dev machine, packages update rapidly—especially the Linux kernel. Due to open-source licensing differences (CDDL vs. GPL), OpenZFS is not built into the Linux kernel and instead runs as an out-of-tree module. This is where DKMS (Dynamic Kernel Module Support) comes in. Every time you upgrade to a new kernel, DKMS automatically recompiles the OpenZFS module to match so you don’t lose access to your pool after rebooting.

Fedora uses Btrfs by default for the OS partition, but OpenZFS remains a compelling choice for secondary storage. You can combine 2–4 external HDDs or SSDs into a mini NAS for source code, virtual machines (VMs), or backups. Thanks to its RAM-backed ARC cache and self-healing mechanisms, your data is far better protected.

Installing OpenZFS and the DKMS Module on Fedora

Make sure you have a Fedora machine (Workstation or Server) with sudo privileges and at least one or two secondary drives (or free partitions) to practice on. Never create a Zpool over the drive where your operating system is installed.

Step 1: Update the System and Install Kernel Build Tools

DKMS needs kernel headers that match your running kernel to compile the OpenZFS module. First, update your system and install the required build tools:

sudo dnf update -y
sudo dnf install -y kernel-devel kernel-headers gcc make dkms

If the command above just upgraded your kernel to a new version (for example, from 6.11 to 6.12), run sudo reboot to boot into the latest kernel before continuing.

Step 2: Add the Official OpenZFS Repository for Fedora

The official OpenZFS repository automatically detects your Fedora release using the %{dist} macro:

sudo dnf install -y https://zfsonlinux.org/fedora/zfs-release-2-5$(rpm --eval "%{dist}").noarch.rpm
sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-openzfs

Quick note: If you are running a newer Fedora release, check zfsonlinux.org for the latest zfs-release package version before running this command.

Step 3: Install ZFS and Enable Services

Next, install the zfs package. This pulls in zfs-dkms and compiles the module right in your terminal (typically taking 2–5 minutes depending on your CPU):

sudo dnf install -y zfs

Once installed, load the module into the Linux kernel and enable the systemd services so ZFS automatically re-imports your pools on boot:

sudo modprobe zfs
sudo systemctl enable --now zfs-import-cache zfs-mount zfs.target

Run a quick check to confirm DKMS compiled the module successfully for your current kernel:

dkms status
zfs --version

If the output shows installed alongside your running kernel version, you’re good to go.

Detailed Configuration: Managing Zpools, Datasets, and Snapshots

Think of OpenZFS architecture in three simple layers. A Zpool is a large warehouse built from multiple physical drives. A Dataset is an individual room inside that warehouse where you can set storage quotas or enable compression independently. A Snapshot is a point-in-time photograph of that room’s state.

Creating and Managing a Zpool

A common beginner mistake is using device names like /dev/sdb or /dev/sdc when creating a pool. These names can easily shift when you plug in a USB drive or swap SATA ports. Instead, use the persistent hardware identifiers in /dev/disk/by-id/:

ls -la /dev/disk/by-id/

Suppose you have two 1TB drives configured as a Mirror (similar to RAID 1, writing simultaneously to both drives). The command below creates a Zpool named tank with ashift=12 (matching the 4096-byte sector size of modern HDDs/SSDs):

sudo zpool create -o ashift=12 tank mirror \
  /dev/disk/by-id/ata-WDC_WD10EZEX-001 \
  /dev/disk/by-id/ata-WDC_WD10EZEX-002

If you are just testing on a single drive, omit the mirror keyword and pass a single disk path.

Creating Datasets and Optimizing Storage

Instead of dumping all your files into the root /tank directory, organize them into separate Datasets for each workload. The beauty of Datasets is that they share the pool’s free space dynamically rather than being locked to fixed sizes like traditional partitions:

sudo zfs create tank/projects
sudo zfs create tank/backups

Enabling lz4 compression saves 30%–50% of disk space on source code and log files with virtually zero CPU overhead. Additionally, disabling atime skips updating access timestamps every time a file is read, boosting I/O performance:

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

For your backup directory, set a storage cap (e.g., 200 GB) to prevent runaway logs or backups from filling up the entire pool:

sudo zfs set quota=200G tank/backups

Creating and Restoring Snapshots

Before upgrading a database or running a bulk file cleanup script, take a Snapshot. This completes in under a second and initially consumes almost no extra space:

sudo zfs snapshot tank/projects@truoc-khi-nang-cap

List all existing snapshots:

zfs list -t snapshot

If an upgrade goes wrong, roll the entire tank/projects directory back to the exact state when the snapshot was taken with a single command:

sudo zfs rollback tank/projects@truoc-khi-nang-cap

If you only accidentally deleted a single file like config.yaml, you don’t need to roll back the whole directory. OpenZFS lets you browse the hidden .zfs/snapshot/ directory inside the mountpoint and copy that specific file back:

cp /tank/projects/.zfs/snapshot/truoc-khi-nang-cap/config.yaml /tank/projects/

Health Checks and Monitoring OpenZFS

Even the most resilient storage system needs periodic checkups to catch failing drives before they die completely.

Checking Zpool Status and Capacity

The first command to remember is zpool status. It reports your pool’s health (ONLINE, DEGRADED, or FAULTED) along with read (READ), write (WRITE), and checksum (CKSUM) error counts for each drive:

sudo zpool status -v

To check actual available space and the compression ratio (e.g., 1.45x) for each Dataset, run:

zpool list
zfs list -o name,used,avail,refer,compressratio,mountpoint

Running Periodic Scrubs to Self-Heal Data

A Scrub is like a full warehouse inventory audit. ZFS reads every block of data on disk, verifies its checksum, and automatically repairs any mismatches it finds. You should run a scrub manually or schedule a monthly cron job:

sudo zpool scrub tank

For 500 GB of data on HDDs, this typically takes 40–90 minutes. While the scrub runs in the background, you can use zpool status to check its progress percentage and scan speed.

Monitoring I/O Performance and the ARC Cache

OpenZFS uses free RAM as an Adaptive Replacement Cache (ARC) to speed up file reads. To view real-time read/write stats every 2 seconds per drive, run:

zpool iostat -v 2

The included arcstat tool shows how much RAM ARC is using and whether your cache hit ratio is healthy (typically above 80%–90%):

arcstat 2

By default on Linux, ZFS can claim up to 50% of total RAM for ARC. On a 16 GB Fedora Workstation running Docker or VMs, dedicating 8 GB to cache can be excessive. You can cap ARC at 4 GiB (4,294,967,296 bytes) by creating a modprobe configuration file:

echo "options zfs zfs_arc_max=4294967296" | sudo tee /etc/modprobe.d/zfs.conf
sudo dracut --force

After a reboot, ARC memory usage will stay capped at 4 GiB.

Share: