AutoFS Server : Mounting File System Automatically

In Linux OS, you mount the drives automatically with autofs Server. This server is very simple to configure.

The basic idea behing this is

Just go to the assigned folder for that drive and it will automatically gets mounted and it will remain mounted till you are in that folder. If you come out of that folder then it gets automatically unmounted is timeout time. It is usually 1 min, but you can increase the same by editing the configuration file.

Below are simple steps to configure this server.

1. First check the software with yum command.

# yum list autofs

2. If the server is not there then you can install with

# yum install autofs -y

3. This is server, so you need to make it in start state at the time of booting.

# systemctl enable autofs.service
# systemctl start autofs.service
# systemctl status autofs.service

The basic installation and setup is now complete.

4. The autofs server be default refers to /etc/auto.master file. We have to edit this file to suit our requirements. To understand this in better way consider following example.

Let us assume that we have following devices with their expected mount points

/dev/cdrom /magnum/mycd

/dev/fd0 /magnum/mydisk

/var/ftp/pub Folder located via NFS on 10.0.0.1 Server /magnum/remote

5. To setup this there is no need to create parent folder /magnum on server. It will automatically gets created.

6. Now edit /etc/auto.master and add following line in the file.

/magnum               /etc/auto.magnum

It simply tells autofs server that we have separate configuration file for /magnum folder.

7. Now create /etc/auto.magnum file and write following lines in it.

mycd    -fstype=auto    :/dev/cdrom
mydisk  -fstype=vfat    :/dev/fd0
remote  -fstype=nfs     10.0.0.1:/var/ftp/pub

8. That’s all. Just restart the services as below.

# systemctl stop autofs.service
# systemctl start autofs.service

9. Now you can check yourself that /magnum folder is created. Now try to change directory as below.

# cd /magnum/mycd             

The CD will be mounted in /magnum/mycd folder automatically.

10. Similarly you can mount all the devices.

11. You can increase the timeout from 60 secs, which is default to some other value say 120 secs by changing the line in /etc/auto.master file as below.

/magnum               /etc/auto.magnum       --timeout=120