Share ZFS datasets with NFS

Thanks to MarkJohnston for recommending this configuration.

Host

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

nfs_server_enable="YES"
mountd_enable="YES"
rpc_lockd_enable="YES"
rpc_statd_enable="YES"
rpcbind_enable="YES"

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

# zfs set sharenfs='ro=192.168.1.0/24,-alldirs' pool/dataset

Start the NFS server:

# service nfsd start
# service mountd reload

Guest

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

Mount the filesystem. /foo corresponds to the actual mount point of the dataset in the host:

# mkdir -p /mnt/foo
# mount -t nfs 192.168.1.5:/foo /mnt/foo

If and when done, unmount it:

# umount /mnt/foo

In case you want the filesystem to be mounted on boot, add the following line to /etc/fstab:

192.168.1.5:/foo   /mnt/foo        nfs     ro      0       0

Further reading

ZFS/ShareNFS (last edited 2023-01-29T14:23:20+0000 by GrahamPerrin)