NFS Mounted File Systems
What is NFS?
NFS stands for Network File System. A NFS is not your typical filesystem. NFS are a type of filesystem that can be mounted and shared over a network. The advantage of using a NFS filesystem is that you can centrally locate it and then share it out to multiple systems.
To share a directory with another system, we need to add the directory to be shared across the network into a file located in the following path "/etc/exports". The "/etc/exports" file contains a table of local physical filesystems on a NFS server that are accessible to NFS clients. Below is a view of this file before we add our filesystem:
linux-j2w3:~ # cat /etc/exports # See the exports(5) manpage for a description of the syntax of this file. # This file contains a list of all directories that are to be exported to # other computers via NFS (Network File System). # This file used by rpc.nfsd and rpc.mountd. See their manpages for details # on how make changes in this file effective.
In the following example, I am going to use yast to configure an openSUSE 12.3 system as the NFS server and use Ubuntu 12.04 as the NFS client where the mount of the NFS filesystem will be issued. First, we need to create a test directory with some files on our openSUSE system:
linux-j2w3:/testnfs # ls -l total 12 -rw-r--r-- 1 root root 52 Jun 7 21:42 testfile1.txt -rw-r--r-- 1 root root 52 Jun 7 21:43 testfile2.txt -rw-r--r-- 1 root root 52 Jun 7 21:43 testfile3.txt linux-j2w3:/testnfs # cat testfile1.txt testfile2.txt testfile3.txt I am a test file mounted on a openSUSE system Hello I am a test file mounted on a openSUSE system Hello I am a test file mounted on a openSUSE system Hello
Next on the openSUSE system we will use yast to add our directory to the "/etc/exports" file:
Under Network Services, we need to select the option NFS Server.
Accept the following options and click "Next"
Now choose the option to add a directory to export. Here we chose our test directory "testnfs".
Next choose our host options. here I have gone with the default options. You can specify individual servers here.
Finally, click on "Finish", our services will be restarted and our filesystem should now be exported.
Our changes will now be visible within the "/etc/exports" file:
linux-j2w3:/testnfs # cat /etc/exports /testnfs *(fsid=0,crossmnt,ro,root_squash,sync,no_subtree_check)
On our local server (Ubuntu), add a mount point for our NFS filesystem:
john@john-desktop:/$ sudo mkdir nfs john@john-desktop:/$ ls -l /nfs total 0
Before you mount the nfs filesystem you will need the following package to be installed "nfs-common" To install this we issue the command:
sudo apt-get install nfs-common
Now we can issue our mount command:
john@john-desktop:/$ sudo mount 192.168.0.16:/testnfs /nfs john@john-desktop:/$ ls -l /nfs total 12 -rw-r--r-- 1 root root 52 Jun 7 21:42 testfile1.txt -rw-r--r-- 1 root root 52 Jun 7 21:43 testfile2.txt -rw-r--r-- 1 root root 52 Jun 7 21:43 testfile3.txt
Adding our NFS to the mount table
If the nfs mount is to be a permanent feature on your system, you will need to add an entry into the mount table so that it will be mounted each time after a system reboot. The syntax for mounting an NFS filesystem is:
/rmtserver:/testnfs /nfs nfs ro,bg 0 0
The above will automatically mount the nfs from the mount table providing the remote server is running.