Autofs is a service in Linux like operating system which automatically mounts the file system and remote shares when it is accessed. Main advantage of autofs is that you don’t need to mount file system at all time, file system is only mounted when it is in demand.
Autofs service reads two files Master map file ( /etc/auto.master ) and a map file like /etc/auto.misc or /etc/auto.xxxx.
In ‘/etc/auto.master’ file we have three different fields :
/<Mount-Point> <Map-file> <Timeout-Value>
In map file (/etc/auto.misc or /etc/auto.xxxx) also we have three different fields:
<Mount-Point> <Mount-Options> <Location_of_File System>
In this article we will mount the NFS share using autofs. NFS share ‘/db_backup‘ is exported from Fedora NFS Server (192.168.1.21). We are going to mount this nfs share on CentOS 7 & Ubuntu Linux using autofs.
Steps to mount nfs share using Autofs in CentOS 7
Step:1 Install autofs package.
Install the autofs package using below yum command if it is not installed.
[root@linuxtechi ~]# rpm -q autofs package autofs is not installed [root@linuxtechi ~]# yum install autofs
Step:2 Edit the Master map file (/etc/auto.master )
Add the following line .
[root@linuxtechi ~]# vi /etc/auto.master /dbstuff /etc/auto.nfsdb --timeout=180
Note : Mount point ‘/dbstuff’‘ must exist on your system. If not then create a directory ‘mkdir /dbstuff‘. NFS Share will automatically umount after 180 seconds or 3 minutes if don’t perform any action on the share.
Step:2 Create a map file ‘/etc/auto.nfsdb’
Create a map file and add the following line.
[root@linuxtechi ~]# vi /etc/auto.nfsdb db_backup -fstype=nfs,rw,soft,intr 192.168.1.21:/db_backup
Save and exit the file.
Where :
- db_backup is a mount point.
- -fstype=nfs is the file system type & ‘rw,soft,intr’ are mount options.
- ‘192.168.1.21:/db_backup’ is nfs share location.
Step:3 Start the auotfs service.
[root@linuxtechi ~]# systemctl start autofs.service [root@linuxtechi ~]# systemctl enable autofs.service ln -s '/usr/lib/systemd/system/autofs.service' '/etc/systemd/system/multi-user.target.wants/autofs.service' [root@linuxtechi ~]#
Step:3 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.
Steps to mount NFS share using autofs in Ubuntu Linux.
Step:1 Install the autofs package using apt-get command.
linuxtechi@linuxworld:~$ sudo apt-get install autofs
Step:2 Edit the Master Map file ‘/etc/auto.master’
Add the following line in the master map file.
linuxtechi@linuxworld:~$ sudo vi /etc/auto.master /dbstuff /etc/auto.nfsdb --timeout=180
Save & exit the file.
Create the mount point.
linuxtechi@linuxworld:~$ sudo mkdir /dbstuff linuxtechi@linuxworld:~$
Step:2 Create a map file ‘/etc/auto.nfsdb’.
Add the following line in the map file.
linuxtechi@linuxworld:~$ sudo vi /etc/auto.nfsdb db_backup -fstype=nfs4,rw,soft,intr 192.168.1.21:/db_backup
Step:3 Start the autofs service.
linuxtechi@linuxworld:~$ sudo /etc/init.d/autofs start
Centos7 has systemd with automount. Thus you don’t really need autofs.
How to create multiple automount in nfs
@pramod: I think you need to add in /etc/auto.nfsdb file otherwise you can use RHEL IDM , FreeIPA to manage automount in your environment.
How to list all autofs mount points in command line