Installing ZFS on Ubuntu: The ‘Lifesaver’ for Peace of Mind and Data Security

Ubuntu tutorial - IT technology blog
Ubuntu tutorial - IT technology blog

The Nightmare of Data Loss and Why ZFS is a Real Lifesaver

Have you ever stayed up all night because a hard drive suddenly “gave up”? Or even worse, accidentally typed rm -rf on the wrong critical database folder? That feeling of helplessness is truly terrible. When I first started as a sysadmin, I once lost all project data due to a tiny bad sector. After that shock, I realized ext4 or xfs just wasn’t enough. That’s when I discovered ZFS (Zettabyte File System).

ZFS is more than just a file system. It’s like an intelligent warehouse management brain, combining both a Volume Manager and a File System. The biggest selling point of ZFS is its self-healing capability and real-time data compression. In particular, the Snapshots feature has saved me from “near-death” situations more times than I can count.

Three Core Concepts to Master ZFS

ZFS operates completely differently from traditional partitioning. To avoid confusion, you just need to grasp these three concepts.

1. Storage Pool (ZPool): The Data Pond

Instead of formatting individual partitions (sda1, sdb1…), ZFS aggregates all physical drives into a shared “pond” called a ZPool. From here, you can freely create smaller file systems inside. Expansion is incredibly easy: just plug a new drive into the pool and the capacity increases instantly.

2. Copy-on-Write (CoW) and Snapshots

This is a feature I’m truly passionate about. When you modify a file, ZFS doesn’t overwrite the old location. It writes new data to a different empty block and then updates the pointer. This ensures data remains safe even during sudden power outages. Snapshots leverage this mechanism to “photograph” the system state almost instantly without consuming extra space (unless data changes).

3. RAID-Z: The Software Alternative to Expensive RAID Cards

Don’t waste money on hardware RAID cards unless you really need to. RAID-Z handles everything via software but is extremely efficient:

  • RAID-Z1: Allows 1 drive failure (equivalent to RAID 5).
  • RAID-Z2: Allows 2 simultaneous drive failures (equivalent to RAID 6).
  • Mirror: Writes data in parallel (equivalent to RAID 1).

Hands-on: Installing and Configuring ZFS on Ubuntu

Assume you are using Ubuntu Server 22.04 or 24.04. We will use 3 empty hard drives (sdb, sdc, sdd) to build a RAID-Z1 system.

Step 1: Install Management Tools

Although the Ubuntu Kernel already supports ZFS, you still need the command-line toolset to operate it.

sudo apt update && sudo apt install zfsutils-linux -y

Type zfs --version to ensure everything is ready.

Step 2: Identify Hard Drives

Never rely on names like sdb or sdc because they can change after every reboot. Use the actual disk IDs instead:

ls -l /dev/disk/by-id/

This tip keeps your pool stable, preventing pool errors caused by the system misidentifying device names.

Step 3: Create a ZPool with RAID-Z Configuration

I will create a pool named data_pool using the following command:

sudo zpool create -f data_pool raidz1 /dev/sdb /dev/sdc /dev/sdd

ZFS will automatically mount the pool to the /data_pool directory. Check the status again with zpool status.

Step 4: Create Datasets and Enable lz4 Compression

Don’t just dump everything into the pool’s root directory. Create separate Datasets instead. I usually enable lz4 compression for datasets containing logs or source code. In practice, lz4 can help you save 30-50% of storage space with almost zero CPU overhead.

sudo zfs create data_pool/projects
sudo zfs set compression=lz4 data_pool/projects

Step 5: Snapshots – A True Time Machine

Before performing a major application update, “seal” a snapshot:

sudo zfs snapshot data_pool/projects@backup_before_update

If the code ends up broken everywhere, it takes just one second to return to the previous state using the rollback command.

ZPool Maintenance: Don’t Forget the ‘Scrub’ Command

ZFS can detect silent data corruption thanks to the Checksum mechanism. My advice is to run the scrub command once a month to let the system scan and automatically repair hard drive errors.

sudo zpool scrub data_pool

If a hard drive fails (DEGRADED status), simply pull out the old drive, plug in a new one, and run zpool replace. RAID-Z will automatically resynchronize the data without interrupting the system.

Conclusion: ZFS is a Worthwhile Investment

ZFS is truly a heavy-duty weapon for anyone looking to build a resilient storage system. It completely eliminates data loss anxiety for tech professionals. A small note: ZFS loves RAM. The old rule of thumb is 1GB of RAM for every 1TB of data if using Deduplication, but for basic needs, 8GB-16GB of RAM is more than enough for a home NAS or small server. Try installing it today for better sleep!

Share: