Ubuntu - Using NFS

Using NFS on Ubuntu

Ubuntu version 14.04

Accessing exports/shares on another machine

View exports/shares

The showmount command is part of the NFS common package. It provides a way to list file systems that have been exported on an NFS server.

showmount -e

If the package is not installed, a notice is typically shown that gives the details for installing the required package. In this example the package is installed using apt-get.

mikeb@mb-u14vm1:~$ showmount
The program 'showmount' is currently not installed. You can install it by typing:
sudo apt-get install nfs-common
mikeb@mb-u14vm1:~$ sudo apt-get install nfs-common

After installing the package, you can execute showmount with the -e option followed by the hostname or IP address for the NFS server. This will list all the file sysystems exported on that server.

mikeb@mb-u14vm1:~$ showmount -e
Export list for
/rfs/mbtestnfs1 *
/rfs/nfsv4      *
/rfs/nfs        *

The following example creates a directory in /mnt to use as a mount point for one of the exports from the NFS server.

mikeb@mb-u14vm1:~$ sudo mkdir /mnt/mbtestnfs1
mikeb@mb-u14vm1:~$ ls /mnt

Mounting an export/share

Command example:

sudo mount example.hostname.com:/ubuntu /local/ubuntu

This is the syntax I used for the mount I tested based on recoomendations from the server product.

sudo mount -t nfs -o rw,nolock,hard,intr,nfsvers=3,tcp,rsize=131072,wsize=131072,bg /mnt/mbtestnfs1

You can enter the mount command to verify that the NFS export can be mounted and accessed. After you verify the command works as expected, it is necessary to add the information to the systems vfstab to mount the file system at boot.

mikeb@mb-u14vm1:~$ sudo mount -t nfs -o rw,nolock,hard,intr,nfsvers=3,tcp,rsize=131072,wsize=131072,bg /mnt/mbtestnfs1
mikeb@mb-u14vm1:~$ df -h
Filesystem                        Size  Used Avail Use% Mounted on
/dev/mapper/u1404lts--1--vg-root   36G  1.3G   33G   4% /
none                              4.0K     0  4.0K   0% /sys/fs/cgroup
udev                              2.0G  4.0K  2.0G   1% /dev
tmpfs                             396M  516K  395M   1% /run
none                              5.0M     0  5.0M   0% /run/lock
none                              2.0G     0  2.0G   0% /run/shm
none                              100M     0  100M   0% /run/user
/dev/sda1                         236M   37M  187M  17% /boot     455T     0  455T   0% /mnt/mbtestnfs1

Setting up exports/shares

Check to see if server is installed

dpkg -l | grep nfs-kernel-server

Install NFS server

If the NFS server is not installed, the package will need to be installed and the service will need to be started.

sudo apt-get install nfs-kernel-server

After the NFS server package is installed, the file systems that are to be shared (exported) are added to the /etc/eports file. The syntax is described on the man page and includes options for acces control as well as other important settings.

  • edit /etc/exports
  • restart NFSd
sudo service nfs-kernel-server start