How to Install ZFS on Debian/Ubuntu

ZFS (Zettabyte File System) is an advanced filesystem that combines the roles of traditional filesystems, volume managers, and RAID arrays. It brings powerful features like data integrity verification, automatic repair, efficient snapshots, and simplified storage management.

Bertie Atkinson

ZFS was originally developed by Sun Microsystems for Solaris, and has since been ported to Linux. It’s designed to protect your data with a focus on integrity above all else. When you store data in ZFS, it calculates checksums for everything, allowing it to detect and (when configured with redundancy) automatically repair corrupted data.

Think of ZFS as not just a filesystem, but a complete storage management system that:

  • Protects against data corruption
  • Simplifies administration
  • Provides flexible storage pools
  • Offers efficient data compression, deduplication, and encryption

Installation Process for Ubuntu

Ubuntu makes ZFS installation relatively straightforward since the ZFS modules are included in the standard kernel.

Step 1: Install ZFS utilities

# Update package lists
sudo apt update

# Install ZFS packages
sudo apt install zfsutils-linux

This command installs the userspace tools needed to create and manage ZFS pools and filesystems. The kernel modules are already available in the Ubuntu kernel, so you don’t need to build them separately.

Step 2: Verify the installation

# Check if ZFS module is loaded
lsmod | grep zfs

# Check ZFS version
modinfo zfs | grep version

You should see output indicating that the ZFS module is loaded into the kernel. If not, you might need to load it manually with sudo modprobe zfs.

Installation Process for Debian

Debian requires a slightly different approach depending on the version you’re using.

For Debian 10 (Buster) and newer:

# Update package lists
sudo apt update

# Install required packages
sudo apt install -y gnupg

# Add Backports repository for the latest ZFS version (for Debian 11)
echo "deb http://deb.debian.org/debian bullseye-backports main contrib" | sudo tee /etc/apt/sources.list.d/bullseye-backports.list

# Update package lists again
sudo apt update

# Install ZFS from backports
sudo apt install -t bullseye-backports zfsutils-linux

For Debian 12 (Bookworm), you can install directly without using backports:

sudo apt update
sudo apt install zfsutils-linux

Step 2: Verify the installation

# Check if ZFS module is loaded
lsmod | grep zfs

# Check ZFS version
modinfo zfs | grep version

Setting Up Your First ZFS Pool

After installation, you can create your first ZFS pool. A pool is a collection of storage devices that ZFS manages as a single entity.

Step 1: Identify available disks

# List all disks and partitions
lsblk

# For more detailed information
sudo fdisk -l

Make note of the devices you want to use in your ZFS pool (e.g., /dev/sdb, /dev/sdc). Be extremely careful to identify the correct devices as this process will erase any existing data on them.

Step 2: Create a simple ZFS pool

For a single disk setup (no redundancy):

sudo zpool create mypool /dev/sdb

For a mirrored setup (RAID1-like redundancy):

sudo zpool create mypool mirror /dev/sdb /dev/sdc

For a RAID-Z setup (RAID5-like redundancy, requires at least 3 disks):

sudo zpool create mypool raidz /dev/sdb /dev/sdc /dev/sdd

Step 3: Verify the pool creation

# List all ZFS pools
sudo zpool list

# Check the status of your pool
sudo zpool status mypool

Step 4: Create a ZFS filesystem within the pool

ZFS allows you to create multiple filesystems within a pool, each with its own settings:

# Create a basic filesystem
sudo zfs create mypool/data

# Create a compressed filesystem
sudo zfs create -o compression=on mypool/compressed_data

Step 5: Mount your new filesystem

ZFS automatically mounts filesystems under /{poolname}/{filesystem}. For example:

  • /mypool
  • /mypool/data
  • /mypool/compressed_data

You can check these mount points with:

sudo zfs list

Common ZFS Operations

Once you have ZFS installed and a pool created, here are some common operations:

Taking snapshots

One of ZFS’s most powerful features is efficient snapshots:

# Create a snapshot of a filesystem
sudo zfs snapshot mypool/data@snapshot1

# List all snapshots
sudo zfs list -t snapshot

# Access snapshot files through the hidden .zfs directory
ls /mypool/data/.zfs/snapshot/snapshot1/

Think of snapshots as photographs of your filesystem at a particular moment in time. They’re incredibly space-efficient because they only track changes, not the entire filesystem.

Setting properties

ZFS has numerous properties you can set on filesystems:

# Enable compression
sudo zfs set compression=lz4 mypool/data

# Set a quota (limit) on a filesystem
sudo zfs set quota=100G mypool/data

# Enable automatic snapshots
sudo zfs set com.sun:auto-snapshot=true mypool/data

Checking pool health

Regular health checks are important for maintaining data integrity:

# Check pool status
sudo zpool status mypool

# Run a scrub to check and repair data
sudo zpool scrub mypool

# Check scrub progress
sudo zpool status mypool

A scrub is like a full filesystem check that verifies all data against its checksums, repairing any issues if possible.

ZFS Configuration Recommendations

For optimal ZFS performance and reliability, consider these recommendations:

Memory considerations

ZFS benefits from having ample RAM available:

  • Minimum: 2GB RAM
  • Recommended: At least 8GB RAM for general use
  • For deduplication: 1GB RAM per 1TB of storage (approximately)

ZFS uses the ARC (Adaptive Replacement Cache) to cache frequently accessed data in memory. More RAM means better read performance as more data can be cached.

Adjusting the ARC size

If ZFS uses too much RAM, you can limit the ARC size:

# Set maximum ARC size to 4GB
echo "options zfs zfs_arc_max=4294967296" | sudo tee /etc/modprobe.d/zfs.conf

The value is in bytes, so 4GB = 4 × 1024³ = 4,294,967,296 bytes.

Storage device considerations

ZFS works best with:

  • Whole disks rather than partitions
  • Disks of the same size in a pool
  • Non-SMR (Shingled Magnetic Recording) drives for write-intensive workloads

Potential Issues and Troubleshooting

Kernel updates

Occasionally, a kernel update might cause ZFS compatibility issues. If this happens:

# Reinstall ZFS after a kernel update
sudo apt install --reinstall zfsutils-linux

Pool import problems

If a pool doesn’t automatically import after a reboot:

# List available pools
sudo zpool import

# Import a specific pool
sudo zpool import mypool

DKMS build failures

If you encounter DKMS (Dynamic Kernel Module Support) build failures:

# Install required headers
sudo apt install linux-headers-$(uname -r)

# Reinstall ZFS
sudo apt install --reinstall zfsutils-linux

Conclusion

ZFS provides a robust, feature-rich storage solution that protects your data with its focus on integrity. The installation process on Debian and Ubuntu has become much more straightforward in recent years, making this powerful filesystem accessible to more users.

After installation, take time to explore ZFS’s many features like snapshots, send/receive for backups, and various compression algorithms. The learning curve may be steeper than traditional filesystems, but the benefits in terms of data protection and management capabilities are substantial.

Remember that ZFS is designed to protect your data, so always maintain proper backups even when using ZFS’s advanced redundancy features. No filesystem, no matter how advanced, replaces a good backup strategy.

Share This Article