AUTOFS

AutoFS is a utility that mount local or remote drives only when they are accessed and if you don’t use them, they will be unmounted automatically after a certain time (as configured).

Difference Between /etc/fstab and Autofs (AutoMount)

As we know that /etc/fstab is used for permanent mounting of file systems but it has advantage only if you have limited 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  gets effected.

But Autofs mounts the file systems on user’s demand. By default, the mount point 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 don’t use the mount point for some time then it will automatically go to unmounted state.

How to Configure AUTOFS in RHEL Machine

Prerequisites

  • You should have sudo permissions as a user
  • autofs package should be installed on your machine


Configuration Files used in Autofs

  • /etc/auto.master
  • /etc/auto.misc  (name of this file can be anything)
  • /etc/sysconfig/autofs


Steps for configuring Autofs :

In our example we will mount the NFS share using autofs. NFS share ‘/db_backup‘ is exported from NFS Server (192.168.1.21). We are going to mount this nfs share on CentOS 7 machine

1 : Edit the Master map file (/etc/auto.master)

[root@devopscheetah ~]# cat /etc/auto.master | grep -v “#”
/dbstuff /etc/auto.nfsdb –timeout=180

  • /dbstuff should be a directory on your client system.
  • NFS Share will automatically umount after 180 seconds or 3 minutes if user doesn’t access the share.
  • /etc/auto.nfsdb is our MAP File where we will configure the NFS server and Mount details.


2 : Configure map file ‘/etc/auto.nfsdb’

[root@devopscheetah ~]# cat /etc/auto.nfsdb
db_backup -fstype=nfs,rw,soft,intr 192.168.1.21:/db_backup

  • db_backup is a directory where ‘192.168.1.21:/db_backup’ is mounted.
  • -fstype=nfs is the file system type & ‘rw,soft,intr’ are mount options.
  • 192.168.1.21:/db_backup’ is nfs share location.


3 : Start the auotfs service

[root@devopscheetah ~]# systemctl start autofs.service
[root@devopscheetah ~]# systemctl enable autofs.service


4 : Now try to access the mount point

Mount point of nfs share will be ‘/dbstuff/db_backup’. When we try access the mount point then autofs service will mount nfs share automatically and the content of db_backup directory will be accessible.

 

 

Check out : How we can create VPC/Subnets on AWS ?

Leave a Reply

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