How to configure automount on Linux

In this article you will learn how to configure automount on Linux. autofs also called automount, is a nice feature in Linux that is used to automatically mount filesystems at the user’s request. There are two ways in Linux that we can mount the filesystem; H. / etc / fstab and another one is autofs, / etc / fstab is used to automatically load the file systems when the system starts up and autos do the same.

Difference between / etc / fstab and autofs (AutoMount)

You might think that if both do the same, automount should be used instead of / etc / fstab. and what is the difference between / etc / fstab and autofs? Here I explain the exact difference between / etc / fstab and autofs.

As we know, / etc / fstab is used to permanently mount filesystems, but is only useful when there are fewer mount points associated with your / etc / fstab file, but if you work in a large organization and over so many Mount points have points associated with your / etc / fstab file, in which case they affect the performance of your overall system.

However, autos mounts the file systems as the user needs. By default, the mount point configured in autos is not provisioned until the user accesses the mount point. When a user tries to access the mount point, it is automatically provisioned. If the user does not use the mount point for a long period of time, it is automatically deployed and automatically switches to standby mode.

For example, if two Network File System (NFS) shares have been exported and configured in autos to be automatically posted to a directory named / myautoshares for users. In this case, until the user has not accessed the mount point, the file system becomes unmounted and you cannot see a mounted file system in the / myautoshares directory. As soon as the user accesses the mount point, it is automatically mounted and is in the mount state until the user uses this mount point. When the user stops using this mount point, the mount is automatically dismounted. Here we use autos to automatically provide the NFS exported shares.

Note: We can set the time after which the file system automatically unmounts once the user stops using the mount point.

How to configure automount on Linux

Follow the steps below to configure autos

Step: 1 Requires packages

Before we start configuring autos, we need to install the necessary packages. The main package we need to install is You can use the following command to check whether the packages are already installed or not.

# rpm -qa | grep -i autofs

Install the autofs packages with the yum command (see below).

# yum -y install autofs   # Install Autofs Package
Loaded plugins: fastestmirror, langpacks
base                                                     | 3.6 kB     00:00     
extras                                                   | 3.4 kB     00:00     
updates                                                  | 3.4 kB     00:00     
updates/7/x86_64/primary_db                                | 2.2 MB   00:08     
Loading mirror speeds from cached hostfile
 * base:
 * extras:
 * updates:
Resolving Dependencies
--> Running transaction check
---> Package autofs.x86_64 1:5.0.7-56.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

 Package         Arch            Version                    Repository     Size
 autofs          x86_64          1:5.0.7-56.el7             base          782 k

Transaction Summary
Install  1 Package

Total size: 782 k
Installed size: 4.9 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 1 pre-existing rpmdb problem(s), 'yum check' output follows:
ipa-client-4.1.0-18.el7.centos.0.1.x86_64 has missing requires of autofs
  Installing : 1:autofs-5.0.7-56.el7.x86_64                                 1/1 
  Verifying  : 1:autofs-5.0.7-56.el7.x86_64                                 1/1 

  autofs.x86_64 1:5.0.7-56.el7                                                  


Since the autofs package was successfully installed, we can check the installation status of the autofs package with the following command.

# rpm -qa | grep -i autofs

Step: 2 Configure /etc/auto.master

Here we’re going to use NFS exported shares with autos to automatically deploy them. To check the NFS exports, simply run the following command.

# showmount -e
Export list for
/packages *
/database *

As we can see above, we have two NFS exports, i.e. /Package and /Database, Now create a directory for autos to mount the file systems.

[[email protected] ~]# mkdir /myautoshares/

The main configuration files of autos are /etc/auto.master Here we can link the file in which we will mention all NFS mount points. The syntax to be entered /etc/auto.master File is shown below:

Note: It is not mandatory to mention it time-out Syntax in the configuration file /etc/auto.master, but this is recommended.

The configuration part is highlighted in blue.

[[email protected] ~]# nano /etc/auto.master

# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
/misc   /etc/auto.misc

### My AutoShares ###

/myautoshares   /etc/auto.sharedfs      --timeout=35

Where :

  • / myautoshares – This is the directory where autos mount the file systems
  • /etc/auto.sharedfs – In this file we have to mention the file systems that are automatically mounted by autofs
  • –Timeout = 35 – This means that if the user does not use the mount point for 35 seconds, the mount will be dismounted automatically.

Step: 3 Create and configure /etc/auto.sharedfs

Now we have to do it /etc/auto.sharedfs File that we mentioned in /etc/auto.master File to mention the file systems.

Just copy that /etc/auto.misc File as /etc/auto.sharedfs As shown below. /etc/auto.misc file is the sample file that is created automatically after the autofs package is installed.

[[email protected] ~]# cp /etc/auto.misc /etc/auto.sharedfs

Now just edit it /etc/auto.sharedfs File and mention the file systems as mount, the syntax is shown below:

Note: The configuration part is highlighted in blue.

[[email protected] ~]# nano /etc/auto.sharedfs

# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage

cd              -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom

# the following entries are samples to pique your imagination
#linux          -ro,soft,intr 
#boot           -fstype=ext2            :/dev/hda1
#floppy         -fstype=auto            :/dev/fd0
#floppy         -fstype=ext2            :/dev/fd0
#e2floppy       -fstype=ext2            :/dev/fd0
#jaz            -fstype=ext2            :/dev/sdc1
#removable      -fstype=ext2            :/dev/hdd

packages        -fstype=nfs
database        -fstype=nfs

We are done with the configuration part. Now you can start the autofs service with the following command.

[[email protected] ~]# systemctl start autofs.service

Now it’s time to test it. So let’s list our autos mount point, i.e. H. / Myautoshares, with the command ls -l.

[[email protected] ~]# ls -l /myautoshares/
total 0

As we can see above, no active mounts are currently available because, as I explained, it is in standby mode until the user does not access the mount.

Let us now access our first NFS export with the following command. H. / Packages, too.

[[email protected] ~]# cd /myautoshares/packages/
[[email protected] packages]# ls
file1.txt  file2.txt  file3.txt  file4.txt  file5.txt

As we can see above, we can successfully access the NFS mount. Now we list our mount point again, i.e. Refer to the issue below.

[[email protected] ~]# ls -l /myautoshares/
total 0
drwxrwxrwx. 2 root root 86 Feb  1 22:45 packages

Let’s now access our second NFS export, i.e. H. / Database.

[[email protected] ~]# cd /myautoshares/database
[[email protected] database]# ls
test1.txt  test2.txt  test3.txt  test4.txt  test5.txt

As we can see in the output below, we can access both shares exported by NFS.

[[email protected] database]# ls -l /myautoshares/
total 0
drwxrwxrwx. 2 root root 86 Feb  1 21:42 database
drwxrwxrwx. 2 root root 86 Feb  1 22:45 packages

If the user does not access these NFS shares for 35 seconds, the deployment is automatically dismounted.

Read Also – Change the Runlevel in Rhel 7 / Centos 7 with Systemd using Systemctl

That’s all. In this article we explained how to configure autos (automount) under Linux. I hope you like this article. If you like this article, just share it. If you have any questions about this article, please comment.