Bootstrap FreeKB - AutoFS - Install and configure AutoFS with CIFS (Common Internet File System)
AutoFS - Install and configure AutoFS with CIFS (Common Internet File System)

Updated:   |  AutoFS articles

Typically, AutoFS is used to automatically mount a CIFS (Common Internet File System) or NFS (Network File System) share, or both. This article describes the process to setup AutoFS to mount a CIFS share. Refer to install and configure AutoFS with NFS (Network File System) for the steps on how to setup AutoFS to mount an NFS share.

On a Red Hat distribution (CentOS, Fedora, RedHat), dnf or yum can be used to install the CIFS utilties and AutoFS packages.

dnf install autofs
dnf install cifs-utils

 

Before setting up AutoFS, ensure you can manually mount the share using the mount command.

mkdir /mnt/share
mount --types cifs //fs1.example.com/share /mnt/share --options username=john.doe,password=MyPassword

 

Then, use the umount command to unmount the share.

umount /mnt/share
rmdir /mnt/share

 

The ps command can be used to determine if your system is using init or systemd. If PID 1 is init, then you will use the service command. If PID 1 is systemd, then you will use the systemctl command.

If your system is using systemd, use the systemctl command to start and enable autofs.

systemctl enable autofs
systemctl start autofs
systemctl status autofs

 

If your system is using init, use the chkconfig and service commands to start and enable autofs.

chkconfig autofs on
service autofs start
service autofs status

 

In this example, the hostname of the file server is server1.example.com, and directory /mnt/share is being shared. The network path to the share is //server1.example.com/share.

In this example, AutoFS will mount //server1.example.com/share to /mnt/myShare on the client.

 

In the /etc/auto.master configuration file, specify the root directory on the client that the share will be mounted on. In this example, since we want //server1.example.com/share mounted to /mnt/myShare on the client, the root of the mount point is just /mnt. Note: Only /mnt needs to exist on the client. You do not need to create a directory named myShare on the client.

The second field of /etc/auto.master will be the absolute path to a file that will contain the logic to mount the CIFS share. In this example, the /etc/auto.nfs file will contain the logic to mount the share.

/mnt    /etc/auto.cifs   --timeout=60 --ghost

 

Create /etc/auto.cifs. This file does not need to be named auto.cifs. It can be named anything you would like.

touch /etc/auto.cifs

 

Ensure /etc/auto.cifs permissions are -rw-r--r--. Do not add the x (execute) permission, as this will cause the file to be executed instead of read.

chmod 644 /etc/auto.cifs

 

The first field in /etc/auto.cifs will be the name of the directory on the client where AutoFS will mount the share. For example, if you want to mount //server1.example.com/share to /mnt/share on the client, you will have /mnt in /etc/auto.master and share in /etc/auto.cifs. 

The second field in /etc/auto.cifs will be the file server hostname and the share directory.

share  -fstype=cifs,username=johndoe,password=myPassword  ://cifs.example.com/share

 

Since changes have been made to configuration files, you will need to restart AutoFS so that AutoFS can used the updated configuration file.

systemctl restart autofs

 

The mount command should show that auto.cifs is mapped to mnt. However, //server1.example.com/share will not be mounted at /mnt/share because AutoFS is an on-demand mount.

mount
. . . 
/etc/auto.cifs on /mnt type autofs

 

List the contents of /mnt/share, which will trigger AutoFS to automount the CIFS share.

ls /mnt/share

 

The mount command should now show that AutoFS mounted the share.

mount
. . . 
/etc/auto.cifs on /mnt type autofs
//cifs.example.com/share on /mnt/share type cifs

 

You should now be able to list the contents of /mnt/share.

ls /mnt/share
. . .
File1 File2 File3

 

If the share is not being mounted, add the following to /etc/sysconfig/autofs. Restart autofs, and there will be debugging events in /var/log/messages.

OPTION="--debug"

 

In the prior examples, the share is being mounted on /mnt/share. List the /mnt directory. Notice the /mnt directory is empty and is 0 bytes. 0 bytes means that automount has read your maps and is possessing the directory.

ls -la /mnt
. . .
drwxr-xr-x  2  root  root    0  Aug  29  15:42 .



Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 1f6538 in the box below so that we can be sure you are a human.