Skip to main content
Instead of mounting NFS shares permanently at boot — which can slow startup or cause the system to hang if the NFS server is unavailable — use autofs for service-based, on-demand mounts. autofs is an automounter daemon that mounts filesystems only when they are accessed (on-demand), rather than at boot. This makes NFS mounts more reliable and fault-tolerant: a down NFS server will not block or delay system startup because autofs attempts mounts only when a user or process accesses the mount point.
A dark-themed slide titled "Autofs" showing a central card labeled "autofs" with three blue gradient circles above it and two rounded info boxes reading "Service-based Automounter" and "Automatically mounts filesystems when accessed." A gear icon and an exclamation mark are visible near the bottom.
This guide uses the example NFS server 10.0.2.15 exporting under /srv/nfs/. Replace the IP and export paths to match your environment. These examples assume a RHEL-like system (CentOS, Fedora, Rocky, Alma).

What you’ll configure

  • Install and enable the autofs service.
  • Create a master map file (/etc/auto.master.d/master.autofs) that references:
    • a direct map (/etc/auto.direct), and
    • an indirect map (/etc/auto.indirect).
  • Test that NFS exports are mounted on-demand when accessed.

Installation and enabling the autofs service

Install autofs:
Enable and start autofs (use --now to enable and start in one step):
Sample status output:

Configuring the autofs master file and maps

autofs uses a master map that points to one or more map files. Modern RHEL-like distributions allow dropping files with the .autofs suffix into /etc/auto.master.d/. Create a file /etc/auto.master.d/master.autofs that tells autofs where to find the direct and indirect maps. Create /etc/auto.master.d/master.autofs:
  • /- (direct map) means each key in /etc/auto.direct is a full absolute path to be mounted.
  • /indirect (indirect map) means subdirectories under /indirect are created on-demand according to keys found in /etc/auto.indirect.

Direct map: absolute mount points

Create /etc/auto.direct. Direct maps use absolute mount points. Example: mount the export 10.0.2.15:/srv/nfs/share at /auto-direct:
  • The left column is the absolute mount point.
  • The middle field lists mount options (-rw,sync).
  • The right side is the NFS server export.

Indirect map: keyed subdirectories under a parent

Create /etc/auto.indirect. Indirect maps use keys that become subdirectories under the parent (/indirect in the master file). Using a wildcard allows matching multiple keys:
  • * matches any subdirectory name under /indirect.
  • & expands to the matched key, so accessing /indirect/central mounts 10.0.2.15:/srv/nfs/share/autofs-indirect/central.
Restart autofs to apply configuration:

Quick reference: map files

Testing the automounts

After restarting autofs, autofs creates the mount-point directories even before the NFS mounts occur. Verify the directories exist:
Direct map behavior: accessing the absolute mount point triggers a mount:
Indirect map behavior: the parent directory may appear empty until a keyed subdirectory is accessed. Accessing a keyed subdirectory triggers autofs to mount only that export:
Each subdirectory under /indirect is mounted individually and on-demand when first accessed. For example, accessing /indirect/east will mount 10.0.2.15:/srv/nfs/share/autofs-indirect/east. This on-demand mount behavior avoids slow or stalled boots caused by unreachable network shares.
If the NFS server is unreachable, autofs will not block boot; however, processes that try to access a missing mount point will hang until the mount times out or the server becomes available. Ensure NFS server accessibility, firewall rules, and SELinux contexts are correct for your environment.

Troubleshooting tips

  • Confirm the NFS server and exported paths are reachable: showmount -e 10.0.2.15.
  • Check journalctl -u autofs for autofs-specific logs and errors.
  • If mounts fail, verify NFS client packages (nfs-utils) are installed and that the firewall allows NFS traffic.
  • For SELinux-denied mounts, inspect ausearch or audit.log and apply required boolean / context fixes.

Summary

You have configured autofs to manage both direct and indirect NFS automounts:
  • Installed and enabled the autofs service.
  • Created a master map file (/etc/auto.master.d/master.autofs) referencing a direct map (/etc/auto.direct) and an indirect map (/etc/auto.indirect).
  • Used direct maps for absolute mount points and indirect maps for keyed on-demand subdirectories with wildcard matching and & substitution.
  • Verified that NFS exports are mounted only when accessed, improving boot reliability and reducing dependency on network availability.
By using autofs, systems relying on network-attached storage can avoid slow or stalled boot behavior caused by static NFS mounts.
A dark-themed slide or interface with the word "Summary" on the left and a panel on the right listing storage-related topics. Items include "Basic storage," "Managing Swap Space," "Logical Volumes," and "Working with Network Attached Storage."

Watch Video

Practice Lab