Lesson 5 | Setting up the automounter |
Objective | Configure on-demand mounts on Red Hat Enterprise Linux (RHEL) using autofs , verify operation, and understand the optional systemd.automount approach. |
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.
autofs
.systemd.automount
instead.autofs
sudo dnf install -y autofs sudo systemctl enable --now autofs sudo systemctl status autofs
/nfs
) containing many on-demand submounts./opt/reports
)./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
/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
/etc/auto.direct
/opt/reports -rw,soft,intr nfs-srv:/export/reports /backup -ro nfs-srv:/export/backup
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
journalctl -u autofs -f
automount -m
sudo automount -f -v
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.
/nfs
) to a map file (e.g., /etc/auto.nfs
) and global options (e.g., --timeout
, --ghost
).key options target
. Legacy examples often showed CD/floppy; today you’ll typically map NFS/CIFS exports using the same syntax.autofs
and enable the service./etc/auto.master
(indirect and/or direct maps).findmnt
; watch logs if needed.