kaeru


"Stuff I'm working on ..."

NFSv4 and ZFS on FreeBSD

by kaeru published 2024/09/28 11:25:00 GMT+8, last modified 2024-09-28T11:43:05+08:00
Configuring NFSv4 and ZFS on FreeBSD Server with Ubuntu Client
DSC_0004.JPG
Toshiba NAS 4TB Hard Disk

If you just want to get files and folders on a server shared by different users, on different operating systems, then setting up a Samba server is easy, discoverable by users and well documented. That has always been the case for the home server. NFS is more suited to share filesystems between Unix machines on a fast trusted local network.

Have always had a soft spot for NFS, especially Solaris thin clients that allow you to use any thin client terminal and have your Unix desktop with you load up wherever you are on campus, with all your apps, dotfile configurations and files.

Since I have a Linux workstation at home and FreeBSD server with a few always mounted directories, why not have a go and revisit NFS, ZFS and FreeBSD 14 circa 2024?

NFS documentation is a bit mixed up between NFSv3 and NFSv4 and it's not intuitively clear how zfs share interacts nfs exports. So hopefully this will help folks get started quickly without getting a bit confused like I did, with only the relevant configuration and documentation links.

Setting up NFSv4 on FreeBSD

Main documentation is manpage nfsv4(4)

Add the following in your rc.conf as documented :

#NFS
nfs_server_enable="YES"
nfsv4_server_enable="YES"
nfsuserd_enable="YES"

NFSv4 With ZFS

Documentation man pages are: exports(5) and zfsprops(7)

This is where it gets a bit confusing when it comes to the traditional /etc/exports configuration with zfs share command.

NFSv4 has a single top level definition for root. All your other exports come under this. Since we're using zfs share, we only need to add one entry in /etc/exports.

V4: /

You can set it lower level if you wish, but all your zfs share exports will need to be below that.

Setting up ZFS share properties

Documentation zfs-share(8)

ZFS shares are added automatically and loaded in /etc/zfs/exports for zfs datasets that have the sharenfs property.

And loaded via running zfs-share -a

You add the dataset you want to share by setting the property following standard exports format.

zfs set sharenfs="-network fdd5:xxxx:xxxx:0::1/64" media/music

which will then show up in

/etc/zfs/exports as

# !!! DO NOT EDIT THIS FILE MANUALLY !!!

/media/music -network fdd5:xxxx:xxxx:0::1/64

If it's not there after setting up, just run zfs share -a and check.

Important, NFS with ZFS cannot traverse nested datasets with -alldirs

Since each dataset is essentially a mounted drive, you will be able to browse nested datasets if you share at a higher level, but won't be able to list the contents.

For example if /media/music is a dataset and /media/movies are both datasets, you can't just share /media and only mount /media on client. You will have to set and mount for each sub zfs dataset. Exporting and mounting media will give you No input/Output errors when you try to list files and they will show up as empty. It will need to look like this.

# !!! DO NOT EDIT THIS FILE MANUALLY !!! 

/media/music -network fdd5:xxxx:xxxx:0::1/64
/media/media -network fdd5:xxxx:xxxx:0::1/64

Restart nfs and zfs share -a and check your /etc/zfs/exports to check it all looks good, and you're ready to mount it on client machine.

NFSv4 on Ubuntu Linux

Is straightforward. NFSv4 doesn't have showmount, so you'll have to know what you have to mount. You'll need the nfs-common.

apt install nfs-common

Mounting nfs on Linux

mount.nfs4 -v [fdd5:xxxx:xxxx:0::1]:/media/music /mnt/media/music

It should work. If you are getting permission errors, then double check all is OK on FreeBSD side.

On FreeBSD server restart services and zfs share by running:

service nfsd
zfs unshare -a
zfs share -a

And check /etc/export and /etc/zfs/esports for any typos.

If all is well, then you can mount it automatically in fstab like below.

[fdd5:xxxx:xxxx:0::1]:/media/music /mnt/media/music nfs4 _netdev,auto 0 0

Now that basics are working, will explore other NFSv4 features in future.