Introduction
Instead of using the samba protocol, that is more resource consuming and is needed only when the network files should be shared including Windows machines or other desktops or anyway for some specific needs, a better solution to share folders between several linux machines is through the NFS file system.
Server install and setting
Installing the server side on raspian should be take in account a couple of issues that affect this Debian distro. First of all we have two options to install the server: nfs-server and nfs-kernel-server but only the second is well working in this Debian distro without issues. Debian documentation site only says that this is strongly suggested on the most recent distributions The problem is that this choice should be warned because also the other NFS server alternative installs on raspian without problem.
Installation
So we proceed installing the NFS server, the NFS common utilities and the portmapper:
$>sudo apt-get install nfs-kernel-server nfs-common portmap
Note: the portmap package (port mapping service) must be installed but it is probably already present on the system; it depends on what other packages you have previously installed in your Raspberry. So don't worry if after the installation you see that the package is already installed and if you read that there is a problem starting the nfs server.
Configuration
After the packages installation has been finished we should configure the NFS server instructing how to share the folders that will be mounted by the remote linux machines, editing the exports file
$>sudo nano /etc/exports
Every folder that should be shared with the NFS clients should be listed in this configuration file. The following configuration line is related to the case we are managing; for further details on the exports conifguration file syntax read the exports NFS configuration documentation.
/home/stream xxx.xxx.xxx.xxx/0(rw,sync,no_subtree_check,no_root_squash)
Despite what I have found on the Internet in many place It is mandatory to specify the NFS server IP and the subnet /0 (for the case of a single device sharing a folder).
Restart and fine tuning
At this point, we should restart the NFS service with the command
$>sudo service nfs-kernel-server restart
Surprisingly the server seems unable to restart showing a message like the response listed below
$>sudo service nfs-kernel-server restart [ ok ] Stopping NFS kernel daemon: mountd nfsd. [ ok ] Unexporting directories for NFS kernel daemon.... [ ok ] Exporting directories for NFS kernel daemon.... [....] Starting NFS kernel daemon: nfsd [warn] Not starting: portmapper is not running ... (warning).
Showing the RPC call status with the command
$> rpcinfo -p
we see something like the following:
<br>rpcinfo: can't contact portmapper: RPC: Remote system error - No such file or directory
This occurs because of the issue mentioned above. The port mapping service is correctly installed on the system but seems that raspian is not enabled to start it by default during the reboot. The workaround to solve this issue is to explicitly add the binding of the port mapping to the boot sequence startup via rc.d configuration with the following command:
$>sudo update-rc.d rpcbind enable && sudo update-rc.d nfs-common enable
At this point after the reboot the system works correctly. Test restarting the NFS service after a reboot
$>sudo /etc/init.d/nfs-kernel-server restart
to see the correct restart sequence notifications on the terminal
pi@RPIslave2 ~ $ sudo /etc/init.d/nfs-kernel-server restart
[ ok ] Stopping NFS kernel daemon: mountd nfsd.
[ ok ] Unexporting directories for NFS kernel daemon....
[ ok ] Exporting directories for NFS kernel daemon....
[....] Starting NFS kernel daemon: nfsdrpc.nfsd: address family inet6 not supported by protocol TCP
mountdrpc.mountd: svc_tli_create: could not open connection for udp6
rpc.mountd: svc_tli_create: could not open connection for tcp6
rpc.mountd: svc_tli_create: could not open connection for udp6
rpc.mountd: svc_tli_create: could not open connection for tcp6
rpc.mountd: svc_tli_create: could not open connection for udp6
rpc.mountd: svc_tli_create: could not open connection for tcp6
Take in account that he warnings related to the tcp6 and udp6 depends on the use of the IPV4 only and not the IPV6 protocol in the network, so it doesn't affect the server functionality. For permanent mounting the mount parameters should be added to the /etc/fstab file of the client computer.
Client installation and setting
Client installation is almost simple as we only need to install the portmapper and the nfs client.
Install the packages
$>sudo apt-get install nfs-common
Then create the folder where the remote mount should be mapped
$>sudo mkdir -p <client mount folder>
Now mount the remote folder (with the full path) on the client local folder on the client machine.
$>sudo mount xxx.xxx.xxx.xxx:/<server full path shared folder> <client mount folder>
That's all!
With the mount command you will see an output like this (showing my specific case as an example)
$>mount /dev/root on / type ext4 (rw,noatime,data=ordered) devtmpfs on /dev type devtmpfs (rw,relatime,size=437856k,nr_inodes=109464,mode=755) tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=88432k,mode=755) tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) tmpfs on /run/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=176860k) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) /dev/mmcblk0p5 on /boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro) rpc_pipefs on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime) /dev/mmcblk0p3 on /media/SETTINGS_ type ext4 (rw,nosuid,nodev,relatime,data=ordered,uhelper=udisks) 192.168.5.3:/home/pi/stream on /mnt/stream type nfs4 (rw,relatime,vers=4.0,rsize=65536,wsize=65536,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.5.2,local_lock=none,addr=192.168.5.3)
Where the last line shows the remote /home/stream folder mounted on the local /mnt/stream folder You will see also the mounted folder, that is as a matter of fact is very similar to a removable media with the disk free df command as shown in the example below.
$> df -h Filesystem Size Used Avail Use% Mounted on rootfs 877G 4.3G 828G 1% / /dev/root 877G 4.3G 828G 1% / devtmpfs 428M 0 428M 0% /dev tmpfs 87M 304K 87M 1% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 173M 0 173M 0% /run/shm /dev/mmcblk0p5 60M 15M 45M 25% /boot /dev/mmcblk0p3 27M 442K 25M 2% /media/SETTINGS_ 192.168.5.3:/home/pi/stream 5.8G 2.6G 2.9G 48% /mnt/stream