Any NFS share made available by a server can be mounted using various
methods. Of course, the share can be manually mounted, using
themount command, to acquire the exported filesystem
at a particular mount point. However, this requires that the root user
type the mount command every time the system
restarts. In addition, the root user must remember to unmount the
filesystem when shutting down the machine. Two methods of configuring
NFS mounts include modifying the /etc/fstab or
utilizing the autofs service.
Placing a properly formatted line in the
/etc/fstab file has the same effect as manually
mounting the exported filesystem. The /etc/fstab
file is read by the /etc/rc.d/init.d/netfs script
at system startup. The proper filesystem mounts, including NFS, are
put into place.
A sample /etc/fstab line to mount an NFS export
looks like the following:
<server>:</path/of/dir> </local/mnt/point> nfs <options> 0 0 |
The <server-host>
relates to the hostname, IP address, or fully qualified domain name of
the server exporting the filesystem. The
</path/to/shared/directory>
tells the server what export to mount. The
</local/mount/point>
specifies where on the local filesystem to mount the exported
directory. This mount point must exist before
/etc/fstab is read or the mount will fail. The
nfs option specifies the type of filesystem being
mounted.
The <options> area
specifies how the filesystem is to be mounted. For example, if the
options area states rw,suid on a particular mount,
the exported filesystem will be mounted read-write and the user and
group ID set by the server will be used. Note, parentheses are not to
be used here. For more mount options, see the Section called Common NFS Mount Options.
One drawback to using /etc/fstab is that,
regardless of how much you use that mounted filesystem, your system
must dedicate resources to keep that mount in place. This is not a
problem with one or two mounts, but when your 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 will
mount and unmount NFS filesystems automatically, saving resources.
The autofs script, located in
/etc/rc.d/init.d, is used to control
automount 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 all by hand. By running autofs as
a service that starts and stops in designated runlevels, the mount
configurations in the various files can be automatically
implemented. In order to use autofs, you must have
the autofs RPM installed on your system.
The autofs configuration files are arranged in a
parent-child relationship. A main configuration file
(/etc/auto.master) refers mount points on your
system that are linked to a particular map
type, which take 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 like this:
The <mount-point>
indicates where the device or exported filesystem should mount on your
local filesystem. The
<map-type> relates
to the way in which the mount point will be 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, usually named
auto.<mount-point>,
where
<mount-point> is
the mount point designated in auto.master,
contains lines that look like this:
<directory> <mount-options> <host>:<exported-filesystem> |
The <directory>
refers to the directory within the mount point where the exported
filesystem should be mounted. Much like a standard
mount command, the host exporting the filesystem,
as well as the filesystem being exported, are required in the
<host>:<exported-filesystem>
section. To specify particular options to be used when mounting the
exported filesystem, place them in the
<mount-options>
section, separated by commas. For NFS mounts that use
autofs, you should definitely place
-fstype=nfs in the
<mount-options>
section, at a minimum.
While autofs configuration files can be used for a
variety of mounts to many types of devices and filesystems, 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, they 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 internal network. The
auto.master file in this situation would look
similar to this:
This sets up the /home mount point on the local
system to be configured by the /etc/auto.home
file, which may look similar to this:
* -fstype=nfs,soft,intr,rsize=8192,wsize=8192,nosuid server.domain.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.domain.com
system within its exported /home filesystem. 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,
see the Section called Common NFS Mount Options.
Beyond mounting a filesystem via NFS on a remote host, a number of
different options may be specified at the time of the mount that can
make it easier to use. These options can be utilized with manual
mount commands, /etc/fstab
settings, and autofs, and other mounting methods.
The following options are the most popular for NFS mounts:
hard or soft specifies
whether the program using a file via an NFS connection should stop
and wait (hard) for the server to come back
online if the host serving the exported filesystem is unavailable,
or if it should report an error (soft).
If you specify hard, you will not be able to
terminate the process waiting for the NFS communication to resume
unless you also specify the intr option.
If you specify soft, you can set an additional
timeo=<value>
option, where
<value>
specifies the number of seconds to pass before the error is
reported.
intr allows NFS requests to be interrupted if the
server goes down or cannot be reached.
nolock is occasionally required when
connecting to older NFS server. To require locking, use the
lock option.
noexec does not permit the execution of binaries
on the mounted filesystem. This is useful if your Red Hat Linux system is
mounting a non-Linux filesystem via NFS that contains binaries
that will not execute on your machine.
nosuid does not allow set-user-identifier or
set-group-identifier bits to take effect.
rsize=8192 and wsize=8192 may
speed up NFS communication for reads (rsize) and
writes (wsize) by setting a larger data block
size, in bytes, to be transferred at one time. Be careful when
changing these values; some older Linux kernels and network cards
may not work well with larger block sizes.
nfsvers=2 or nfsvers=3
specify which version of the NFS protocol to use.
Many more options are available on the mount man
page, including options to be used when mounting non-NFS filesystems.