On recent experience, our team frequently needs to transfer or share huge files across multiple raspberry pi and Linux computers in a local area network (LAN). Since it’s not convenient to use scp command by ssh, I set up NFS as a share center to save our time.

What is NFS?

NFS was developed at a time when we weren’t able to share our drives like we are able to today – in the Windows environment. It offers the ability to share the hard disk space of a big server with many smaller clients. Again, this is a client/server environment. While this seems like a standard service to offer, it was not always like this. In the past, clients and servers were unable to share their disk space.

Thin clients have no hard drives and thus need a “virtual” hard-disk. The NFS mount their hard disk from the server and, while the user thinks they are saving their documents to their local (thin client) disk, they are in fact saving them to the server. In a thin client environment, the root, usr, and home partitions are all offered to the client from the server via NFS.

Let’s start!

Network Environment

In my case, Raspberry Pi is NFS client and a Linux PC (Debian) is NFS server, they are in same Local Area Network(LAN).

NFS server: 172.17.168.74
NFS client: 172.17.168.109

For the server, we must ensure the server uses a static IP address and don’t change it (you should edit the network configuration file /etc/network/interfaces), you need to configure the network to static IP in Linux, there is only one server allowed in LAN. For clients, there can be many clients in LAN, clients can use dynamic IP or static IP.

Install NFS in Pi and another Linux

Making your computer an NFS server or client is very easy. Raspberry Pi NFS client needs:

$ sudo apt-get install nfs-common portmap

while a Linux (Debian) NFS server needs:

$ sudo apt-get install nfs-kernel-server nfs-common portmap

Create Shared Folder

In server PC, create a folder that you want to share:

# ‘share’ is the folder that you want to share
$ mkdir /home/zcl/share

In client raspberry pi, we create a folder:

$ mkdir /home/pi/share

NFS Server Configuration

NFS exports from a server are controlled by the file /etc/exports. Each line begins with the absolute path of a directory to be exported, followed by a space-seperated list of allowed clients. Now, we open root Terminal in Linux server:

$ sudo nano /etc/exports

Add following lines at the end to exports file:

/home/zcl/share 172.17.168.*(rw,sync, no_root_squash) 

Press “Ctrl + O” to save and press “Ctrl +X” to quit.

  • rw: read and write

  • no_root_squash: Allows root users on client computers to have root access on the server.

Then restart NFS service in server:

$ sudo /etc/init.d/nfs-kernel-server restart

NFS Client Configuration

NFS volumes can be mounted by root directly from the command line. Before we mount, we can check NFS shared folder in client:

$ sudo showmount –e 172.17.168.74

You will see the following if all setting and network connection is good:

Export List for 172.17.168.74:
/home/zcl/share 172.17.168.*

If you see the above lines, continue to mount:

$ sudo mount 172.17.168.74:/home/zcl/share /home/pi/share

Now you can put files to ‘share’ folder in the server, you will see the same files appear in the client. It is more usual for clients to mount NFS volumes automatically at boot time. NFS volumes can be specified like any others in /etc/fstab:

$ sudo nano /etc/fstab

Add the following lines to fstab:

172.17.168.74:/home/zcl/share /home/pi/share nfs rsize=8192,wsize=8192,timeo=14,intr

Press “Ctrl + O” to save and press “Ctrl +X” to quit.

Now NFS volumes can be mounted automatically at boot-time.