Linux Advanced 02 — NFS and On-Demand Mounting with AutoFS

Linux course index · Linux Advanced category · Lesson 2 of 9

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Create an indirect AutoFS map and distinguish a running automounter from a successful NFS mount.

Concepts and setup

AutoFS mounts a filesystem on access and may expire an idle mount. The master map associates a base directory with a map file. An indirect map’s key becomes a child of that base. The example adapts the site’s AutoFS and NFS mounting walkthrough.

You need a disposable client with autofs and NFS client tools and a second VM with an authorized read-only NFSv4 export at 192.168.56.20:/labdocs. Substitute your real lab values, and put README.txt in the export. The client master map must include /etc/auto.master.d for the following layout to work.

Configure the map and trigger the mount

# Use file names not already present in the lab.
printf '/mnt/oe-share /etc/auto.oe-share --timeout=60\n' |
  sudo tee /etc/auto.master.d/oe-share.autofs
printf 'docs -fstype=nfs,ro,vers=4 192.168.56.20:/labdocs\n' |
  sudo tee /etc/auto.oe-share
sudo systemctl restart autofs
sudo automount -m
cat /mnt/oe-share/docs/README.txt
findmnt -T /mnt/oe-share/docs -o SOURCE,TARGET,FSTYPE,OPTIONS

Possible output

...
Mount point: /mnt/oe-share
...
Hello from lab NFS
SOURCE                 TARGET              FSTYPE OPTIONS
192.168.56.20:/labdocs  /mnt/oe-share/docs  nfs4   ro,...

Reading the file triggers a lookup. An autofs mount on the base is not proof that the remote export is mounted.

Inspect the journal and remove the lab map

journalctl -b -u autofs -n 20 --no-pager
cd "$HOME"
sudo rm /etc/auto.master.d/oe-share.autofs /etc/auto.oe-share
sudo systemctl restart autofs
findmnt -rn -t nfs,nfs4 -o TARGET

Possible output

... autofs.service: Started ...
# The lab mount under /mnt/oe-share is absent from the final list.

Close programs that are holding files or directories open before cleanup. Do not remove pre-existing map files.

Questions only

Quick-check questions

  1. What triggers the indirect mount?
  2. Why is systemctl status not sufficient to verify an export?

Assessment questions

  1. Decode the key, client path, and export in this map.
  2. If the map loads but cat times out, what should you inspect?
  3. How can you prove the export is mounted read-only without attempting to write?

Questions and answers

Quick-check answers

  1. What triggers the indirect mount?
    Answer — An access to the key under the configured base directory.
  2. Why is systemctl status not sufficient to verify an export?
    Answer — The service can run with a broken map, inaccessible server, or invalid export.

Assessment answer key

  1. Decode the key, client path, and export in this map.
    Answer — The key is docs, its client path is /mnt/oe-share/docs, and its export is 192.168.56.20:/labdocs.
  2. If the map loads but cat times out, what should you inspect?
    Answer — Check the lab route, the server and NFS service, export authorization, path, and autofs journal.
  3. How can you prove the export is mounted read-only without attempting to write?
    Answer — Inspect the actual mount options with findmnt and confirm ro.

Source articles on this site

Continue the course

Previous lesson 01 — LVM and Controlled Filesystem Growth. Next lesson 03 — SELinux Contexts, Booleans, and Denials.

Linux course index · Linux Advanced category · Lesson 2 of 9

Leave a Reply