How to install and configure Autofs on CentOS 7 / Fedora 22 / Ubuntu 14.04

Configure Autofs on CentOS 7
Configure Autofs on CentOS 7

Autofs is an automounter utility, helps you to automatically mount NFS share when a file or directory is requested on the NFS mount point. Auto-mounts are mounted only when they are assessed, and are unmounted after a period of inactivity.

In the last tutorial we used /etc/fstab to mount a filesystem automatically across the system reboot, but here we will use autofs to mount the same NFS share. This is very useful incase if the client server has to mount many mounts at one time, over all boot up time will be increased; with the autosfs we can speed up the boot up time.

When the static mount (/etc/fstab) is used, regardless of how infrequently a user accesses the NFS mounted file system, the system must dedicate resources to keep the mounted file system in place. Autofs solves the problem of keeping the filesystem mounted that are not frequently accessed by the users by unmounting it after a period of inactivity. Because of this, automounting NFS/Samba shares conserves bandwidth and offers better overall performance compared to static mounts via fstab.

Autofs can also be used to mount other file systems including AFS, SMBFS, CIFS, and local file systems.

This guide helps you to install and configure Autofs on CentOS 7 / Fedora 22 / Ubuntu 14.04, same steps will be applicable to previous versions of CentOS, Fedora and Ubuntu.


Here are my demo nodes detail, I’ve both NFS and Client server in same distribution.

NFS Server Hostname: server.itzgeek.local (CentOS 7 / Fedora 22 / Ubuntu 14.04)

NFS Server IP Address:

Share Path: /nfsfileshare

NFS Client Hostname: client.itzgeek.local (CentOS 7 / Fedora 22 / Ubuntu 14.04)

NFS Client IP Address:

Autofs mount path: /autofs/nfsfileshare

Other HowTo’s that you would require to setup autofs.

Install Autofs:

Let’s install autofs package, it is available in the base repository. Install it using following command in terminal.

### CentOS 7 / Fedora 22 ###

# yum -y install autofs

### Ubuntu 14.04 ###

$ sudo apt-get install autofs

Configure Autofs:

The main configuration file for Autofs is the /etc/auto.master file, also referred to as the master map. The master map file contains a list of mount and the location of its map.

Sample output of /etc/auto.master, you can see the mount and its map shown in “Green“.

# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
/misc   /etc/auto.misc
# NOTE: mounts done from a hosts map will be mounted with the
#       "nosuid" and "nodev" options unless the "suid" and "dev"
#       options are explicitly given.
/net    -hosts
# Include /etc/auto.master.d/*.autofs
# The included files must conform to the format of this file.
# Include central master map if it can be found using
# nsswitch sources.
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.

Edit /etc/auto.master:

As per our scenario, we are going to mount NFS share on /autofs/nfsfileshare using Autofs. The following step creates a mount point at /autofs and configures it according to the settings specified in /etc/auto.nfs (which we will create in the next step).

### CentOS 7 / Fedora 22 ###

# vi /etc/auto.master

### Ubuntu 14.04 ###

$ sudo nano /etc/auto.master

Add the following line at the end of /etc/auto.master file. The default timeout for autofs is 300 seconds (5 minutes). After five minutes of inactivity, a filesystem that is mounted will be automatically unmounted.

Note: It is optional to define the timeout in /etc/auto.master file.

/autofs   /etc/auto.nfs --timeout=60

Create /etc/auto.nfs:

Now, we will create the file which contains our automounter map.

### CentOS 7 / Fedora 22 ###

# vi /etc/auto.nfs

### Ubuntu 14.04 ##

$ sudo nano /etc/auto.nfs

This file should contain a separate line for each NFS share. The format for a line is {mount point} [{mount options}] {location}. The mount points specified here will be relative to the mount point given in /etc/auto.master.

nfsfileshare        -fstype=nfs4,rw,soft,intr


nfsfileshare : Mount Point

-fstype=nfs4,rw,soft,intr : Mount options : Share location

This creates a new mount point at /autofs/nfsfileshare/ and mounts the NFS “/nfsfileshare” directory exported by “

Restart the autofs service and enable it to start at system startup.

### CentOS 7 / Fedora 22 ###

# systemctl restart autofs
# systemctl enable autofs

### Ubuntu 14.04 ##

$ sudo service autofs restart
$ sudo update-rc.d autofs defaults

Testing Autofs:

Now, try accessing “/autofs/nfsfileshare” directory.

Note: Make sure you unmount the static mounts and remove the entry from /etc/fstab file.

$ ll  /autofs/nfsfileshare

total 0
drwxrwxrwx 4 root root 33 Sep 17 17:47 ./
drwxr-xr-x 3 root root  0 Sep 19 01:23 ../
drwxr-xr-x 2 root root  6 Sep 17 17:39 1/
drwxrwxr-x 2 raj  raj   6 Sep 17 17:45 2/
-rw-rw-r-- 1 raj  raj   0 Sep 17 17:47 test

You would see the content of NFS shared directory. Also, use “df” command to see the mounted file systems, you could see the NFS share that is mounted automatically.

Note: Below is the sample out of “df” command (Ubuntu 14.04).

$ df -hT

Filesystem                 Type      Size  Used Avail Use% Mounted on
/dev/sda1                  ext4       98G  3.7G   89G   4% /
none                       tmpfs     4.0K     0  4.0K   0% /sys/fs/cgroup
udev                       devtmpfs  478M  4.0K  478M   1% /dev
tmpfs                      tmpfs      98M  1.5M   97M   2% /run
none                       tmpfs     5.0M     0  5.0M   0% /run/lock
none                       tmpfs     489M  144K  489M   1% /run/shm
none                       tmpfs     100M   32K  100M   1% /run/user nfs4       50G  858M   50G   2% /autofs/nfsfileshare

To test the unmount, do not perform any action on the mounted file system for 5 minutes (In my case 1 minute as i set –timeout=60). The autofs will automatically unmount the filesystem once the inactivity time has passed.

Note: Please do not even try to use “df” command to check the mounted filesystems as “df” command may access the mounted filesystems which will cause delay in unmount.

Debugging and Troubleshooing:

CentOS 7 / Fedora 22:

Note: Make sure you have LOGGING=”debug” in “/etc/sysconfig/autofs

# cat /var/log/messages

Sep 19 13:14:20 client automount[1891]: expire_proc_indirect: expire /autofs/nfsfileshare
Sep 19 13:14:20 client automount[1891]: handle_packet: type = 4
Sep 19 13:14:20 client automount[1891]: handle_packet_expire_indirect: token 4, name nfsfileshare
Sep 19 13:14:20 client automount[1891]: expiring path /autofs/nfsfileshare
Sep 19 13:14:20 client automount[1891]: umount_multi: path /autofs/nfsfileshare incl 1
Sep 19 13:14:20 client automount[1891]: umount_subtree_mounts: unmounting dir = /autofs/nfsfileshare

If you see the output marked in “Green“, autofs unmounted the NFS share after the timeout.

Ubuntu 14.04:

$ sudo service autofs stop

$ sudo automount -f -v

Try to access the share in another terminal, and go through the output of the above command on first terminal.

Starting automounter version 5.0.7, master map /etc/auto.master
using kernel protocol version 5.02
lookup(dir): dir map /etc/auto.master.d missing or not readable
lookup(file): failed to read included master map dir:/etc/auto.master.d
lookup(file): failed to read included master map auto.master
mounted indirect on /autofs with timeout 60, freq 15 seconds
attempting to mount entry /autofs/nfsfileshare
 mounted /autofs/nfsfileshare
1 remaining in /autofs
1 remaining in /autofs
1 remaining in /autofs
1 remaining in /autofs
expiring path /autofs/nfsfileshare
 expired /autofs/nfsfileshare

If you see the output marked in “Green“, autofs automatically mounted the filesystem on your access and unmounted it after the timeout.

That’s All, You have successfully mounted NFS mount via autofs!.


Share This Post

  • Iain

    You should probably make a note to install nfs-common first for those connecting for the first time.