Setting up an NFS Server with Linux, Mac, and Kodi Clients

Posted on Tue 22 June 2021 in Sysadmin

Introduction

We'd like to set up an NFS 3 server on a Raspberry Pi with Linux, Mac, and Kodi clients. Kodi does not support NFS 4 out of the box, so we'll stick with NFS 3 for now.

Set up the Server

As a starting point, follow this tutorial to install and set up an NFS (4) server on the Raspberry Pi. Then, make sure to change the server configuration as follows for running an NFS 3 server (assuming you want to export the /nfsexport/myshare directory:

/etc/exports

/nfsexport             *(rw,sync,no_subtree_check)
/nfsexport/myshare     *(rw,sync,no_subtree_check)

/etc/hosts.deny

rpcbind mountd nfsd statd lockd rquotad : ALL

/etc/hosts.allow

rpcbind mountd nfsd statd lockd rquotad : 127.0.0.1 192.168.100.2 192.168.100.3 <more-ip-addresses> 

Finally, run sudo systemctl restart nfs-kernel-server.service for the changes to take effect and check if your NFS server is running as expected using sudo rpcinfo -p. Your NFS share will them be available at nfs://<ip-address>/nfsexport/myshare

Linux Client Configuration

Add the following line to your /etc/fstab:

<ip-address>:/nfsexport/myshare /mnt/nfs nfs auto 0 0

Mac (Catalina+) Client Configuration

To mount the NFS volume at boot time, we have to add it to the automounter master map (source).

/etc/auto_master

Add the following auto_nfs line to the end of the file. This will try to auto-mount your nfs drive.

#
#
...
/-                 auto_nfs     -nobrowse,nosuid

/etc/auto_nfs

Create the file /etc/auto_nfs and use the template below as an example for your settings.

/System/Volumes/Data/Users/Shared/nfs_volume -fstype=nfs,noowners,nolockd,resvport,hard,bg,intr,rw,tcp,nfc,rsize=8192,wsize=8192 nfs://<ip-address>:/nfsexport/myshare
  • /System/Volumes/Data/Users/Shared/nfs_volume, the location where you want to mount the volume. Change nfs_volume to match the location where you want the volume to be visible in your local file system.
  • -fstype=nfs, the filetype to mount
  • noowners,nolockd,resvport,hard,bg,intr,rw,tcp,nfc,rsize=8192,wsize=8192, the mounting parameters where the parameter resvport might be required to connect to the NFS volume.
  • nfs://<ip-address>:/nfsexport/myshare, the location of the NFS volume

Set the proper rights on the file /etc/auto_nfs:

sudo chmod 644 /etc/auto_nfs

Mount the NFS Volume

Use the following command to initiate the automounter:

$ sudo automount -cv
automount: /net updated
automount: /home updated
automount: /System/Volumes/Data/Users/tisgoud/nfs_volume updated
automount: no unmounts

Your NFS volume is now mounted.

Kodi Client Configuration

Use the following address for your media source definitions:

nfs://<ip-address>/nfsexport/myshare/<sub-path>