An autofs mount keeps an NFS export off the active mount table until a process opens the configured path. That avoids boot delays and idle network mounts on Linux clients that only need the export during certain jobs.
Autofs reads a master map, then a map file that describes the real filesystem behind each watched path. This configuration uses a direct map so /mnt/projects stays as the path users open, while autofs mounts files.example.net:/srv/nfs/projects only when that path is accessed.
A manual test with the same export should work before autofs is introduced. Replace the host, export, and mount path with site values, and keep the final checks in the flow because map syntax errors and server-side export problems often appear only when the path is first touched.
Steps to automount an NFS export with autofs:
- Install the autofs and NFS client packages.
$ sudo apt update $ sudo apt install autofs nfs-common
On RHEL-family systems, install autofs and nfs-utils with sudo dnf install autofs nfs-utils.
- Create the local path that will become the autofs trigger.
$ sudo mkdir -p /mnt/projects
Use a path that is empty or already dedicated to this NFS export. A direct map lets autofs manage the exact path instead of creating a key under a parent directory.
- Mount the export manually once to confirm the server, export path, and client package are working before adding autofs.
$ sudo mount -t nfs4 files.example.net:/srv/nfs/projects /mnt/projects $ findmnt /mnt/projects TARGET SOURCE FSTYPE OPTIONS /mnt/projects files.example.net:/srv/nfs/projects nfs4 rw,relatime,vers=4.2 $ sudo umount /mnt/projects
- Create a master-map drop-in for the direct map.
$ sudo vi /etc/auto.master.d/projects.autofs
The filename must end with .autofs because packaged autofs configurations normally include only that suffix from /etc/auto.master.d.
- Register the direct map and set an idle timeout.
/- /etc/auto.projects --timeout=60
The /- master-map entry tells autofs that the map file contains full mount paths. --timeout=60 lets autofs unmount idle entries after about one minute when no process is using them.
- Create the map file named in the master map.
$ sudo vi /etc/auto.projects
- Add the NFS export entry to the map file.
/mnt/projects -fstype=nfs4,rw files.example.net:/srv/nfs/projects
For Kerberos-protected exports, add the matching security option, such as sec=krb5p, and confirm the client has valid Kerberos credentials before triggering the mount.
- Check that automount can read the new map.
$ sudo automount -m autofs dump map information =========================== global options: none configured Mount point: /- source(s): instance type(s): file map: /etc/auto.projects /mnt/projects | -fstype=nfs4,rw files.example.net:/srv/nfs/projects
The map dump should show Mount point: /- and the full /mnt/projects key for a direct map.
- Enable and start the autofs service, then reload it after the map change.
$ sudo systemctl enable --now autofs.service $ sudo systemctl reload autofs.service
No output from the reload command means systemd accepted the reload request. Use sudo systemctl restart autofs.service instead when the unit does not support reload on a nonstandard distribution.
- Confirm that the service is active.
$ systemctl is-active autofs.service active
- Access the path to trigger the NFS mount.
$ ls /mnt/projects README.txt reports
The first access can pause while autofs contacts the NFS server and starts the mount.
- Verify that /mnt/projects is mounted from the expected export.
$ findmnt /mnt/projects TARGET SOURCE FSTYPE OPTIONS /mnt/projects files.example.net:/srv/nfs/projects nfs4 rw,relatime,vers=4.2
If the path stays unmounted or the command hangs, inspect sudo journalctl -u autofs.service -b and confirm the server still exports /srv/nfs/projects to the client.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.