Filesystem Administration  «Prev  Next»

Lesson 5Setting up the automounter
ObjectiveConfigure on-demand mounts on Red Hat Enterprise Linux (RHEL) using autofs, verify operation, and understand the optional systemd.automount approach.

Setting up the Automounter on RHEL (autofs)

Automounting mounts a filesystem when it’s first accessed and unmounts it after a period of inactivity. On RHEL 8/9, the standard solution is the autofs service. Use it primarily for NFS, but it can also drive CIFS/SMB and local devices.

Outcomes

1) Install and enable autofs

sudo dnf install -y autofs
sudo systemctl enable --now autofs
sudo systemctl status autofs

2) Choose a map style

3) Define maps in /etc/auto.master (or a drop-in under /etc/auto.master.d/)

# Indirect map of NFS exports; --ghost shows keys before first access
/nfs   /etc/auto.nfs   --timeout=120 --ghost

# Direct map for individual absolute mount points
/-     /etc/auto.direct   --timeout=120

4) Create the map files

Indirect map example: /etc/auto.nfs

# key        mount options                  remote export
proj        -rw,soft,intr                   nfs-srv:/export/projects
data        -ro                             nfs-srv:/export/data
# CIFS example (requires cifs-utils)
share       -fstype=cifs,credentials=/root/.smbcred,vers=3.0 ://filesrv/share

Direct map example: /etc/auto.direct

/opt/reports  -rw,soft,intr  nfs-srv:/export/reports
/backup       -ro            nfs-srv:/export/backup

5) Reload and test

sudo systemctl reload autofs    # or: sudo systemctl restart autofs
ls /nfs/proj                    # first access triggers mount
findmnt /nfs/proj               # verify it is mounted
# After ~120s idle, autofs will unmount automatically

Troubleshooting

Optional: systemd.automount

For simple cases, you can have systemd automount a path without autofs. Either use unit files or a single /etc/fstab entry:

# /etc/fstab (systemd automount)
nfs-srv:/export/projects  /mnt/projects  nfs  noauto,x-systemd.automount,x-systemd.idle-timeout=120  0 0
sudo systemctl daemon-reload
sudo systemctl restart remote-fs.target

Prefer autofs for many dynamic keys, complex maps, or heterogeneous backends. Prefer systemd.automount for a few static mount points already managed by systemd.

Legacy images retained (context)

/etc/auto.master layout
/etc/auto.master ties a mount point (e.g., /nfs) to a map file (e.g., /etc/auto.nfs) and global options (e.g., --timeout, --ghost).
Example map entries
Map file concept: key options target. Legacy examples often showed CD/floppy; today you’ll typically map NFS/CIFS exports using the same syntax.

Checklist

  1. Install autofs and enable the service.
  2. Add entries to /etc/auto.master (indirect and/or direct maps).
  3. Create map files with keys, options, and targets.
  4. Reload the service and access a key to trigger mounts.
  5. Verify with findmnt; watch logs if needed.

SEMrush Software 5 SEMrush Banner 5