Linux allows you to mount filesystems statically in the /etc/fstab file. However, with the approach, the mount point is always mapped even when you’re not using the mapped resource. To improve automounting of NFS/Samba shares, a tool called autofs was created. This allows automounting of NFS/Samba shares to conserve bandwidth and offer better overall performance compared to mounting statically. autofs is a program for automatically mounting directories on an as-needed basis. This is good in that it will only mount resources when needed which improves the systems’ performance. To get started with autofs, follow the steps below:

Install autofs on Ubuntu

Before you can start using autofs, make sure it’s installed in Ubuntu. If not, run the commands below to install it. Now that autofs is installed, continue below to use it. autofs uses a configuration file as the framework for completing tasks. It looks up a map file located at /etc/auto.master by default. The lines in auto. master describes a mount and the location of its map. auto.master file field:

Mount point Location of the map file Map optional

Auto mounting NFS shares

For this tutorial, we’re going to be using autofs to mount a directory or folder via NFS on our remote server. The first thing we’ll do is enter a mount point for our NFS share on our local server at /months and configures it according to the settings specified in /etc/auto.nfs. Run the commands below to open the auto.master file Then add the line below at the end of the file to define the /mynfs share on the local host. Save the file and exit. Next, run the commands below to create the file which contains the automounter map we specified above. This file should contain a separate line for each NFS share if you’re going to be defining multiple NFS shares. The format for a line is {mount point} [{mount options}] {location}. So to mount a remote server to our /mynfs path on the local host, add this line in the /etc/auto.NFS file. If your NFS shares use NFSv4, you need to tell autofs about that. When you’re done editing the files, run the commands below to reload autofs configurations. After reloading, check the service status. It should display a similar line as shown below: That should do it. Conclusion: This post showed you how to use autofs to mount NFS shares on Ubuntu for better improvement over static mount. If you find any error above, please use the form below to report. You may also like the post below: