The following procedure illustrates how to configure autofs to auto-mount an NFS share available on your network. It assumes you are familiar with NFS exports.
- Edit the master map file /etc/auto.master:
sudo vim /etc/auto.master
Add a new entry for the new NFS mount at the end of /etc/auto.master:
It tells autofs that the base mount point is /nfs, the NFS shares are specified in the /etc/auto.nfs map, and that all shares in this map will be automatically unmounted after 10 seconds of inactivity.
- Create a new map file for NFS shares:
sudo vim /etc/auto.nfs
/etc/auto.nfs normally contains a separate line for each NFS share.
Add the line describing the mount point and the NFS share network address:
The above line means that the /home/geeko/doc/export directory on the jupiter.com host will be auto-mounted to the /nfs/export directory on the local host (/nfs is taken from the auto.master map) when requested.
The /nfs/export directory will be created automatically by autofs.
- Optionally comment out the related line in /etc/fstab if you previously mounted the same NFS share statically. The line should look similar to this:
#jupiter.com:/home/geeko/doc/export /nfs/export nfs defaults 0 0
- Reload autofs and check if it works:
sudo systemctl restart autofs
# ls -l /nfs/export
drwxr-xr-x 6 1001 users 4096 Oct 25 08:56 ./
drwxr-xr-x 3 root root 0 Apr 1 09:47 ../
drwxr-xr-x 5 1001 users 4096 Jan 14 2013 .images/
drwxr-xr-x 10 1001 users 4096 Aug 16 2013 .profiled/
drwxr-xr-x 3 1001 users 4096 Aug 30 2013 .tmp/
drwxr-xr-x 4 1001 users 4096 Oct 25 08:56 SLE-12-manual/
If you can see the list of files on the remote share, then autofs is functioning.