Chapter 39. Mounting file systems on demand
As a system administrator, you can configure file systems, such as NFS, to mount automatically on demand.
39.1. The autofs service
This section explains the benefits and basic concepts of the
autofs service, used to mount file systems on demand.
One drawback of permanent mounting using the
/etc/fstab configuration is that, regardless of how infrequently a user accesses the mounted file system, the system must dedicate resources to keep the mounted file system in place. This might affect system performance when, for example, the system is maintaining NFS mounts to many systems at one time.
An alternative to
/etc/fstab is to use the kernel-based
autofs service. It consists of the following components:
- A kernel module that implements a file system, and
- A user-space service that performs all of the other functions.
autofs service can mount and unmount file systems automatically (on-demand), therefore saving system resources. It can be used to mount file systems such as NFS, AFS, SMBFS, CIFS, and local file systems.
39.2. The autofs configuration files
This section describes the usage and syntax of configuration files used by the
The master map file
autofs service uses
/etc/auto.master (master map) as its default primary configuration file. This can be changed to use another supported network source and name using the
autofs configuration in the
/etc/autofs.conf configuration file in conjunction with the Name Service Switch (NSS) mechanism.
All on-demand mount points must be configured in the master map. Mount point, host name, exported directory, and options can all be specified in a set of files (or other supported network sources) rather than configuring them manually for each host.
The master map file lists mount points controlled by
autofs, and their corresponding configuration files or network sources known as automount maps. The format of the master map is as follows:
mount-point map-name options
The variables used in this format are:
autofsmount point; for example,
- The map source file, which contains a list of mount points and the file system location from which those mount points should be mounted.
- If supplied, these apply to all entries in the given map, if they do not themselves have options specified.
Example 39.1. The /etc/auto.master file
The following is a sample line from
Map files configure the properties of individual on-demand mount points.
The automounter creates the directories if they do not exist. If the directories exist before the automounter was started, the automounter will not remove them when it exits. If a timeout is specified, the directory is automatically unmounted if the directory is not accessed for the timeout period.
The general format of maps is similar to the master map. However, the options field appears between the mount point and the location instead of at the end of the entry as in the master map:
mount-point options location
The variables used in this format are:
This refers to the
autofsmount point. This can be a single directory name for an indirect mount or the full path of the mount point for direct mounts. Each direct and indirect map entry key (mount-point) can be followed by a space separated list of offset directories (subdirectory names each beginning with
/) making them what is known as a multi-mount entry.
- When supplied, these are the mount options for the map entries that do not specify their own options. This field is optional.
This refers to the file system location such as a local file system path (preceded with the Sun map format escape character
:for map names beginning with
/), an NFS file system or other valid file system location.
Example 39.2. A map file
The following is a sample from a map file; for example,
payroll -fstype=nfs4 personnel:/dev/disk/by-uuid/52b94495-e106-4f29-b868-fe6f6c2789b1 sales -fstype=xfs :/dev/disk/by-uuid/5564ed00-6aac-4406-bfb4-c59bf5de48b5
The first column in the map file indicates the
autofs mount point:
payroll from the server called
personnel. The second column indicates the options for the
autofs mount. The third column indicates the source of the mount.
Following the given configuration, the
autofs mount points will be
-fstype= option is often omitted and is generally not needed for correct operation.
Using the given configuration, if a process requires access to an
autofs unmounted directory such as
autofs service automatically mounts the directory.
The amd map format
autofs service recognizes map configuration in the
amd format as well. This is useful if you want to reuse existing automounter configuration written for the
am-utils service, which has been removed from Red Hat Enterprise Linux.
However, Red Hat recommends using the simpler
autofs format described in the previous sections.
39.3. Configuring autofs mount points
This procedure describes how to configure on-demand mount points using the
# yum install autofs
Start and enable the
# systemctl enable --now autofs
Create a map file for the on-demand mount point, located at
/etc/auto.identifier. Replace identifier with a name that identifies the mount point.
- In the map file, fill in the mount point, options, and location fields as described in The autofs configuration files section.
- Register the map file in the master map file, as described in The autofs configuration files section.
Try accessing content in the on-demand directory:
$ ls automounted-directory
39.4. Automounting NFS server user home directories with autofs service
This procedure describes how to configure the autofs service to mount user home directories automatically.
- The autofs package is installed.
- The autofs service is enabled and running.
Specify the mount point and location of the map file by editing the
/etc/auto.masterfile on a server on which you need to mount user home directories. To do so, add the following line into the
Create a map file with the name of
/etc/auto.homeon a server on which you need to mount user home directories, and edit the file with the following parameters:
* -fstype=nfs,rw,sync host.example.com:/home/&i
You can skip
fstypeparameter, as it is
nfsby default. For more information, see
# systemctl reload autofs
39.5. Overriding or augmenting autofs site configuration files
It is sometimes useful to override site defaults for a specific mount point on a client system.
Example 39.3. Initial conditions
For example, consider the following conditions:
Automounter maps are stored in NIS and the
/etc/nsswitch.conffile has the following directive:
automount: files nis
auto.mastermap file contains:
beth fileserver.example.com:/export/home/beth joe fileserver.example.com:/export/home/joe * fileserver.example.com:/export/home/&
The file map
/etc/auto.homedoes not exist.
This section describes the examples of mounting home directories from a different server and augmenting
auto.home with only selected entries.
Example 39.4. Mounting home directories from a different server
Given the preceding conditions, let’s assume that the client system needs to override the NIS map
auto.home and mount home directories from a different server.
In this case, the client needs to use the following
/home /etc/auto.home +auto.master
/etc/auto.homemap contains the entry:
Because the automounter only processes the first occurrence of a mount point, the
/home directory contains the content of
/etc/auto.home instead of the NIS
Example 39.5. Augmenting auto.home with only selected entries
Alternatively, to augment the site-wide
auto.home map with just a few entries:
/etc/auto.homefile map, and in it put the new entries. At the end, include the NIS
auto.homemap. Then the
/etc/auto.homefile map looks similar to:
mydir someserver:/export/mydir +auto.home
With these NIS
auto.homemap conditions, listing the content of the
$ ls /home beth joe mydir
This last example works as expected because
autofs does not include the contents of a file map of the same name as the one it is reading. As such,
autofs moves on to the next map source in the
39.6. Using LDAP to store automounter maps
This procedure configures
autofs to store automounter maps in LDAP configuration rather than in
autofs map files.
LDAP client libraries must be installed on all systems configured to retrieve automounter maps from LDAP. On Red Hat Enterprise Linux, the
openldappackage should be installed automatically as a dependency of the
To configure LDAP access, modify the
/etc/openldap/ldap.conffile. Ensure that the
schemaoptions are set appropriately for your site.
The most recently established schema for storing automount maps in LDAP is described by the
rfc2307bisdraft. To use this schema, set it in the
/etc/autofs.confconfiguration file by removing the comment characters from the schema definition. For example:
Example 39.6. Setting autofs configuration
DEFAULT_MAP_OBJECT_CLASS="automountMap" DEFAULT_ENTRY_OBJECT_CLASS="automount" DEFAULT_MAP_ATTRIBUTE="automountMapName" DEFAULT_ENTRY_ATTRIBUTE="automountKey" DEFAULT_VALUE_ATTRIBUTE="automountInformation"
Ensure that all other schema entries are commented in the configuration. The
automountKeyattribute replaces the
cnattribute in the
rfc2307bisschema. Following is an example of an LDAP Data Interchange Format (LDIF) configuration:
Example 39.7. LDF Configuration
# extended LDIF # # LDAPv3 # base <> with scope subtree # filter: (&(objectclass=automountMap)(automountMapName=auto.master)) # requesting: ALL # # auto.master, example.com dn: automountMapName=auto.master,dc=example,dc=com objectClass: top objectClass: automountMap automountMapName: auto.master # extended LDIF # # LDAPv3 # base <automountMapName=auto.master,dc=example,dc=com> with scope subtree # filter: (objectclass=automount) # requesting: ALL # # /home, auto.master, example.com dn: automountMapName=auto.master,dc=example,dc=com objectClass: automount cn: /home automountKey: /home automountInformation: auto.home # extended LDIF # # LDAPv3 # base <> with scope subtree # filter: (&(objectclass=automountMap)(automountMapName=auto.home)) # requesting: ALL # # auto.home, example.com dn: automountMapName=auto.home,dc=example,dc=com objectClass: automountMap automountMapName: auto.home # extended LDIF # # LDAPv3 # base <automountMapName=auto.home,dc=example,dc=com> with scope subtree # filter: (objectclass=automount) # requesting: ALL # # foo, auto.home, example.com dn: automountKey=foo,automountMapName=auto.home,dc=example,dc=com objectClass: automount automountKey: foo automountInformation: filer.example.com:/export/foo # /, auto.home, example.com dn: automountKey=/,automountMapName=auto.home,dc=example,dc=com objectClass: automount automountKey: / automountInformation: filer.example.com:/export/&