9.4. NFS Client Configuration Files

NFS shares are mounted on the client side using the mount command. The format of the command is as follows:

mount -o <options> <host>:</remote/export> </local/directory>

Replace <options> with a comma separated list of options for the NFS file system (refer to Section 9.4.3 Common NFS Mount Options for details). Replace <host> with the remote host, </remote/export> with the remote directory being mounted, and replace </local/directory> with the local directory where the remote file system is to be mounted.

Refer to the mount man page for more details.

If accessing an NFS share by manually issuing the mount command, the file system must be remounted manually after the system is rebooted. Red Hat Enterprise Linux offers two methods for mounting remote file systems automatically at boot time: the /etc/fstab file or the autofs service.

9.4.1. /etc/fstab

The /etc/fstab file is referenced by the netfs service at boot time, so lines referencing NFS shares have the same effect as manually typing the mount command during the boot process.

A sample /etc/fstab line to mount an NFS export looks like the following example:

<server>:</remote/export> </local/directory> nfs <options> 0 0

Replace <server> with the hostname, IP address, or fully qualified domain name of the server exporting the file system.

Replace </remote/export> with the path to the exported directory.

Replace </local/directory;> with the local file system on which the exported directory is mounted. This mount point must exist before /etc/fstab is read or the mount fails.

The nfs option specifies the type of file system being mounted.

Replace <options> with a comma separated list of options for the NFS file system (refer to Section 9.4.3 Common NFS Mount Options for details). Refer to the fstab man page for additional information.

9.4.2. autofs

One drawback to using /etc/fstab is that, regardless of how infrequently a user accesses the NFS mounted file system, the system must dedicate resources to keep the mounted file system in place. This is not a problem with one or two mounts, but when the system is maintaining mounts to a dozen systems at one time, overall system performance can suffer. An alternative to /etc/fstab is to use the kernel-based automount utility, which can mount and unmount NFS file systems automatically, saving resources.

The autofs service is used to control the automount command through the /etc/auto.master primary configuration file. While automount can be specified on the command line, it is more convenient to specify the mount points, hostname, exported directory, and options in a set of files rather than typing them manually.

The autofs configuration files are arranged in a parent-child relationship. The main configuration file (/etc/auto.master) lists mount points on the system that are linked to a particular map type, which takes the form of other configuration files, programs, NIS maps, and other less common mount methods. The auto.master file contains lines referring to each of these mount points, organized in the following manner:

<mount-point> <map-type>

The <mount-point> element specifies the location of the mount on the local file system. The <map-type> specifies how the mount point is mounted. The most common method for auto mounting NFS exports is to use a file as the map type for the particular mount point. The map file is usually named auto.<mount-point>, where <mount-point> is the mount point designated in auto.master. A line within map files to mount an NFS export looks like the following example:

</local/directory>  -<options>  <server>:</remote/export>

Replace </local/directory;> with the local file system on which the exported directory is mounted. This mount point must exist before the map file is read, else the mount fails.

Replace <options> with a comma separated list of options for the NFS file system (refer to Section 9.4.3 Common NFS Mount Options for details). Be sure to include the hyphen character (-) immediately before the options list.

Replace <server> with the hostname, IP address, or fully qualified domain name of the server exporting the file system.

Replace </remote/export> with the path to the exported directory.

Replace <options> with a comma separated list of options for the NFS file system (refer to Section 9.4.3 Common NFS Mount Options for details).

While autofs configuration files can be used for a variety of mounts to many types of devices and file systems, they are particularly useful in creating NFS mounts. For example, some organizations store a user's /home/ directory on a central server via an NFS share, then configure the auto.master file on each of the workstations to point to an auto.home file containing the specifics for how to mount the /home/ directory via NFS. This allows the user to access personal data and configuration files in their /home/ directory by logging in anywhere on the network. The auto.master file in this situation would look similar to this:

/home   /etc/auto.home

This sets up the /home/ mount point on the local system to be configured by the /etc/auto.home file, which looks similar to the example below:

*  -fstype=nfs,soft,intr,rsize=8192,wsize=8192,nosuid,tcp  server.example.com:/home

This line states that any directory a user tries to access under the local /home/ directory (due to the asterisk character) should result in an NFS mount on the server.example.com system on the mount point /home/. The mount options specify that each /home/ directory NFS mounts should use a particular collection of settings. For more information on mount options, including the ones used in this example, refer to Section 9.4.3 Common NFS Mount Options.

For more information about autofs configuration files, refer to the auto.master man page.

9.4.3. Common NFS Mount Options

Beyond mounting a file system via NFS on a remote host, a number of different options can be specified at the time of the mount that can make it easier to use. These options can be used with manual mount commands, /etc/fstab settings, and autofs.

The following are options commonly used for NFS mounts:

Many more options are listed on the mount man page, including options for mounting non-NFS file systems.