Kodi server part 2: NFS file sharing

This is the second part of a multi-part tutorial describing how to configure the "perfect" Kodi media centre running on top of ubuntu server.

Other parts of the tutorial may be found here:

This part of the tutorial concerns the use of the Network File System (NFS) protocol for sharing files on your network.

NFS file server

At the moment, your media database is shared between devices but the actual files are not - if you added a file on the local filesystem of your kodi box to the library, the library entry would show up on the second machine but there would be no way to play it.

We will set up an NFS server to share files on the local network. NFS is ideal for sharing media files because it is extremely fast (low protocol overhead compared to alternatives like Samba, SSHFS and FTP) and although access control tools in NFS are poor compared to other protocols, the files we will be sharing aren't private and write access isn't required so we can just make them available read-only.

Access control in NFS is based on IP addresses - if you want to read more, see the centos docs for NFS - NFSv4 has some improvements that switch from host based methods to user based authentication, but I won't go into it here because NFSv3 is good enough and NFSv4 isn't supported by Kodi.

Start by installing the NFS server:

sudo apt-get update
sudo apt-get install nfs-kernel-server

Next we will start and enable two services. First is rpcbind, which is a service that acts kind of like a DNS server for NFS, by telling clients which port number to use to connect to the NFS server:

sudo systemctl start rpcbind
sudo systemctl enable rpcbind

And secondly, the NFS server itself:

sudo systemctl start nfs-server
sudo systemctl enable nfs-server

We are going to place all of the files to be shared under a new directory /srv/nfs/. As you will see later, I have three external hard drives containing media files, which are mounted at /srv/nfs/drive1, /srv/nfs/drive2 and /srv/nfs/drive3. First, make the directories you need like this:

sudo mkdir -p /srv/nfs/{drive1,drive2,drive3}

If you have a large internal hard drive in your kodi box that contains media files you want to export (e.g. files under /home/kodi/Videos/), you will still want to export these using NFS so that they are available on the network. If you are in this situation, make sure there is nothing private in the videos directory, and then create a symbolic link into /srv/nfs/:

sudo ln -s /home/kodi/Videos /srv/nfs/localvideos

Next, we need to tell NFS which files to share. Open /etc/exports and add one line for the /srv/nfs directory and another line for each drive to share the files read only:

/srv/nfs                192.168.1.0/24(ro,fsid=0,no_subtree_check)                                             
/srv/nfs/drive1        192.168.1.0/24(ro,no_subtree_check,insecure)                                           
/srv/nfs/drive2           192.168.1.0/24(ro,no_subtree_check,insecure)                                                  
/srv/nfs/drive3          192.168.1.0/24(ro,no_subtree_check,insecure)

Make sure you update the IP address in each line to match your local subnet. The lines above assume your router is at 192.168.1.1 and will allow any client with a 192.168.1.X IP address to access the files.

When you are done, refresh the list of exported drives:

sudo exportfs -rav

If you want to check the exports at any time, you can use:

sudo showmount -e localhost

When you add this media source in Kodi, select NFS and the NFS share on this box should be automatically detected. Kodi will write media files into the library database as nfs://192.168.1.X/srv/nfs/drive1/media.mkv, not nfs://localhost/srv/nfs/drive1/media.mkv, so the library database will still work from other devices.

Type: 

Add new comment