This page will show how to run a NFS server on your ESPRESSObin running either Ubuntu 14.04 or Ubuntu 16.04. We will be using an NFS server to share a directory located on our ESPRESSObin with other devices on the same network but will not cover any authentication security measures.
Installation
Install the NFS server on ESPRESSObin running Ubuntu file system with:
root@localhost:~# apt-get install nfs-kernel-server
On the client side check for your distribution's required NFS packages. For Ubuntu:
espressobin@buildserver:~$ sudo apt-get install nfs-common
Configuration
For example, let us say we have a /home/music/ directory on our ESPRESSObin board which contains some music we want to export:
root@localhost:/home# ls music/ 01 - Space Oddity.mp3 02 - The Man Who Sold The World.mp3 04. One.mp3 08. Fade To Black.mp3
To export it, we need an export file system first. We will keep all our exports in a single directory we will name espressobin_export from which on we will mount other directories using the --bind option as will be shown later. So, first we create the export file system:
root@localhost:~# mkdir -p /espressobin_export/music
We will be accessing the NFS share from the client without LDAP/NIS authentication, so it is important that both /export and /export/music have 777 permissions and have nobody:nogroup credentials. Additional configurations are needed when using authentication but they will not be covered here.
To set these permissions, do:
root@localhost:/# chmod -R 777 espressobin_export/ root@localhost:/# chown -R nobody:nogroup espressobin_export/
Now we mount the "real" /home/music directory to our "export" one with:
root@localhost:/# mount --bind /home/music /espressobin_export/music
The /espressobin_export/music/ directory now of course contains files from /home/music/ directory:
root@localhost:/# ls espressobin_export/music/ 01 - Space Oddity.mp3 02 - The Man Who Sold The World.mp3 04. One.mp3 08. Fade To Black.mp3
To automatically mount this directory on every reboot, add this line to /etc/fstab:
/home/music /espressobin_export/music none bind 0 0
At this stage, check that both the server (ESPRESSObin) and the client (your laptop/computer) have correct domain names in /etc/idmapd.conf file, meaning that they have the same Mapping section:
[Mapping] Nobody-User = nobody Nobody-Group = nogroup
Now to export our directories to a local network (in our case 192.168.22.0/24), in the ESPRESSObin console we head to /etc/exports file and add the following lines:
/espressobin_export 192.168.22.0/24(rw,fsid=0,no_subtree_check,sync) /espressobin_export/music 192.168.22.0/24(rw,nohide,no_subtree_check,sync)
As can be seen above, the syntax for adding clients looks something like this:
directory_to_export client(share_option1,...,share_option)
where our options are:
- rw → Allowing the client both read and write access to the shared directories.
- fsid=0 → Specifying /home/espressobin_export as our root directory.
- no_subtree_check → This option prevents subtree checking.
- sync → Forcing NFS to write changes to disk before replying.
See exports man page for more options on how to configure share exporting. Now we export the shares using:
root@localhost:/home# exportfs -ra
Note that you may need to issue this command every time you update /etc/exports file. You may also need to restart the nfs-kernel-server service:
root@localhost:/home# service nfs-kernel-server restart
On the client (your Linux machine) we now simply mount what we have exported previously. We do that with:
espressobin@buildserver:~$ sudo mount -o proto=tcp,port=2049 192.168.22.1:/espressobin_export /media
where 192.168.22.1 is the IP address of our ESPRESSObin NFS server, /espressobin_export is the afore-defined directory we want to export, and /media is where we want this directory to be mounted on our Linux machine. Of course, now you can access your exported files, for example:
espressobin@buildserver:~$ cd /media espressobin@buildserver:~$ ls music/ 01 - Space Oddity.mp3 02 - The Man Who Sold The World.mp3 04. One.mp3 08. Fade To Black.mp3