Chapter 20. Mounting file systems on demand


As a system administrator, you can configure file systems, such as NFS, to mount automatically on demand.

20.1. The autofs service

The 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.

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:

  • A kernel module that implements a file system.
  • A user-space service that performs all of the other functions.

For more information, see the autofs(8) man page on your system.

20.2. The autofs configuration files

This section describes the usage and syntax of configuration files used by the autofs service.

The master map file

The 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:

mount-point  map-name  options
Copy to Clipboard Toggle word wrap

The variables used in this format are:

mount-point
The autofs mount point; for example, /mnt/data.
map-file
The map source file, which contains a list of mount points and the file system location from which those mount points should be mounted.
options
If supplied, these apply to all entries in the given map, if they do not themselves have options specified.

Example 20.1. The /etc/auto.master file

The following is a sample line from /etc/auto.master file:

/mnt/data  /etc/auto.data
Copy to Clipboard Toggle word wrap

Map files

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
Copy to Clipboard Toggle word wrap

The variables used in this format are:

mount-point
This refers to the autofs mount 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.
options
When supplied, these options are appended to the master map entry options, if any, or used instead of the master map options if the configuration entry append_options is set to no.
location
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 20.2. A map file

The following is a sample from a map file; for example, /etc/auto.misc. To use this map file for mounting under /misc, add the following to the master map file /etc/auto.master:

/misc		/etc/auto.misc
Copy to Clipboard Toggle word wrap

The /etc/auto.misc file contains:

payroll  -fstype=nfs4  personnel:/exports/payroll
sales    -fstype=xfs   :/dev/hda4
Copy to Clipboard Toggle word wrap

The first column in the map file indicates the autofs mount point: sales and 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 /home/payroll and /home/sales. The -fstype= option is often omitted and is not needed if the file system is NFS, including mounts for NFSv4 if the system default is NFSv4 for NFS mounts.

Using the given configuration, if a process requires access to an autofs unmounted directory such as /home/payroll/2006/July.sxc, the autofs service automatically mounts the directory.

The amd map format

The 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.

For more information, see the: * autofs(5), autofs.conf(5), and auto.master(5) man pages on your system * /usr/share/doc/autofs/README.amd-maps file

20.3. Configuring autofs mount points

Configure on-demand mount points by using the autofs service.

Prerequisites

  • Install the autofs package:

    # dnf install autofs
    Copy to Clipboard Toggle word wrap
  • Start and enable the autofs service:

    # systemctl enable --now autofs
    Copy to Clipboard Toggle word wrap

Procedure

  1. 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.
  2. In the map file, enter the mount point, options, and location fields as described in The autofs configuration files section.
  3. Register the map file in the master map file, as described in The autofs configuration files section.
  4. Allow the service to re-read the configuration, so it can manage the newly configured autofs mount:

    # systemctl reload autofs.service
    Copy to Clipboard Toggle word wrap
  5. Try accessing content in the on-demand directory:

    # ls automounted-directory
    Copy to Clipboard Toggle word wrap

You can configure the autofs service to retrieve automount maps stored in an LDAP directory.

Prerequisites

  • The autofs and openldap packages are installed.
  • A Kerberos-capable service is running for secure authentication.

Procedure

  1. To configure LDAP access, modify the /etc/openldap/ldap.conf file. Ensure that the BASE and URI options are set to reflect the appropriate server and base for locating automount entries.
  2. In the /etc/autofs.conf file configure the LDAP schema for automount maps. By default, autofs will check the commonly used schemas in the order given in the configuration file:

    #
    # Define the LDAP schema to used for lookups
    #
    # If no schema is set autofs will check each of the schemas
    # below in the order given to try and locate an appropriate
    # basdn for lookups. If you want to minimize the number of
    # queries to the server set the values here.
    #
    #map_object_class = nisMap
    #entry_object_class = nisObject
    #map_attribute = nisMapName
    #entry_attribute = cn
    #value_attribute = nisMapEntry
    #
    # Other common LDAP naming
    #
    #map_object_class = automountMap
    #entry_object_class = automount
    #map_attribute = ou
    #entry_attribute = cn
    #value_attribute = automountInformation
    #
    #map_object_class = automountMap
    #entry_object_class = automount
    #map_attribute = automountMapName
    #entry_attribute = automountKey
    #value_attribute = automountInformation
    Copy to Clipboard Toggle word wrap
    Note

    You can also set these values explicitly to marginally reduce LDAP queries. You can write the attributes in both lower and upper cases in the /etc/autofs.conf file.

  3. The most recently established schema for storing automount maps in LDAP is described by the rfc2307bis draft. To use this schema, configure it in the /etc/autofs.conf file by uncommenting and setting the appropriate value for the ldap_schema option. For example, if you are using a non-standard schema or need to override the default behavior, you can specify the relevant schema attributes in the /etc/autofs.conf file. The following values correspond to commonly used schema settings such as those from the rfc2307bis draft:

    default_map_object_class = automountMap
    default_entry_object_class = automount
    default_map_attribute = automountMapName
    default_entry_attribute = automountKey
    default_value_atrribute = automountInformation
    Copy to Clipboard Toggle word wrap

    Note that the autofs automatically detects standard schemas, and specifying these settings is typically only necessary in custom or mixed-schema environments. If used, only one complete set of schema definitions should be active.

  4. If you choose to specify a custom schema in the configuration, ensure that only one complete set of schema-related entries is active. Comment out any other to avoid conflicts. In the rfc2307bis schema, the automountKey attribute replaces the cn attribute used in the older rfc2307 schema. The following is an example of a corresponding LDAP Data Interchange Format (LDIF) configuration:

    # auto.master, example.com
    dn: automountMapName=auto.master,dc=example,dc=com
    objectClass: top
    objectClass: automountMap
    automountMapName: auto.master
    
    # /home, auto.master, example.com
    dn: automountMapName=auto.master,dc=example,dc=com
    objectClass: automount
    automountKey: /home
    automountInformation: auto.home
    
    # auto.home, example.com
    dn: automountMapName=auto.home,dc=example,dc=com
    objectClass: automountMap
    automountMapName: auto.home
    
    # 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/&
    Copy to Clipboard Toggle word wrap
  5. To allow authentication from an LDAP server, edit the /etc/autofs_ldap_auth.conf file:

    1. Change authrequired to yes.
    2. Set the principal to the Kerberos host principal for the LDAP server, host/FQDN@REALM. The principal name is used to connect to the directory as part of GSS client authentication:

      <autofs_ldap_sasl_conf
           usetls="no"
           tlsrequired="no"
           authrequired="yes"
           authtype="GSSAPI"
      clientprinc="host/server.example.com@EXAMPLE.COM"/>
           secret="<ldap password>"/>
      Copy to Clipboard Toggle word wrap

      For more information about host principal, see Using canonicalized DNS host names in IdM. You can also run klist -k to get the exact host principal information.

Configure the autofs service to mount user home directories automatically.

Prerequisites

  • The autofs package is installed.
  • The autofs service is enabled and running.

Procedure

  1. Define the mount point and the local automount map by editing the /etc/auto.master file on the server where you want to mount user home directories, and add:

    /home /etc/auto.home
    Copy to Clipboard Toggle word wrap
  2. Create the local automount map file /etc/auto.home on the server where you need to mount user home directories, and add:

    * -fstype=nfs,rw,sync host.example.com:/home/&
    Copy to Clipboard Toggle word wrap

    You can skip fstype parameter, as it is nfs by default. For more information, see autofs(5) man page on your system.

  3. Reload the autofs service:

    # systemctl reload autofs
    Copy to Clipboard Toggle word wrap

It is sometimes useful to override site defaults for a specific mount point on a client system.

Initial conditions:

For example, consider the following conditions:

  • nsswitch tells autofs which services to check for maps.
  • The map you want to augment or add to is named auto.home.
  • The auto.home map is stored in ldap and the /etc/nsswitch.conf has the following directive:

    automount: files ldap
    Copy to Clipboard Toggle word wrap
  • The /etc/auto.master map file contains:

    /home /etc/auto.home
    Copy to Clipboard Toggle word wrap
  • The map /etc/auto.home` file contains:

    *  fileserver.example.com:/export/home/&
    Copy to Clipboard Toggle word wrap

Using plus map inclusion:

To read the centrally managed auto.home map through nsswitch, remove the the wildcard map entry * fileserver.example.com:/export/home/& from the local /etc/auto.home file and replace it with +auto.home.

Note

Plus map inclusion can only be used in local maps. When autofs encounters the files source through a plus map inclusion, it skips it if the included map name is identical to the map currently being read. In this case, since both are auto.home, autofs proceeds to the next source defined in nsswitch.conf, which is ldap. If a wildcard map entry is present in the map, it does not affect the directory listing, even when browse mode is enabled. This is because autofs does not know what the wildcard might match when a lookup is done. As a result, it cannot create mount point directories in advance.

Overriding or Adding Entries

To override or add specific entries locally, place them before the +auto.home line in /etc/auto.home. For example the /etc/auto.home file would look like:

mydir  someserver:/export/mydir

+auto.home
Copy to Clipboard Toggle word wrap
Note

To display local entries like mydir when listing /home, enable browse mode by setting browse_mode = yes in /etc/autofs.conf. Wildcard entries (like *) do not appear in directory listings unless accessed.

Mount a file system on-demand using the automount systemd units when mount point is defined in /etc/fstab. You have to add an automount unit for each mount and enable it.

Procedure

  1. Add desired fstab entry as documented in Persistently mounting file systems. For example:

    /dev/disk/by-id/da875760-edb9-4b82-99dc-5f4b1ff2e5f4  /mount/point  xfs  defaults  0 0
    Copy to Clipboard Toggle word wrap
  2. Add x-systemd.automount to the options field of entry created in the previous step.
  3. Load newly created units so that your system registers the new configuration:

    # systemctl daemon-reload
    Copy to Clipboard Toggle word wrap
  4. Start the automount unit:

    # systemctl start mount-point.automount
    Copy to Clipboard Toggle word wrap

Verification

  1. Check that mount-point.automount is running:

    # systemctl status mount-point.automount
    Copy to Clipboard Toggle word wrap
  2. Check that automounted directory has desired content:

    # ls /mount/point
    Copy to Clipboard Toggle word wrap

For more information, see Managing systemd

Mount a file system on-demand using the automount systemd units when mount point is defined by a mount unit. You have to add an automount unit for each mount and enable it.

Procedure

  1. Create a mount unit. For example:

    mount-point.mount
    [Mount]
    What=/dev/disk/by-uuid/f5755511-a714-44c1-a123-cfde0e4ac688
    Where=/mount/point
    Type=xfs
    Copy to Clipboard Toggle word wrap
  2. Create a unit file with the same name as the mount unit, but with extension .automount.
  3. Open the file and create an [Automount] section. Set the Where= option to the mount path:

    [Automount]
    Where=/mount/point
    [Install]
    WantedBy=multi-user.target
    Copy to Clipboard Toggle word wrap
  4. Load newly created units so that your system registers the new configuration:

    # systemctl daemon-reload
    Copy to Clipboard Toggle word wrap
  5. Enable and start the automount unit instead:

    # systemctl enable --now mount-point.automount
    Copy to Clipboard Toggle word wrap

Verification

  1. Check that mount-point.automount is running:

    # systemctl status mount-point.automount
    Copy to Clipboard Toggle word wrap
  2. Check that automounted directory has desired content:

    # ls /mount/point
    Copy to Clipboard Toggle word wrap

For more information, see Managing systemd

Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2025 Red Hat