CONFIGURE AUTOFS (AUTOMOUNT) IN LINUX

CONFIGURE AUTOFS (AUTOMOUNT) IN LINUX

Introduction

Autofs also referred as Automount is a nice feature in linux used to mount the filesystems automatically on user’s demand. There are two ways available in linux by which we can mount the file system i.e. /etc/fstab and another one is Autofs. /etc/fstab is used to mount the filesystems automatically at when system bootsup and Autofs is also doing the same thing.

Difference Between /etc/fstab and Autofs (AutoMount)

You might thinking that if both are doing the same thing then why to use Autofs (Automount) instade of /etc/fstab. and what is the difference between /etc/fstab and Autofs. Here I am going to explain you what is the exact difference between /etc/fstab and Autofs.

As we know that /etc/fstab is used for permanent mounting of file systems but it will be useful only if you have less mount points connected to your /etc/fstab file but if you are working on a large organisation and have so many mount points linked to your /etc/fstab file then in that case your overall system’s performance will be get effected.

But Autofs mounts the file systems on user’s demand. Bydefault the mount point’s configured in Autofs is in unmounted state till the user access the mount point, once user try to access the mount point it will mount automatically and if user dont use the mount point for some time then it will automatically go to unmount state.

For example if we have Two NFS (Network File System) exported share drives and configured in Autofs to automatically mount in directory named /myautoshares for users. In that case till the user didnt access to the mountpoint it will be on unmounted state and you unable to see any mounted filesystem in /myautoshares directory, once user access the mount point it will automatically get mounted and will be in mount state till user uses that mountpoint. once user stop using that mount point it will unmount automatically. Here we are using Autofs to mount the NFS exported shares automatically.

Note : We can set time for after what time the filesystem unmount automatically once user stop using the mountpoint.

Follow the below Steps to configure Autofs

Step : 1 Requires Packages

Before we start the configuration of Autofs we have to install required packages. The main package we have to install is autofs.xxx.xxx.rpm. you can check if the packages is already installed or not by using below command.

# rpm -qa | grep -i autofs

Install the autofs packages by using yum command as shown 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: centos.myfahim.com
 * extras: centos.myfahim.com
 * updates: centosc6.centos.org
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
================================================================================
Installing:
 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 

Installed:
  autofs.x86_64 1:5.0.7-56.el7                                                  

Complete!

As we can see the autofs package installed successfully, we can confirm the autofs packages installation status by using below command.

# rpm -qa | grep -i autofs
autofs-5.0.7-56.el7.x86_64

Step : 2 Configure /etc/auto.master

Here we are going to use NFS exported shares with Autofs to automatically mount it. To check the NFS exports just run the below command.

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

As we can see above we have two NFS exports i.e. /package and /database. Now create a directory for Autofs to mount the filesystems.

[root@oracledb ~]# mkdir /myautoshares/

The main configuration files of Autofs is /etc/auto.master where we can link the file in which we are going to mention all NFS mount points. The syntax to enter in /etc/auto.master file is shown below :

<Mount-Point> <File where we mention the Filesystems>  <Time after which the filesystem will Unmount>

Note : It is not mandatory to mention timeout syntax in /etc/auto.master configuration file but It is recomended to do so.

Configuration part is Highlighted in Blue Color.

[root@oracledb ~]# 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 Autofs will mount the filesystems
  • /etc/auto.sharedfs – In this file we have to mention the file systems which will automatically mounted by Autofs
  • –timeout=35 – This is states that if user will don’s use the mount point for 35 Seconds, then it will unmounted automatically.

Also Read :

  • HOW TO RESET FORGOTTEN ROOT PASSWORD IN RHEL/CENTOS 7
  • HOW TO INSTALL AND CONFIGURE CACHING-ONLY DNS SERVER WITH BIND IN RHEL/CENTOS
  • HOW TO CONFIGURE SLAVE DNS SERVER WITH BIND ( SECONDARY DNS SERVER ) IN LINUX

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

Now we have to create /etc/auto.sharedfs file which we have mentioned in /etc/auto.master file to mention the file systems.

Just copy the /etc/auto.misc file as /etc/auto.sharedfs as shown below. /etc/auto.misc file is the sample file which is created automatically after autofs package installation.

[root@oracledb ~]# cp /etc/auto.misc /etc/auto.sharedfs

Now just edit the /etc/auto.sharedfs file and mention the filesystems to be mount, the Syntax shown below :

<Name of the Share>  <File System> <NFS Share Path/Drive Path/Syntax>

Note : Configuration Part are Highlighted in Blue Color.

[root@oracledb ~]# 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           ftp.example.org:/pub/linux
#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     192.168.0.104:/packages
database        -fstype=nfs     192.168.0.104:/database

We are done with configuration part, now let’s go ahead and start the autofs service using below command.

[root@oracledb ~]# systemctl start autofs.service

Now it’s time for testing. So let’s list our Autofs mount point i.e. /myautoshares using ls -l command.

[root@oracledb ~]# ls -l /myautoshares/
total 0

As we can see above currently there is no active mounts are available because as i explained earlier till user don’t access the mount it will be in unmount state.

Now let’s go ahead and access our first NFS export i.e. /packages by using below command.

[root@oracledb ~]# cd /myautoshares/packages/
[root@oracledb packages]# ls
file1.txt  file2.txt  file3.txt  file4.txt  file5.txt

As we can see above we able to access the NFS mount successfully. Now let’s again list our mount point i.e. /myautoshares and I am sure it will definitely show the NFS mount points shared by Autofs. Refer the Output below.

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

Now let’s access our second NFS export i.e. /database.

[root@oracledb ~]# cd /myautoshares/database
[root@oracledb database]# ls
test1.txt  test2.txt  test3.txt  test4.txt  test5.txt

As we can see on the output below we able to access our both NFS Exported shares.

[root@oracledb 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

Now if user don’t use access this NFS shares for 35 Seconds it will be automatically unmounted.

So this is how we can configure Autofs (Automount) in Linux, If you found this article useful then Please Like Us, Subscribe Us or If you have something to say then feel free to comment on the comment box below.

 

+133
Tweet
Share27
Share1
Pin3
Stumble
Shares 64
Share

Balamukunda Sahu

This is Balamukunda Sahu the Founder and Editor of ELinuxBook have 5+ years of Industrial Experience. I thankful to all our website viewers who encourage me to write quality posts and articals, Keep visit to our site and I will bring all latest Linux Tutorials, Updates and News for you.

You may also like...

  • 0

    HOW TO INSTALL AND CONFIGURE CACHING-ONLY DNS SERVER WITH BIND IN RHEL/CENTOS

    January 6, 2017

     by Balamukunda Sahu · Published January 6, 2017 · Last modified January 26, 2017

  • 2

    HOW TO SET/CHANGE GRUB BOOT LOADER PASSWORD IN REDHAT/CENTOS/FEDORA

    October 9, 2016

     by Balamukunda Sahu · Published October 9, 2016 · Last modified January 26, 2017

  • 0

    HOW TO CONFIGURE LINUX LVM (LOGICAL VOLUME MANAGER) USING SOFTWARE RAID 5

    June 14, 2017

     by Balamukunda Sahu · Published June 14, 2017

2 Responses

  • Comments2
  • Pingbacks0
  1. Jose Prakash says:
    May 4, 2017 at 5:45 am

    excellent article to understand autofs

    Reply
    • Balamukunda Sahu says:
      May 31, 2017 at 10:17 am

      Thank You so much for finding the article useful.

      Reply

Leave a Reply to Balamukunda Sahu Cancel reply

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

  • Next story HOW TO CONFIGURE RAID 5 (SOFTWARE RAID) IN LINUX USING MDADM
  • Previous story STEP BY STEP INSTALLATION OF CENTOS 7 WITH SCREENSHOTS

Categories

  • Linux Basic Commands
  • Linux Basic Tool's
  • Linux HowTo's
  • Linux Tutorials
  • Monitoring Tools
  • Programming Languages
  • RHEL 7
  • ubuntu
  • Webmin Guides

Recent Comments

  • Balamukunda Sahu on HOW TO INSTALL PYTHON 3.6 ON UBUNTU 16.04
  • Balamukunda Sahu on HOW TO INSTALL PYTHON 3.6 ON UBUNTU 16.04
  • Sanjay on HOW TO INSTALL PYTHON 3.6 ON UBUNTU 16.04
  • Balamukunda Sahu on HOW TO CONFIGURE AUTOFS (AUTOMOUNT) IN LINUX
  • Balamukunda Sahu on HOW TO INSTALL ORACLE VM VIRTUALBOX IN UBUNTU 16.04

Recent Posts

  • HOW TO INSTALL VLC MEDIA PLAYER IN REDHAT/CENTOS
  • HOW TO INSTALL NGINX SERVER IN REDHAT/CENTOS/FEDORA
  • HOW TO INSTALL WEBMIN WITH SSL IN LINUX – A WEB INTERFACE TO CONFIGURE LINUX
  • HOW TO CONFIGURE LINUX LVM (LOGICAL VOLUME MANAGER) USING SOFTWARE RAID 5
  • HOW TO CONFIGURE LOCAL YUM REPOSITORY PACKAGE INSTALLER USING APACHE SERVER

Categories

  • Linux Basic Commands
  • Linux Basic Tool's
  • Linux HowTo's
  • Linux Tutorials
  • Monitoring Tools
  • Programming Languages
  • RHEL 7
  • ubuntu
  • Webmin Guides

Elinuxbook: Linux Tutorials, Guides, Howtos, Tips and Tricks © 2018. All Rights Reserved.

Without our permission Content/Work of this site cannot be Republished either Online or Offline, .