16

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

5
  • Are you getting anything in the logs?
    – c1tadel1
    Jan 6, 2011 at 21:40
  • Where are the logs? I have tried /var/log/messages to no avail, and there is no syslog file.
    – Phanto
    Jan 7, 2011 at 12:21
  • You are looking in the right place. Try "echo 1 >/proc/fs/cifs/cifsFYI" to increase the debug messages a bit and give dmesg a try.
    – c1tadel1
    Jan 7, 2011 at 16:26
  • I don't have the /proc/fs/cifs/ directory, so I cannot run the command. I also can't mkdir cifs, even as root. The service is running, but I seriously don't know why it's just not working. I may have to contact RH support.
    – Phanto
    Jan 10, 2011 at 13:33
  • Forget the proc location. Do you even have the module installed? Run this. ls -al /lib/modules/uname -r/kernel/fs/cifs you should see cifs.ko
    – c1tadel1
    Jan 10, 2011 at 18:49

4 Answers 4

10

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.

4
  • Thank you. I have completely forgotten about this issue. I actually contacted Red hat support, and the options you mention in the opts you mention do work. The key was to place the info in auto.misc for whatever reason. It's funny, since we don't even need to do this anymore.
    – Phanto
    May 11, 2011 at 16:28
  • This is useful, but unfortunately I don't get to customize the mount points, which was the original goal of the question (and what I came here to find out) May 16, 2013 at 18:36
  • As an interesting development, using this with an EMC device (not sure module) required me to remove the -N from the smbclient line. Encountered this problem today.
    – lsd
    Mar 6, 2015 at 20:39
  • 1
    Also, the credentials file must not have spaces between the equals signs. That caused a bunch of errors until I found that out. Two different pieces of documentation said different things.
    – lsd
    Mar 6, 2015 at 20:40
10

Since I just spent my entire morning debugging this same issue. Let me explain what happened above.

/etc/auto.master

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

This means I want to mount something at /test and for the details read /etc/auto.test

/etc/auto.test

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

This means as a sub-folder of what was specified in auto.master please mount test with the information following. (i.e. the mount will be /test/test as slm correctly pointed out).

This means that ls /test/test will display the contents of //server/test

To accomplish the original goal of /test -> //server/test you would want the following:

/etc/auto.master

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

A couple other notes. I found the following mount options useful.

rw - mount it read/write

noserverino - removes error message about inode number support

credentials=[credential file] - this allows you to create a separate file with the credentials in them. It has the following format:

username=[windows username, domain can be included as well]
password=[windows password]

EDIT -- 2013-06-17 13:28PM GMT-8

slm in the comments has pointed out that mounting to the root of the file system could be dangerous. lsd in the comments suggests a workaround, which is to creating a symlink from the root of the filesystem to a different place where you would mount that would not overlap with something common. For example, if you wanted to have /test be a mount, then you would actually mount stuff to /net/the_test_mount and then create a symlink /test that points to /net/the_test_mount

3
  • 3
    This is dangerous in the sense that if someone were to add usr or etc for example to /etc/auto.test that these mounts would effectively override those directories on the system. Granted that's highly unlikely but in general mounts are not done at the root level.
    – slm
    May 16, 2013 at 20:34
  • Is there a better way to provide a root mount using autofs? If so please update your answer or leave a comment and I can update mine. May 16, 2013 at 22:28
  • 1
    Have the mounts go to /net, say, and have symbolic links from /test to /net/server/test (or whatever). Now whenever you cd to /net and ls or whatever, it will mount.
    – lsd
    Jun 17, 2013 at 20:12
4

I just did this on a CentOS 5.6 box and I think part of your problem might be with your auto.test file. In it's current form you'll be creating a /test mount point and then a single moung of test under it, i.e. /test/test. Also you might want to add the --ghost switch to your auto.master line like so:

/test    /etc/auto.test    --timeout=60 --ghost

The --ghost switch creates stubs of mount points even when a given share isn't being actively mounted.

Take a look at this CentOS wiki Tips and Tricks page on ways to mount SMB/CIFS shares.

Mounting tips

  • Windows Share = \mysmb\share1
  • Unix Dir. = /test/dir1

idea #1

 # /etc/auto.master
/test                 /etc/auto.test --timeout=600 --ghost

# /etc/auto.test
dir1         -fstype=cifs,rw,noperm,netbiosname=${HOST},credentials=/etc/creds.txt ://mysmb/test/dir1
dir2         -fstype=cifs,rw,noperm,netbiosname=${HOST},credentials=/etc/creds.txt ://mysmb/test/dir2

idea #2

 # /etc/auto.master
/test                 /etc/auto.test --timeout=600 --ghost

# /etc/auto.test
*            -fstype=cifs,rw,noperm,netbiosname=${HOST},credentials=/etc/creds.txt ://mysmb/test/&
2
  • Thank you for your reply. Please see my comment for lsd.
    – Phanto
    May 11, 2011 at 16:29
  • 1
    My god... --ghost should be default. I'm on fedora/rhel/centos it reads the map, but when I go inside the folder, nothing is there... I then had the crazy idea of doing cd "sharename" and it magically entered the folder which ls says does not exist... arrgh
    – Ray Foss
    Nov 20, 2019 at 0:33
-1

If you are using cifs it's recommended also to use _netdev parameter.

_netdev it's because the filesystem resides on a device that requires network access, this is used to prevent the system from attempting to mount these filesystems until the network has been enabled on the host system.

1
  • 1
    Corrected a few format and spelling errors. You should probably point out how and where to put that parameter using the configuration from the question as an example too. May 21, 2018 at 5:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .