A small ZFS mirror for a home NAS
For years my "NAS" was a single USB disk hanging off a router. It worked until the day it did not. This is the replacement: an old mini PC, two 4 TB disks and ZFS on Ubuntu. Nothing clever, which is the point.
Why a mirror
With two disks the choice is a mirror or nothing. A mirror halves the capacity, but any single disk can die and the data is still there. More importantly for a home setup, ZFS checksums every block, so a mirror can not only survive a dead disk but also repair silent corruption from the good copy.
Creating the pool
Always use the stable /dev/disk/by-id names, never /dev/sdX, which can change between boots:
sudo apt install zfsutils-linux
ls -l /dev/disk/by-id/ | grep -v part
sudo zpool create -o ashift=12 \
-O compression=lz4 -O atime=off -O xattr=sa \
tank mirror \
/dev/disk/by-id/ata-DISK_A_SERIAL \
/dev/disk/by-id/ata-DISK_B_SERIAL
ashift=12 matches 4K sectors, and it cannot be changed later. lz4 costs almost nothing and saves a surprising amount on documents and logs.
Datasets instead of folders
Each top-level share gets its own dataset, so snapshots and quotas can differ:
sudo zfs create tank/photos
sudo zfs create tank/documents
sudo zfs create -o quota=500G tank/backups
Scrubs
A scrub reads every block and verifies the checksums. Ubuntu ships a monthly scrub timer; I check that it is enabled and look at the result afterwards:
systemctl list-timers | grep zfs
zpool status -v tank
"0 errors" on every line is what you want. Anything in the CKSUM column means a disk or cable needs attention before it becomes a real problem.
Snapshots that clean up after themselves
Snapshots are cheap, but forgetting to delete them is how a pool fills up. zfs-auto-snapshot keeps a rolling window:
sudo apt install zfs-auto-snapshot
# keeps 4 x 15 min, 24 hourly, 31 daily, 8 weekly, 12 monthly by default
zfs list -t snapshot -o name,used | tail
Accidentally deleted a file? It is in /tank/documents/.zfs/snapshot/, readable like any other directory.
What this is not
A mirror is not a backup.
It protects against a failed disk, not against rm -rf on the wrong path, ransomware or a burst pipe. The important datasets also go to an external disk once a week with zfs send, and that disk lives somewhere else.