Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

ZFS on Linux: A Modern Guide to the Forever File System

· 9 min read · Home Tech

In this article
  1. What Makes ZFS Different
  2. ZFS on Linux: A Brief History
  3. How ZFS Works: Pools, Datasets, and VDEVs
  4. Choosing Your First ZFS Configuration
  5. Installing and Creating Your First Pool
  6. Common Problems and How to Avoid Them
  7. ZFS vs. Traditional RAID and Other File Systems
  8. Costs and Hardware Considerations
  9. Frequently Asked Questions

ZFS on Linux is a mature, production-ready combination that gives you a self-healing, snapshotting, and virtually unlimited file system on standard Linux hardware. This guide explains what makes ZFS different, how to get started with it on Linux, and the practical decisions you will face, from choosing your first pool to recovering from a failed disk.

What Makes ZFS Different

ZFS was originally created by Sun Microsystems for Solaris in 2005, and it was designed from the ground up to solve problems that older file systems like ext4 and XFS handle poorly. The core idea is a copy-on-write (CoW) design: when data changes, ZFS writes the new version to a different location on disk and then updates a pointer to it. This single design choice gives you several powerful features at once.

  • Instant snapshots: Because old data is never overwritten in place, ZFS can freeze a point-in-time view of the entire file system without copying anything. Snapshots take almost no space initially and only grow as you change files.
  • Self-healing checksums: Every block of data has a checksum stored alongside it. When ZFS reads a block, it verifies the checksum. If the data is corrupted (bit rot), ZFS automatically repairs it using redundant copies or parity data, provided you have a mirror or RAID-Z configuration.
  • Data compression: ZFS can transparently compress data on the fly, often with the fast LZ4 algorithm, which can improve both space usage and read/write speed because less data touches the disk.
  • Unified storage pool: Instead of separate partitions for different file systems, ZFS pools all your disks together into one storage pool. You then create datasets (like file systems) that draw from that pool, with no need to pre-allocate sizes.

ZFS on Linux: A Brief History

For many years, ZFS was only available on Solaris and BSD systems. Linux users had to run it through FUSE (Filesystem in Userspace), which worked but was slow and unreliable. That changed in 2013 when the OpenZFS project released a native Linux kernel module. Since then, OpenZFS has become the standard implementation, and it is now included in most major Linux distributions as an installable package.

Today, OpenZFS on Linux is considered stable for production use. It is used by major cloud providers, storage appliance vendors, and millions of home users. The project releases new versions regularly, and the Linux kernel module is maintained to keep up with kernel changes. The main caveat is that ZFS is not part of the official Linux kernel due to licensing differences, so you must install it separately.

How ZFS Works: Pools, Datasets, and VDEVs

Understanding ZFS requires learning three key terms: vdev, pool, and dataset.

  • VDEV (Virtual Device): A vdev is a group of one or more disks. It can be a single disk, a mirror (two or more disks that hold identical copies), or a RAID-Z group (similar to RAID 5 or RAID 6, using distributed parity). The vdev is the unit of redundancy.
  • Pool: A pool is a collection of one or more vdevs. For example, you might have a pool made of two mirror vdevs, each mirror containing two disks. The pool is the total storage space available to your datasets.
  • Dataset: A dataset is a file system or a volume that lives inside a pool. You can create many datasets, each with its own settings for compression, snapshots, quotas, and mount points. Datasets are the things you actually use to store files.
  • When you create a pool, ZFS writes data across all vdevs in a round-robin fashion. This means that if you add a new vdev to a pool, the new space becomes available immediately, but existing data is not automatically rebalanced across the new vdev. This is an important performance consideration.

    Choosing Your First ZFS Configuration

    Before you run any commands, you need to decide on your hardware and redundancy level. The most common choices for home and small business users are:

    • Single disk: You get ZFS features like snapshots, compression, and checksums, but no redundancy. If the disk fails, you lose everything. This is only suitable for non-critical data.
    • Mirror (RAID-1): Two or more disks hold identical copies. You lose half your raw capacity, but you can survive the failure of one disk (or more, if you have more than two in the mirror). This is the simplest and fastest redundant setup.
    • RAID-Z1: Like RAID 5, uses one disk's worth of parity. You need at least three disks. You can survive one disk failure. Good balance of space and safety.
    • RAID-Z2: Like RAID 6, uses two disks' worth of parity. You need at least four disks. Survives two disk failures. Recommended for larger pools (6+ disks) because rebuild times are long.

    A common beginner mistake is to create a RAID-Z1 with many disks (say 8 or 10). If one disk fails, the rebuild process reads all disks heavily, and if another disk fails during the rebuild (which can take days), you lose everything. For pools with more than 6 disks, RAID-Z2 is strongly recommended.

    Installing and Creating Your First Pool

    Installation varies by distribution. On Ubuntu and Debian, you can install with sudo apt install zfsutils-linux. On Fedora, use sudo dnf install zfs (requires enabling the OpenZFS repository). On Arch, sudo pacman -S zfs-linux. After installation, load the kernel module with sudo modprobe zfs (or just reboot).

    To create a pool, you need to identify your disks. Use lsblk or fdisk -l to find device names like /dev/sdb and /dev/sdc. Then create a mirror pool with:

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

    This creates a pool named mypool with a mirror vdev. You can now create datasets with:

    sudo zfs create mypool/data

    This dataset is mounted at /mypool/data by default. You can set compression on it:

    sudo zfs set compression=lz4 mypool/data

    And take a snapshot:

    sudo zfs snapshot mypool/data@before-update

    To roll back to that snapshot, use sudo zfs rollback mypool/data@before-update. Snapshots are read-only, so you must clone them if you want to modify them.

    Common Problems and How to Avoid Them

    ZFS is powerful, but it has a few well-known pitfalls that trip up new users.

    • Running out of RAM: ZFS uses an adaptive replacement cache (ARC) that can consume a large portion of your system memory. By default, it will use up to 50% of your RAM for caching. This is usually good, but on systems with little RAM (say 4 GB), it can cause performance issues. You can limit it with sudo zfs set zfs_arc_max=1073741824 (1 GB).
    • Adding a vdev to a pool does not rebalance: If you add a new vdev, new data will go to it, but old data stays where it is. This can lead to uneven space usage. The only fix is to copy data off and back on, or to create a new pool and migrate.
    • Scrub regularly: A scrub reads all data and verifies checksums, repairing any corruption. You should run sudo zpool scrub mypool at least monthly. You can schedule it with cron or a systemd timer.
    • Don't use hardware RAID: ZFS expects to see individual disks. If you put disks behind a hardware RAID controller, ZFS cannot see the individual disk health or SMART data, and it defeats many of ZFS's self-healing features. Use an HBA (host bus adapter) in IT mode instead.

    ZFS vs. Traditional RAID and Other File Systems

    Many people ask how ZFS compares to a hardware RAID card with ext4, or to other modern file systems like Btrfs. The short answer is that ZFS is generally more feature-complete and mature than Btrfs, which still has occasional issues with RAID 5/6. Hardware RAID plus ext4 gives you redundancy but no checksums, no snapshots, and no compression. ZFS gives you all of that in one integrated stack.

    The main downside of ZFS is that it is not part of the Linux kernel, so you must rely on the OpenZFS project for updates. This is rarely a problem in practice, but it can be a concern for users who want a purely kernel-native solution. Also, ZFS does not support shrinking a pool—you cannot remove a vdev once it is added (except for hot spares). Plan your capacity carefully.

    Costs and Hardware Considerations

    ZFS itself is free and open source. The costs come from hardware. ZFS works best with ECC RAM (error-correcting memory) because it protects against bit rot, but if your RAM has an error, ZFS cannot detect it before writing bad data. ECC is recommended for production, but home users often run ZFS on standard non-ECC RAM without issues. The more important factor is having enough RAM: a general rule is 1 GB of RAM per 1 TB of raw storage, though this is not a hard requirement.

    For disks, any SATA or SAS drive works. ZFS does not require enterprise drives, but it does benefit from drives that support the TLER (time-limited error recovery) feature, which prevents the drive from spending too long trying to read a bad sector and instead reporting it to ZFS so it can be repaired. Consumer drives without TLER can sometimes cause ZFS to drop them from the pool during a scrub, which is why some users prefer NAS-specific drives.

    Frequently Asked Questions

    Is ZFS safe to use on Linux in 2024?

    Yes, OpenZFS on Linux is stable and widely deployed. It is the default file system on many NAS appliances and is used in enterprise environments. The main requirement is to keep it updated and to follow best practices like regular scrubs and having a backup for critical data.

    Can I add a disk to a RAID-Z pool to expand it?

    No, you cannot add a single disk to an existing RAID-Z vdev. You can only add a new vdev (e.g., a mirror or another RAID-Z group) to the pool, which increases total space but does not rebalance existing data. This is a known limitation.

    What is the difference between a snapshot and a clone?

    A snapshot is a read-only point-in-time copy of a dataset. A clone is a writable copy of a snapshot, but it shares data blocks with the original until changes are made. Clones are useful for creating test environments or for branching data.

    How do I move a ZFS pool to a new machine?

    You can export the pool on the old machine with sudo zpool export mypool, then physically move the disks to the new machine and import with sudo zpool import mypool. This is one of ZFS's strengths—pools are portable across systems and even across operating systems that support OpenZFS.

    Does ZFS work on a laptop with a single SSD?

    Yes, you can use ZFS on a single disk. You will not have redundancy, but you still get snapshots, compression, and checksums. Many users run ZFS on laptops for the snapshot feature alone, which allows easy rollback after system updates.

    What is the maximum size of a ZFS pool?

    ZFS uses 128-bit addresses, so the theoretical maximum is billions of times larger than any current hardware. In practice, you are limited by the number of disks you can connect and the size of those disks. For most users, the limit is effectively infinite.