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,-alldirs,-network=192.168.1.0/24" 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 2024-12-03T14:13:44+0000 by ChristosMargiolis)