17.4 Configuring the Automounter

The automounter mounts file systems when they are accessed, rather than maintaining connections for those mounts at all times. When a file system becomes inactive for more than a certain period of time, the automounter unmounts it. Using automounting frees up system resources and improves system performance.

The automounter consists of two components: the autofs kernel module and the automount user-space daemon.

To configure a system to use automounting:

  1. Install the autofs package and any other packages that are required to support remote file systems:

    # yum install autofs
  2. Edit the /etc/auto.master configuration file to define map entries. Each map entry specifies a mount point and a map file that contains definitions of the remote file systems that can be mounted, for example:

    /-          /etc/auto.direct
    /misc       /etc/auto.misc
    /net        -hosts

    Here, the /-, /misc, and /net entries are examples of a direct map, an indirect map, and a host map respectively. Direct map entries always specify /- as the mount point. Host maps always specify the keyword -hosts instead of a map file.

    A direct map contains definitions of directories that are automounted at the specified absolute path. In the example, the auto.direct map file might contain an entry such as:

    /usr/man   -fstype=nfs,ro,soft             host01:/usr/man

    This entry mounts the file system /usr/man exported by host01 using the options ro and soft, and creates the /usr/man mount point if it does not already exist. If the mount point already exists , the mounted file system hides any existing files that it contains.

    As the default file system type is NFS, the previous example can be shortened to read:

    /usr/man   -ro,soft                        host01:/usr/man

    An indirect map contains definitions of directories (keys) that are automounted relative to the mount point (/misc) specified in /etc/auto.master. In the example, the /etc/auto.misc map file might contain entries such as the following:

    xyz       -ro,soft                         host01:/xyz
    cd        -fstype=iso9600,ro,nosuid,nodev        :/dev/cdrom
    abc       -fstype=ext3                           :/dev/hda1
    fenetres  -fstype=cifs,credentials=credfile      ://fenetres/c

    The /misc directory must already exist, but the automounter creates a mount point for the keys xyz, cd , and so on if they does not already exist, and removes them when it unmounts the file system. For example, entering a command such as ls /misc/xyz causes the automounter to the mount the /xyz directory exported by host01 as /misc/xyz.

    The cd and abc entries mount local file systems: an ISO image from the CD-ROM drive on /misc/cd and an ext3 file system from /dev/hda1 on /misc/abc. The fenetres entry mounts a Samba share as /misc/fenetres.

    If a host map entry exists and a command references an NFS server by name relative to the mount point (/net), the automounter mounts all directories that the server exports below a subdirectory of the mount point named for the server. For example, the command cd /net/host03 causes the automounter to mount all exports from host03 below the /net/host03 directory. By default, the automounter uses the mount options nosuid,nodev,intr options unless you override the options in the host map entry, for example:

    /net        -hosts    -suid,dev,nointr

    The name of the NFS server must be resolvable to an IP address in DNS or in the /etc/hosts file.

    For more information, including details of using maps with NIS, NIS+, and LDAP, see the hosts.master(5) manual page.

  3. Start the autofs service, and configure the service to start following a system reboot:

    # service autofs start
    # chkconfig autofs on

You can configure various settings for autofs in /etc/sysconfig/autofs, such as the idle timeout value after which a file system is automatically unmounted.

If you modify /etc/auto.master or /etc/sysconfig/autofs, restart the autofs service to make it re-read these files:

# service autofs restart

For more information, see the automount(8), autofs(5), and auto.master(5) manual pages.