ZFS Cheatsheet
ZFS Cheatsheet
Zpool commands
Create a stripe
zpool create myStripe dev1 ... devN
Create a mirror with two devices
zpool create myMirror mirror dev1 dev2
Create a RAIDZ1 with four devices
zpool create myRaid raidz dev1 dev2 dev3 dev4
Create a stripe of two RAIDZ1s
zpool create raidz dev1 dev2 dev3 raidz dev4 dev5 dev6
Common options when creating a pool
-m none # Don't mount the pool
-o ashift=12 # Disks have 4k block size (2^12 = 4096)
Export a pool (drives can be removed)
zpool export myPool
Import a pool
zpool import myPool
Import a pool with an alternative mountpoint
zpool import myPool -o altroot=/myPool
Import a pool and switch device labels
zpool import myPool -d /dev/disk/by-id
Scrub a pool
zpool scrub myPool
Abort a scrub
zpool scrub -s myPool
Take a device offline
zpool offline myPool dev1
Replace an (offline) device with a new disk
zpool replace myPool oldDev newDev
Report status
zpool status myPool
Create and mount datasets
Create a dataset
zfs create myPool/stuff
Common "zfs create" options
mountpoint=/mnt/stuff # Specify a mountpoint
mountpoint=legacy # Let fstab take care of mounting
fstab entry for a zfs legacy mountpoint
myPool/stuff /mnt/stuff zfs defaults 0 0
Create and mount volumes
Create a 32G volume for a non-zfs filesystem
zfs create myPool/myVol -V 32G
Each volume has an associated shortcut to an associated /dev/zdN device:
/dev/zvol/myPool/myVol -> ../../zd0
Create an ext4 files system on the volume
mkfs -t ext4 /dev/zvol/myPool/myVol
Listing things
List all zfs pools and datasets
zfs list
List all zfs pools, datasets, and snapshots
zfs list -t all
Network shares
Share a filesystem using NFS
zfs set sharenfs=on myPool/stuff
Access a zfs/nfs share remotely
mount -t nfs zfs.host.com:/stuff /mnt/stuff
Share a filesystem using SMB
zfs set sharesmb=on myPool/stuff
Access a zfs/smb share remotely
\\zfs.host.com\mypool_stuff
Additions to smb.conf to enable zfs/smb shares
[global]
usershare path = /var/lib/samba/usershares
usershare max shares = 100
usershare allow guests = yes
usershare owner only = no
File system preparation to enable zfs/smb shares
cd /var/lib/samba
mkdir usershares
chmod o+t usershares
chmod g+w usershares
Enable smb sharing
systemctl restart smb
zfs share -a
Snapshots and clones
Create a snapshot
zfs snapshot myPool/myStuff@now
Access a snapshot from a mounted dataset
Look into the hidden .zfs directory.
DON'T do this if the snapshot will be the target of
subsequent incremental replication. See "Cloning" below.
Clone a snapshot
This is useful if the dataset has no mountpoint or
if it's the target of an incremental backup.
zfs clone myPool/mystuff@now myPool/myTemp
zfs set mountpoint=/myTemp myPool/myTemp
You can now explore /myTemp. When finished:
zfs destroy myPool/myTemp
rmdir /myTemp
Replication
Replicate a snapshot
zfs send myPool/myStuff@now | zfs receive -d myOtherPool/myStuff
Options for zfs send
-R Replication: Include all descendents and properties
Options for zfs receive
-u Don't mount anything created
-F Rollback all changes since most recent snapshot
-d Discard the pool name from the sending path
-x mountpoint
Block mountpoints from taking effect on the target.
If the replicated pool is restored without this
option, all mountpoints will take effect which
may cause conflicts when a pool is used to backup
multiple operating systems.
Replicate a snapshot to another machine
zfs send myPool/myStuff@now | ssh destHost zfs receive -d myOtherPool/myStuff
For this to work, you must have passwordless access via ssh
to "destHost."
Create a recursive snapshot of a pool
zfs snapshot -r yule@now
-r Recursively include all descendent datasets
Initial replication of a pool (yule to myPool)
zfs send -R yule@now | zfs receive -uFd -x mountpoint mrPool/yule
Incremental replication
zfs rename -r yule@now yule@then
zfs snapshot -r yule@now
zfs send -Ri yule@then yule@now | zfs receive -ud -x mountpoint mrPool/yule
zfs destroy -r yule@then
zfs destroy -r mrPool/yule@then
Features
List pool features
zpool get all | grep feature
Upgrade pool to enable all available features
zpool upgrade
Note: "Enabled" does not mean "active"