Skip to content

ZFS Management

tuinix uses ZFS with encryption as its root filesystem. This guide covers day-to-day ZFS operations.

Pool status

# Overall pool health
zpool status NIXROOT

# Dataset listing with space usage
zfs list

Snapshots

Snapshots capture the state of a dataset at a point in time. They're instant and initially consume no additional space.

Creating snapshots

# Snapshot the root dataset
sudo zfs snapshot NIXROOT/root@before-change

# Snapshot with a date-based name
sudo zfs snapshot NIXROOT/root@$(date +%Y-%m-%d)

# Snapshot all datasets recursively
sudo zfs snapshot -r NIXROOT@backup

Listing snapshots

zfs list -t snapshot

Rolling back

Warning

Rolling back destroys all changes made after the snapshot.

sudo zfs rollback NIXROOT/root@before-change

Deleting old snapshots

sudo zfs destroy NIXROOT/root@old-snapshot

Compression

ZFS compression is enabled by default. Check the compression ratio:

zfs get compressratio NIXROOT

Scrubbing

Scrubs verify data integrity by reading all blocks and checking checksums. Run periodically:

# Start a scrub
sudo zpool scrub NIXROOT

# Check scrub progress
zpool status NIXROOT

Recovery

If your system won't boot:

  1. Boot from the installation USB
  2. Import and unlock:
    sudo zpool import -f NIXROOT
    sudo zfs load-key -a
    sudo zfs mount -a
    
  3. Chroot in:
    sudo nixos-enter --root /mnt
    
  4. Fix and rebuild:
    nixos-rebuild boot --flake /etc/tuinix#<hostname>