AutoFS: Direct Mapping with CIFS

AutoFS: Direct Mapping with CIFS

- 3 mins

INTRODUCTION

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:

  1. A kernel module that implements a file system.
  2. 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

  1. Lab environronment & a running instance of CentOS 7.

DEPLOYMENT PROCESS OVERVIEW

  1. Install AutoFS
  2. Configure the auto.master file
  3. Create the auto.map file
  4. Test configuration

TIME TO IMPLEMENT: 15 minutes

INSTALL AUTOFS

  1. First, run the following commands to make sure everything is up to date/upgraded.
  2. sudo yum -y update
    sudo yum -y upgrade
  3. Run the following command to install autofs
  4. sudo yum -y install autofs
  5. Now, run the following command to install cifs
  6. 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

  1. Open the auto.master file in nano by issuing the following command:
  2. sudo nano /etc/auto.master
  3. 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
  4. /etc/auto.directmap

    autofs1

  5. Save and close auto.master file.

CREATE THE MAP FILE

  1. From the /etc directory, issue the following command:
  2. sudo touch auto.directmap
  3. Open the auto.directmap file in nano by issuing the following command:
  4. sudo nano auto.directmap
  5. Edit the auto.directmap file to include the following information
  6. /mnt/mountpoint -fstype=cifs,rw,username=opsadmin,domain=secure.media   ://fqdn/fileshare

    autofs2

  7. Now, change directories -> mnt and make a new directory called mountpoint:
  8. sudo mkdir mountpoint
  9. Note: /mnt/mountpoint is where autofs will mount the File System configured in auto.directmap every time you cdinto the mnt directory.

VERIFY CONFIGURATIONS

  1. To test the configuration, run the following commands:
  2. sudo systemctl enable autfos
    sudo systemctl status autfos
    sudo mount -t cifs -o username=opsadmin,domain=secure.media //fqdn/fileshare /mnt/mountpoint/
  3. Now, change directories into the /mnt/mountpoint directory. If everything is configured appropriately, the direct mapping should be listed.

SUMMARY

  1. The setup is straight forward and isn't a time drain.
  2. 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.
comments powered by Disqus
rss facebook twitter github gitlab youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora quora