Wednesday, January 10, 2018

AutoFS configuration in Linux

http://kerneltalks.com/config/autofs-configuration-linux

On demand NFS mounting utility : autofs. Learn what is autofs, why and when to use autofs and autofs configuration steps in Linux server.


First place to manage mount points on any linux system is /etc/fstab file. This files mounts all listed mount points at system startup and made them available to user. Although, I explained mainly how autofs advantages us with NFS mount points, it also works well with native mount points.
NFS mount points are also part of it. Now, issue is even if user dont access NFS mount points they are still mounted by /etc/fstab and leech some system resources in background continuously. Like NFS services needs to check connectivity, permissions etc details of these mount points in background continuously. If these NFS mounts are considerably high in numbers then managing them through /etc/fstab will be major drawback since you are allotting major system resource chunk to system portion which is not frequently used by users.

Why use AutoFS?
In such scenario, AutoFS comes in picture. AutoFS is on demand NFS mounting facility. In short, it mounts NFS mount points when user tries to access them. Again once time hits timeout value (since last activity on that NFS mount), it will automatically un-mount that NFS mount saving system resources serving idle mount point.
It also reduce your system boot time since mounting task is done after system boot and when user demands it.

When use AutoFS?
  • If your system is having large number of mount points
  • Many of them are not being used frequently
  • System is tight on resources and every single piece of system resource counts

AutoFS configuration steps :
First, you need to install package autofs using yum or apt. Main configuration file for autofs is /etc/auto.master which is also called as mast map file. This file has autofs controlled mount points details. Master file follows below format :
mount_point map_file options
where –
  • mount_point is directory on which mounts should be mounted
  • map_file (automounter map file) is file containing list of mount points and their file systems from which they should be mounted
  • options are extra options to be applied on mount_point
Sample master map file looks like one below :
In above sample, mount points defined under /etc/auto.misc files can be mounted on /my_auto_mount directory with timeout value 60 sec.
Parameter map_file (automounter map file) in above master map file is also an configuration file which has below format :
mount_point options source_location
where –
  • mount_point is directory on which mounts should be mounted
  • options are mounting options
  • source_location is FS or NFS path from where mount will be mounted
Sample automounter map file looks like one below :
User should be aware of share path. Means, in our case, /my_auto_mount and linux, data1 these paths should be known to user in order to access them.
In all both these configuration file collectively tells :
Whenever user tries to access mount point linux or data1 –
  1. autofs checks data1 source (/dev/fs0) with option (-fstype=ext3)
  2. mounts data1 on /my_auto_mount/data1
  3. Un-mounts /my_auto_mount/data1 when there is no activity on mount for 60 secs
Once you are done with configuring your required mounts you can start autofs service.  Reload its configurations :
Thats it! Configuration is done!

Testing AutoFS configuration :
Once you reload configuration, check and you will notice autofs defined mount points are not mounted on systems (output of df -h).
Now cd into /my_auto_mount/data1 and you will be presented with listing of content of data1 from /dev/fd0!
Another way is to use watch utility in another session and keep watch on command mount. AS you executes commands, you will see mount point is mounted on system and after timeout value its un-mounted!

No comments:

Post a Comment