My zfs note

2016-7-9

This is a set of notes for common ZFS command and operations.

ZFS is an advanced file system that enabled snapshot, checksum and soft-raid features. Wiki on ZFS

A good set of ZFS reference can be found below: ZFS admin intro

Create a ZFS mount

List all disks

List all paritions:

lsblk

Show details of the disks:

sudo lshw -class disk

Create a mirrored pool

The follow would create a mirror (think raid 0) across two devices.

sudo zpool create tank mirror sdd sde

Create a dataset on top of the pool

Instead of directly using the created pool, it is usual to build a couple of datasets on top of the pool. To create a dataset,

zfs create tank/test
zfs set compression=lz4 tank/log
zfs set mountpoint=/mnt/test tank/test
zfs mount tank/test

We also enable the compression of the dataset via set compression.

Create a NFS share on top of the created dataset

Setup nfs under Ubuntu:

sudo aptitude install -R nfs-kernel-server
echo '/mnt localhost(ro)' >> /etc/exports
sudo /etc/init.d/nfs-kernel-server start

Share nfs:

zfs set sharenfs="rw=@10.80.86.0/24" pool/srv
zfs set sharenfs="on" pool/srv

Scrub the dataset regularly

Scrubing check the data integrity:

zpool scrub tank

Consider adding above to a cron-job. A set of script can be found here: ZFS scrub and status scripts