Redhat – Mount CIFS share with autofs

autofsautomountcifsredhat

I have a system running RHEL 5.5, and I am trying to mount a Windows share on a server using autofs. (Due to the network not being ready upon startup, I do not want to utilize fstab.) I am able to mount the shares manually, but autofs is just not mounting them.

Here are the files I am working with:

At the end of /etc/auto.master, I have:

## Mount this test share:
/test    /etc/auto.test    --timeout=60

In /etc/auto.test, I have:

test    -fstype=cifs,username=testuser,domain=domain.com,password=password ://server/test

I then restart the autofs service.

However, this does not work. ls-ing the directory does not return any results. I have followed all these guides on the web, and I either don't understand them, or they.just.don't.work.

Thank You

Best Answer

There should be an /etc/auto.smb already, use that, and add the following line to /etc/auto.master:

/cifs   /etc/auto.smb --timeout=60

Now all cifs shares will show up under /cifs:

ls /cifs/<server>

will show all the shares available. You might want to put some options in /etc/auto.smb to mount with specific modes. I have a auto.smb that I found out there somewhere and modified to do exactly that:

#!/bin/bash
# $Id: auto.smb,v 1.3 2005/04/05 13:02:09 raven Exp $
# This file must be executable to work! chmod 755!

key="$1"
credfile="/etc/auto.smb.$key"

opts="-fstype=cifs,file_mode=0644,dir_mode=0755,uid=eng,gid=eng"
smbclientopts=""

for P in /bin /sbin /usr/bin /usr/sbin
do
    if [ -x $P/smbclient ]
    then
        SMBCLIENT=$P/smbclient
        break
    fi
done

[ -x $SMBCLIENT ] || exit 1

if [ -e "$credfile" ]
then
    opts=$opts",credentials=$credfile"
    smbclientopts="-A "$credfile
else
    smbclientopts="-N"
fi

$SMBCLIENT $smbclientopts -gNL $key 2>/dev/null| awk -v key="$key" -v opts="$opts" -F'|' -- '
    BEGIN   { ORS=""; first=1 }
    /Disk/  {
              if (first)
                  print opts; first=0
              dir = $2
              loc = $2
              # Enclose mount dir and location in quotes
              # Double quote "$" in location as it is special
              gsub(/\$$/, "\\$", loc);
              print " \\\n\t \"/" dir "\"", "\"://" key "/" loc "\""
            }
    END     { if (!first) print "\n"; else exit 1 }
'

This will do what you want. I've used it myself.