autofs on demand.
indirect and direct maps, and idle timeout.
Instead of mounting the NFS share permanently on every box, nfsadmin wants it mounted on first access and unmounted when idle. That is autofs, with both an indirect and a direct map.
nfsadmin liked the NFS share from yesterday but not the idea of every box in the fleet holding it mounted around the clock. What they want is on-demand: the share appears the instant someone touches the path, and quietly unmounts once it goes idle. That is autofs, and the ticket asks for it two ways, an indirect map that manages /shares/team, and a direct map that mounts /data/projects with no parent directory to manage.
Indirect and direct maps do nearly the same job and read nearly the same on paper, which is exactly why people mix them up. The difference lives in two precise spots, the auto.master line and the paths inside the map file, and getting either one wrong is the usual reason a mount silently never happens.
The ticket
sudo dnf install -y autofs nfs-utils showmount -e localhost # confirm the NFS share is exported ls -ld /srv/nfsshare
Concept review. The map files, indirect versus direct.
man 5 auto.master man 5 autofs
/etc/auto.master is the top file. It lists mountpoints and points each at a map file that holds the actual mounts. An indirect map manages a set of subdirectories under one parent, good when several shares live under a common directory. A direct map handles specific full paths that do not share a parent.
/etc/auto.master the master, lists mountpoints and their maps -> /etc/auto.shares an indirect map (parent dir plus sub-mounts) -> /etc/auto.direct a direct map (full path mounts) # in auto.master: /shares /etc/auto.shares indirect, parent is /shares /- /etc/auto.direct direct, the /- is the literal indicator
The indirect map
The map line names a subdirectory, options, and the source. The final path becomes the parent from auto.master plus the subdirectory, here /shares/team.
sudo tee /etc/auto.shares << 'EOF' team -rw,sync localhost:/srv/nfsshare EOF sudo cp /etc/auto.master /etc/auto.master.bak echo "/shares /etc/auto.shares" | sudo tee -a /etc/auto.master
The direct map
A direct map is different in two places. The auto.master line uses the literal /- instead of a parent path, and the map file uses absolute paths on each line instead of relative subdirectories.
sudo tee /etc/auto.direct << 'EOF' /data/projects -rw,sync localhost:/srv/nfsshare EOF echo "/- /etc/auto.direct" | sudo tee -a /etc/auto.master
Activate autofs and test
Start the service, then trigger each mount just by looking into the path. autofs creates and mounts it on demand.
sudo systemctl enable --now autofs sudo systemctl reload autofs # after editing maps # indirect: listing the path triggers the mount ls /shares/team mount | grep team cat /shares/team/welcome.txt # direct: same idea ls /data/projects mount | grep projects
Idle timeout
The default idle timeout is five minutes. Access a path and it mounts, leave it alone and autofs unmounts it. You can tune the timeout in auto.master.
ls /shares/team mount | grep team # mounted # leave it idle past the timeout and it unmounts on its own # set a custom timeout in auto.master: # /shares /etc/auto.shares --timeout=60
Exam questions
Write the command first.
Q1. Install and start autofs so it is enabled at boot.
Q2. Configure an indirect map so access to /nfs/data auto-mounts server:/share read-write.
Q3. Configure a direct map to auto-mount nfsserver:/exports/projects at /projects, then verify by entering it.
Answers.
# A1 sudo dnf install -y autofs sudo systemctl enable --now autofs # A2 (indirect) echo 'data -rw server:/share' | sudo tee /etc/auto.nfs echo '/nfs /etc/auto.nfs' | sudo tee -a /etc/auto.master sudo systemctl reload autofs; ls /nfs/data # A3 (direct) echo '/projects -rw nfsserver:/exports/projects' | sudo tee /etc/auto.direct echo '/- /etc/auto.direct' | sudo tee -a /etc/auto.master sudo systemctl reload autofs; cd /projects && ls
Final checklist: confirm everything works
If every check passes, the ticket is done.
# 1. autofs installed and running systemctl is-active autofs # 2. indirect map mounts at /shares/team on access ls /shares/team; mount | grep team # 3. direct map mounts at /data/projects on access ls /data/projects; mount | grep projects # 4. auto.master has both pointers (/shares and /-) # 5. all three exam commands written from scratch # 6. tracker entry checked off
Reply to nfsadmin: autofs configured. Indirect map mounts on /shares/team, direct map at /data/projects, both auto-unmount on idle, service enabled at boot.