Share ZFS datasets with NFS


Add the following lines to /etc/rc.conf:


For some reason the NFS server needs to be restarted the first time after boot. A simple way to do this automatically is:

# echo "service nfsd restart" >> /etc/rc.local

Set the sharenfs property to the dataset you want to share. Replace the IPs and pool/dataset* with your desired values. ZFS properties are documented in zfsprops(8).

We’re going to share 2 datasets, one with read-write and one with read-only access:

# chmod -R 777 /pool/dataset_rw
# zfs set sharenfs='-network=,-alldirs' pool/dataset_rw
# zfs set sharenfs='ro=,-alldirs' pool/dataset_ro

Start the NFS server:

# service nfsd start
# service mountd reload

If any sharenfs changes occur while mountd(8) is running, it has to be reloaded again.


Acquire the host’s IP address using ifconfig(8) on it first. We’ll assume it’s

Mount the filesystems. /pool/dataset* corresponds to the actual mount point of the dataset in the host:

# mkdir -p /mnt/dataset_rw /mnt/dataset_ro
# mount -t nfs -o rw /mnt/dataset_rw
# mount -t nfs -o ro /mnt/dataset_ro

When done, unmount:

# umount /mnt/dataset_rw /mnt/dataset_ro

In case you want the filesystems to be mounted on boot, add the following lines to /etc/fstab:   /mnt/dataset_rw	nfs     rw      0       0   /mnt/dataset_ro	nfs     ro      0       0

Further reading

Tags: bsd