Automount CIFS on SLE11SP4

Mounting CIFS on Linux is always a source of problems. Unlike Windows clients, Linux can not reconnect a disconnected mount, so it hangs if something happens to the Windows server (for example, reboot). Therefore, permanent mounting for Windows share is not recommended.

You should use dynamic on-demand mounting and unmounting of unused directories. The following is an example of setting autofs for CIFS. First let's install the software used here (most likely it is already installed):

# zypper install autofs cifs-utils

Create a credential file, make it readable only for root:

# ll /etc/cifs.creds 
-rw------- 1 root root 43 Oct 17 12:13 /etc/cifs.creds
# cat /etc/cifs.creds

Try to mount manually using this file:

# mount -t cifs -o credentials=/etc/cifs.creds // /mnt/net
# df /mnt/net
Filesystem           Size  Used Avail Use% Mounted on
//  3.8G   20M  3.8G   1% /mnt/net
# umount /mnt/net

Where is my Windows Server and tmp is a Share Name on it.

Once mount works manually, you can continue to make it automatically. Create /etc/auto.cifs like this (all slashes and backslashes are important):

# cat /etc/auto.cifs 
backup  -fstype=cifs,credentials=/etc/cifs.creds        \//

Then edit /etc/auto.master file. Add reference to our configuration file before +auto.master line:

# cat /etc/auto.master 
/cifs   /etc/auto.cifs

Then start the service and enable it on OS boot:

# /etc/init.d/autofs start
# chkconfig autofs on

Check it works:

# ls /cifs/backup
# df /cifs/backup
Filesystem           Size  Used Avail Use% Mounted on
//  3.8G   20M  3.8G   1% /cifs/backup

Check the mount after the timeout (10 minutes by default). This value can be tuned in /etc/sysconfig/autofs configuration file. You can force autofs to unmount inactive mounts by command:

# kill -USR1 $(cat /var/run/
# df

Updated on Tue Oct 17 13:27:14 IDT 2017 More documentations here