Folder sharing with NFS

If you’re running out of space on your Pi’s SD memory card or want to share folders under Linux, you should consider using the Linux network file system (NFS). All you need to do is to install rpcbind, nfs-common and nfs-kernel-server on your Pi.

On a freshly installed you must enable the rpcbind service before you can start the nfs-kernel-server:

$ sudo update-rc.d rpcbind enable

The network file system is particularly useful if you want to merge folders across your home network which reside on different systems. In order to listen to my ogg/mp3 music collection I’ve attached a Raspberry Pi to the AUX input of my Hi-Fi equipment. The collection resides on a USB stick and can be accessed with the music player daemon (mpd) and Minion, so that I can use my smartphone as a remote. Another music collection resides on my AVM Fritz Box, which acts as a mediaserver and NAS.

Server configuration

NFS shared folders are configured in the file /etc/exports. It is possible to restrict access for specific hosts or a subnet. In order to set file permissions correctly, user and group id’s should match on the client and server. If they do not match, you must tell nfs which uids and gids should be used for accessing the folders on your server. (ids of the user “pi” can be revealed by typing “id” into the console).

/media/usb0 (rw,async,no_subtree_check,fsid=0,anonuid=0,anongid=0,all_squash)

Afterwards, check with

sudo exportfs

if the directory was properly exported. If you cannot see the right directory, it might be necessary to restart the nfs-kernel-server service and/or to refresh the nfs exports with:

sudo exportfs -a
sudo exportfs -r

In case that you can see the exported filesystem, but are still unable to mount it from your client, make sure that the portmapper or rpcbind service is enabled and running.

Client configuration

To mount an nfs volume just add the network path and mount point to your /etc/fstab. If you observe a connection timeout, select the NFS version supported by your server with the option nfsvers=4 or nfsvers=3.

nfs_server:/media/usb0 /media/nfs nfs proto=tcp,nfsvers=3,noatime,auto,_netdev,rw,intr 0 0
Notify of
Inline Feedbacks
View all comments