AutoFS: Direct Mapping with CIFS
- 3 minsINTRODUCTION
Linux system’s filesystem table, fstab, is a configuration table designed to ease the burden of mounting and unmounting file systems to a machine. It is a set of rules used to control how different filesystems are treated each time they are introduced to a system. One drawback of using /etc/fstab is that, regardless of how infrequently a user accesses the mounted file system, the system must dedicate resources to keep the mounted file system in place. With multiple mounts this can degraid system performance. An alternative to /etc/fstab is to use the kernel-based automount utility known as AutoFS.
WHAT IS AUTOFS
AutoFS is a kernel-based automount utility that consists of two components:
- A kernel module that implements a file system.
- A user-space daemon that performs all of the other functions.
The automount utility can mount and unmount NFS file systems automatically (on-demand mounting), therefore saving system resources. It can be used to mount other file systems including AFS, SMBFS, CIFS, and local file systems.
In this example, I go through the process of configuring a direct automount map using CIFS on a CentOS 7 box in my Azure home lab.
REQUIREMENTS
- Lab environronment & a running instance of CentOS 7.
DEPLOYMENT PROCESS OVERVIEW
- Install AutoFS
- Configure the auto.master file
- Create the auto.map file
- Test configuration
TIME TO IMPLEMENT: 15 minutes
INSTALL AUTOFS
- First, run the following commands to make sure everything is up to date/upgraded.
- Run the following command to install autofs
- Now, run the following command to install cifs
sudo yum -y update
sudo yum -y upgrade
sudo yum -y install autofs
sudo yum -y install cifs-utils
Note: in this example I am using autofs to mount Common Internet File System (CIFS). Autofs can also be used to mount NFS, AFS, SMBFS, and local file systems as stated above.
CONFIGURE THE AUTO.MASTER FILE
In this example we are going to directly map to a file system. AutoFS uses /etc/auto.master (master map) as its default primary configuration file. Direct maps in autofs provide a mechanism to automatically mount file systems at arbitrary points in the file system hierarchy. A direct map is denoted by a mount point of /- in the master map auto.master file
- Open the auto.master file in nano by issuing the following command:
- In auto.master configuration file, you need to specify the file that will contain your direct mapping information. Simply add the following line after +auto.master
- Save and close auto.master file.
sudo nano /etc/auto.master
/etc/auto.directmap
CREATE THE MAP FILE
- From the /etc directory, issue the following command:
- Open the auto.directmap file in nano by issuing the following command:
- Edit the auto.directmap file to include the following information
- Now, change directories -> mnt and make a new directory called mountpoint:
- Note: /mnt/mountpoint is where autofs will mount the File System configured in auto.directmap every time you cdinto the mnt directory.
sudo touch auto.directmap
sudo nano auto.directmap
/mnt/mountpoint -fstype=cifs,rw,username=opsadmin,domain=secure.media ://fqdn/fileshare
sudo mkdir mountpoint
VERIFY CONFIGURATIONS
- To test the configuration, run the following commands:
- Now, change directories into the /mnt/mountpoint directory. If everything is configured appropriately, the direct mapping should be listed.
sudo systemctl enable autfos
sudo systemctl status autfos
sudo mount -t cifs -o username=opsadmin,domain=secure.media //fqdn/fileshare /mnt/mountpoint/
SUMMARY
- The setup is straight forward and isn't a time drain.
- AutoFS is a great utility to have in your environment. The ability to automount directories on demand is a great feauture, but the inverse is also benefencial: because AutoFS unmounts unused directories at specified intervals, you save on system resources while increasing your level of operational effeciency.