Installing ZFS (Linux)
Introduction
ZFS is available on Linux through the ZFS on Linux (ZoL) project. This guide provides instructions for installing and configuring ZFS on various Linux distributions, focusing on Ubuntu as an example.
Installing ZFS on Ubuntu
Updating the System:
- Before installing ZFS, ensure the system is up to date:
sudo apt update sudo apt upgrade
- Before installing ZFS, ensure the system is up to date:
Installing the ZFS Utilities:
- Install the ZFS utilities using the package manager:
sudo apt install zfsutils-linux - This command installs the necessary ZFS packages and loads the ZFS kernel modules.
- Install the ZFS utilities using the package manager:
Verifying Installation:
- Check if the ZFS modules are loaded:
lsmod | grep zfs - The presence of
zfsin the output confirms that the ZFS modules are loaded.
- Check if the ZFS modules are loaded:
Installing ZFS on Other Linux Distributions
Fedora
Enabling the ZFS Repository:
- Add the ZFS repository to your system:
sudo dnf install https://zfsonlinux.org/epel/zfs-release.el7_9.noarch.rpm
- Add the ZFS repository to your system:
Installing ZFS:
- Install the ZFS packages:
sudo dnf install zfs
- Install the ZFS packages:
Loading ZFS Modules:
- Load the ZFS kernel module:
sudo modprobe zfs
- Load the ZFS kernel module:
Arch Linux
Installing ZFS via AUR:
- Install ZFS using an AUR helper like
yay:yay -S zfs-dkms zfs-utils
- Install ZFS using an AUR helper like
Loading ZFS Modules:
- Load the ZFS kernel module:
sudo modprobe zfs
- Load the ZFS kernel module:
Creating and Configuring ZFS Pools
Once ZFS is installed, ZFS pools can be created using the zpool command. The process is the same across Linux distributions:
Creating a ZFS Pool:
- Example for creating a pool on a single disk:
sudo zpool create mypool /dev/sda
- Example for creating a pool on a single disk:
Verifying the Pool:
- Check the status of the pool:
sudo zpool status
- Check the status of the pool:
Recommended Dataset Properties for Linux
A handful of dataset properties have defaults that suit ZFS's Solaris heritage better than a modern Linux system, and nearly every Linux deployment benefits from changing them. Because dataset properties are inherited, the best time to set them is at pool creation with -O, so that every dataset created later picks them up automatically:
sudo zpool create -o ashift=12 \
-O xattr=sa -O acltype=posixacl -O atime=off \
-O compression=lz4 -O dnodesize=auto \
mypool /dev/sda
What each property does:
xattr=sa— thexattrproperty controls how extended attributes are stored, and Linux uses them heavily (SELinux labels, file capabilities, ACLs). The defaultxattr=onstores each one as a hidden file, costing extra disk seeks on every lookup.xattr=sastores them compactly inside the file's dnode instead, which is significantly faster for metadata-heavy workloads.acltype=posixacl— the defaultacltypediscards POSIX ACLs entirely; setting it toposixaclenables them. This matters even on single-user systems, becausesystemd-journalduses ACLs on/var/log/journal; without this property, persistent journal permissions do not work correctly.atime=off— by default every file read triggers a metadata write to update the access time (atime), which is wasted I/O for almost all workloads. If some software genuinely needs access times,relatime=onis the middle ground, updating them at most once a day.compression=lz4— effectively free on modern CPUs and often improves performance by reducing the amount of data written; incompressible data is detected and stored as-is.dnodesize=auto— lets ZFS use larger dnodes when needed, which keepsxattr=saattributes inside the dnode even when they are numerous. The two properties are usually set together.
On an existing pool the same properties can be applied with zfs set, and child datasets inherit them from that point on. Note that changing xattr=sa only affects newly written extended attributes; existing ones remain in the old format until rewritten.
Two caveats: setting dnodesize to auto activates the large_dnode pool feature, which GRUB does not understand — leave it unset on a boot pool, or constrain the pool with the compatibility property as described in Feature Flags and Pool Compatibility. And xattr=sa attributes may not be readable if the pool is later imported on platforms other than Linux and FreeBSD.
This completes the installation and setup of ZFS on Linux. The following sections will cover fundamental ZFS concepts in more detail.