Skip to content

ZFS Filesystem Management Guide

ZFS Overview

ZFS (Zettabyte File System) is a next-generation filesystem that combines volume management and filesystem capabilities. It provides advanced features like snapshots, compression, deduplication, and built-in RAID functionality.

Prerequisites

  • Root or sudo access required for most ZFS operations
  • ZFS kernel modules must be installed
  • Understanding of storage concepts recommended

Installation & Setup

Install ZFS on Ubuntu
apt install zfsutils-linux

Ubuntu includes ZFS support out of the box.

On Debian, you need to build the kernel module via DKMS:

Install ZFS with DKMS
apt install zfsutils-linux zfs-dkms

Alternative: Zabbly ZFS builds

The Incus team maintains optimized ZFS builds at github.com/zabbly/zfs with pre-compiled modules for Debian.

Distribution Support

ZFS packages are available for most major Linux distributions. Check your package manager for zfs-utils or similar packages.

Pool Management

Create and List Pools

Pool Operations
zpool create local /dev/xxx  #(1)!
zpool list  #(2)!
  1. Creates a new ZFS pool named "local" using device /dev/xxx
  2. Lists all ZFS pools with their status and capacity

Device Selection

Replace /dev/xxx with your actual device path. This will destroy all data on the device!

Import Existing Pools

Import Pool
zpool import local  #(1)!
  1. Imports a previously created pool (useful after boot or cryptsetup unlock)

Auto-Import

Use this command after system boot or when encrypted drives become available via cryptsetup.

Dataset Management

Create and List Datasets

Dataset Operations
zfs create local/home  #(1)!
zfs list  #(2)!
zfs set mountpoint=/home local/home  #(3)!
  1. Creates a new dataset called "home" in the "local" pool
  2. Lists all ZFS datasets with their properties
  3. Sets the mount point for the dataset to /home

Compression & Optimization

Enable Compression
zfs set compression=lz4 local/home  #(1)!
zfs get compression  #(2)!
zfs get compressratio local/home  #(3)!
  1. Enables LZ4 compression (fast and efficient)
  2. Shows compression settings for all datasets
  3. Displays compression ratio for specific dataset
Enable Deduplication
zfs set dedup=on local/home  #(1)!
zpool get dedupratio local  #(2)!
  1. Enables deduplication (requires significant RAM)
  2. Shows deduplication ratio for the pool

RAM Requirements

Deduplication requires ~5GB RAM per TB of unique data. Monitor system memory usage carefully.

NFS Sharing

Setup NFS Server

Install NFS Services
apt install nfs-kernel-server nfs-common  #(1)!
systemctl enable --now rpc-statd.service nfs-server.service  #(2)!
  1. Installs NFS kernel server and common utilities
  2. Enables and starts NFS services

Configure ZFS NFS Shares

NFS Share Configuration
zfs set sharenfs="rw=@10.0.1.0/24" local/home  #(1)!
zfs share local/home  #(2)!
zfs get sharenfs  #(3)!
  1. Sets NFS share permissions for 10.0.1.0/24 network
  2. Activates the NFS share
  3. Displays current NFS share settings

Snapshots & Backups

Snapshot Management

Snapshot Operations
zfs snapshot local/containers/archive@backup  #(1)!
zfs list -t snapshot  #(2)!
zfs destroy local/containers/archive@backup  #(3)!
  1. Creates a snapshot named "backup" of the archive dataset
  2. Lists all available snapshots
  3. Removes the specified snapshot

Remote Backup

Send Snapshot to Remote Host
zfs send local/containers/archive@backup | ssh zfs@10.0.1.1 sudo zfs recv local/lxd00/containers/archive  #(1)!
  1. Sends snapshot over SSH to remote ZFS system for backup

Backup Strategy

  • Create regular snapshots for point-in-time recovery
  • Use zfs send/recv for efficient remote backups
  • Consider automated snapshot management tools

Clone Operations

Create Clone
zfs clone local/containers/archive@backup local/containers/archive-clone  #(1)!
  1. Creates a writable clone from a snapshot

Clones vs Snapshots

  • Snapshots: Read-only point-in-time copies
  • Clones: Writable copies that can be modified independently

Additional Resources

Best Practices

  • Monitor pool health with zpool status
  • Regular snapshots before major changes
  • Use compression for most datasets
  • Be cautious with deduplication on systems with limited RAM

Common Commands Quick Reference

Essential Commands
zpool status      # Check pool health
zfs list -o space # Show space usage
zpool scrub local # Start data integrity check
zfs mount -a      # Mount all datasets