ZFS on Linux – Installation and Setup
This guide covers installing OpenZFS on Ubuntu or Debian and creating your first storage pool. If you’re new to ZFS, start with the ZFS Introduction first.
Requirements
- Ubuntu 20.04+ or Debian 11+
- At least one dedicated disk for ZFS (separate from your OS disk)
- At least 8 GB RAM (more is better for ZFS caching)
Step 1 – Install OpenZFS
sudo apt update
sudo apt install -y zfsutils-linuxVerify the installation:
zfs --versionStep 2 – Find Your Disks
List available disks:
lsblkGet persistent disk IDs (always use IDs in ZFS, not /dev/sdb):
ls -l /dev/disk/by-id/Note the IDs of the disks you want to use. They look like:
ata-WDC_WD4000FYYZ_WD-XXXXXStep 3 – Create a Storage Pool
Single disk (no redundancy — lab use only):
sudo zpool create mypool /dev/disk/by-id/ata-YOUR-DISK-IDMirror (2 disks — recommended minimum for data you care about):
sudo zpool create mypool mirror \
/dev/disk/by-id/ata-DISK1-ID \
/dev/disk/by-id/ata-DISK2-IDRAIDZ1 (3+ disks — 1 disk fault tolerance):
sudo zpool create mypool raidz1 \
/dev/disk/by-id/ata-DISK1-ID \
/dev/disk/by-id/ata-DISK2-ID \
/dev/disk/by-id/ata-DISK3-IDRAIDZ2 (4+ disks — 2 disk fault tolerance):
sudo zpool create mypool raidz2 \
/dev/disk/by-id/ata-DISK1-ID \
/dev/disk/by-id/ata-DISK2-ID \
/dev/disk/by-id/ata-DISK3-ID \
/dev/disk/by-id/ata-DISK4-IDStep 4 – Verify the Pool
zpool statusExample output:
pool: mypool
state: ONLINE
config:
NAME STATE READ WRITE CKSUM
mypool ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
sdb ONLINE 0 0 0
sdc ONLINE 0 0 0Check available space:
zpool listStep 5 – Create Datasets
Datasets are like folders inside a pool, but with their own properties (compression, quotas, snapshots):
# Create a dataset
sudo zfs create mypool/data
sudo zfs create mypool/backups
sudo zfs create mypool/mediaList datasets:
zfs listDatasets are automatically mounted at /mypool/data, /mypool/backups etc.
Step 6 – Enable Compression
ZFS compression is highly recommended — it’s fast and saves significant disk space:
sudo zfs set compression=lz4 mypoolLZ4 is the recommended compression algorithm — fast with good compression ratio. Enable it on the pool level and all datasets inherit it automatically.
Check compression ratio after some data is written:
zfs get compressratio mypoolStep 7 – Set Up Regular Scrubs
A scrub verifies and repairs data integrity. Run it monthly:
sudo zpool scrub mypoolCheck scrub status:
zpool status mypoolTo automate monthly scrubs, add a cron job:
sudo crontab -eAdd:
0 2 1 * * zpool scrub mypoolThis runs a scrub at 2am on the 1st of every month.
Set Mount Point and Permissions
Change where a dataset is mounted:
sudo zfs set mountpoint=/mnt/data mypool/dataSet permissions:
sudo chown -R $USER:$USER /mnt/dataRelated Links
- ZFS – Introduction and Key Concepts — understand ZFS before diving in
- ZFS Basic Commands — snapshots, clones, and everyday commands
- ZFS in Proxmox VE — ZFS integration in Proxmox
- OpenZFS Documentation — official docs