Installing autofs mount Centos 7

Sometimes it is better to have a share automount when a program tries to access a share if the server is rebooted after mounting it can cause lockup issues and even slow boot.

autofs will always make sure your samba and NFS mounts are working. It's pretty slick.

Installing autofs:

autofs can be installed using yum, it is in the normal centos repo, no other repos are needed.

$ sudo yum install -y autofs
Configuring autofs:

Autofs creates a few files under /etc, you will need to edit them with your favorite editor. (vi, joe, nano, vi, etc)

$ sudo vim /etc/auto.master

add the following under the existing /misc entry on line 7, and save the file.

/mnt /etc/auto.cifs
Adding mountpoints:
to add automount points, you need to edit the file we told it to go to for /mnt (which is /etc/auto.cifs), here is an example file from my Linux desktop with a few shares.

share1    -fstype=cifs,rw,noperm,credentials=/etc/credentials.txt    ://
share2    -fstype=cifs,rw,noperm,credentials=/etc/credentials.txt    ://
share3    -fstype=cifs,rw,noperm,credentials=/etc/credentials.txt    ://
share4    -fstype=cifs,rw,noperm,credentials=/etc/credentials.txt    ://

#The first column is what the share is called (where it is mounted in relation to its mount point (which is /mnt)

#EXAMPLE the top line would mount the share to /mnt/share1 and cd'ing to the directory and doing a ls will auto mount the share

you will need to create the folders from column 1 of above, you can do it in one swipe like this:

$ sudo mkdir /mnt/share1 /mnt/share2 /mnt/share3 /mnt/share4

Once you are done, the service needs to be started, but won't… Why?!, it's because we did not create the credential file! doh! Let's do it now.

$ vim /etc/credentials.txt

let's add the following 2 lines to the credentials.txt file.


password=windows_or_samba_passwd (can use guest to mount guest shares.)

Starting autofs

centos 6:

sudo chkconfig autofs on       # to enable service on every boot.
sudo service autofs start      # start service now

centos 7

sudo systemctl enable autofs    # to enable service on every boot.
sudo systemtl start autofs      # start service now

and test:

cd /mnt/transfers
comments powered by Disqus