How to Mount NFS Filesystems with autofs on Ubuntu Linux

|

|

This tutorial guides students and new users on mounting NFS filesystems on Ubuntu 20.04 | 18.04 using the autofs automounting tool. The article details how to install autofs, create a mount point for NFS shares, set up autofs configurations, and reload autofs systems. autofs offers better overall performance compared to static mounting by conserving bandwidth…

This brief tutorial shows students and new users how to mount NFS filesystems with the autofs automounting tool on Ubuntu 20.04 | 18.04.

Linux allows you to mount filesystems statically in the /etc/fstab file. However, the approach always maps the mount point even when 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 because it only mount resources when needed, improving the systems’ performance.

To get started with autofs, follow the steps below:

Install autofs on Ubuntu

Before using autofs, make sure it’s installed in Ubuntu. If not, run the commands below to install it.

sudo apt update
sudo apt-get install autofs

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 auto lines. 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 will be using autofs to mount a directory or folder via NFS on our remote server.

We’ll first enter a mount point for our NFS share on our local server at /months and configure it according to the settings specified in /etc/auto.nfs.

Run the commands below to open the auto.master file

sudo nano /etc/auto.master

Then add the line below at the end of the file to define the /mynfs share on the local host.

/mynfs   /etc/auto.nfs

Save the file and exit.

Next, run the commands below to create the file which contains the automounter map we specified above.

sudo nano /etc/auto.nfs

This file should contain a separate line for each NFS share if you define 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.

/mynfs   -fstype=nfs4   ubuntu2004:/remote_path

If your NFS shares use NFSv4, you must tell autofs about that.

When you’re done editing the files, run the commands below to reload autofs configurations.

sudo service autofs reload

After reloading, check the service status.

sudo service autofs status

It should display a similar line as shown below:

● autofs.service - Automounts filesystems on demand
     Loaded: loaded (/lib/systemd/system/autofs.service; enabled; vendor preset>
     Active: active (running) since Sun 2021-01-17 13:30:49 CST; 20min ago
       Docs: man:autofs(8)
    Process: 5569 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUC>
   Main PID: 3856 (automount)
      Tasks: 4 (limit: 4654)
     Memory: 1.4M
     CGroup: /system.slice/autofs.service
             └─3856 /usr/sbin/automount --pid-file /var/run/autofs.pid

Jan 17 13:30:49 ubuntu2004 systemd[1]: Starting Automounts filesystems on deman>

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:

Like this:



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.