<---- template headericclude ----->
Mounting SMB/CIFS volumes with autofs on the fly
FedoraForum.org - Fedora Support Forums and Community
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2008
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mounting SMB/CIFS volumes with autofs on the fly

    There are a couple of way to mount Samba shares, but I prefer using "autofs" which can mount them on the fly. Use the autofs daemon to have shares automatically mounted on demand. The netfs service (installed by default in Fedora) is not a daemon and can only mount shares on boot, (it can't mount them on demand).


    * Install the “autofs” package:
    Code:
    yum install autofs
    * Edit /etc/auto.master (the master map file), and comment out all lines (with #). This avoids conflicts with the CDROM (which is handled by Gnome), etc. Save the file.
    * Create a new file /etc/auto.cifs, with the contents of:

    Code:
          #!/bin/bash
          # $Id$
          # This file must be executable to work! chmod 755!
          key="$1"
          # Note: create a cred file for each windows/Samba-Server in your network
          #	which requires password authentification.  The file should contain
          #	exactly two lines:
          #          username=user
          #          password=*****
          #	Please don't use blank spaces to separate the equal sign from the
          #	user account name or password.
          credfile="/etc/auto.smb.$key"
          # Note: Use cifs instead of smbfs:
          mountopts="-fstype=cifs,noperm,file_mode=0660,dir_mode=0755"
          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
              	mountopts=$mountopts",credentials=$credfile"
                  smbclientopts="-A "$credfile
          else
              	smbclientopts="-N"
          fi
          $SMBCLIENT $smbclientopts -gL $key 2>/dev/null \
             | awk -v key="$key" -v opts="$mountopts" -F'|' -- '
                  BEGIN   { ORS=""; first=1 }
                  /Disk/  { if (first) { print opts; first=0 };
                            gsub(/ /, "\\ ", $2);
                            sub(/\$/, "\\$", $2);
                            print " \\\n\t /" $2, "://" key "/" $2 }
                  END     { if (!first) print "\n"; else exit 1 }
                  '
    * Set proper permissions on the file:
    Code:
    chmod 755 /etc/auto.cifs
    * Edit /etc/auto.master, and add this line at the bottom (this makes autofs look for the map file for the server that is requested, and mount it in /mnt):
    Code:
    /mnt /etc/auto.cifs --timeout=0
    * You can change the timeout to a value which will cause volumes to unmount after a period of inactivity (best for shares that go up/down on the network often). But if you are mounting volumes from a server, using a timeout of 0 is usually sufficient.
    * Create additional files in /etc/ as: “auto.smb.servername” for each server you wish to connect to, where the the servername is the hostname that contains the share you are connecting to. The contents of each of these files would be:
    Code:
    username=yourusername
    password=yourpassword
    * To protect the password:
    Code:
    chmod 400 /etc/auto.smb.servername
    * Add each servername from the above line to /etc/hosts so that autofs can find the host.
    * Make sure “autofs” is set to start automatically on startup, and that “netfs” is NOT set to start up automatically (using the "ntsysv" utility as root).
    * Now when you access the path of : /mnt/servername, it will appear and all of the shares will be located underneath it (i.e. /mnt/servername/share1), etc. Autofs will scan the server and add all available shares automatically (per the script used as auto.cifs).


    One caveat: autofs will only mount the volumes when a request is made to the mount folder that it is pointed to, i.e. /mnt/servername in the example above. I made a static link on my Desktop that points to the shares, (/mnt/servername/share1, /mnt/servername/share2, etc.), which does the trick.

  2. #2
    Join Date
    Dec 2010
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mounting SMB/CIFS volumes with autofs on the fly

    Hi,

    does not work for me.
    where can i find error messages????

    Michael

  3. #3
    Join Date
    Aug 2008
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mounting SMB/CIFS volumes with autofs on the fly

    Try checking in /var/log/messages. Are you connecting to a Windows system or a Linux Samba system?

  4. #4
    Join Date
    Dec 2010
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mounting SMB/CIFS volumes with autofs on the fly

    Yep, Linux Samba Server on centos 5.5, Linux and MacOsx clients.
    No entries in /var/log/messages, so far I can see.
    When I click on defined mountpoint in nautilus I can only see that owner and group switched to root, but no shares are visible.
    Config exact like your howto, only mountpoint and user/password changed.
    Mountpoint in /home/username/mountpoint
    btw. I'm using FC14 x86_64
    mount via fstab or connecting server in nautilus works fine.

  5. #5
    Join Date
    Aug 2008
    Posts
    193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Mounting SMB/CIFS volumes with autofs on the fly

    OK it could be a couple of things. The mountpoints (and shares) don't show up until you try to access them. So for instance, if you have it set to mount a share as: /mnt/server1/share1 , it won't show up until you try to access that directory. So, in my case I simply create a symlink on the desktop that points to /mnt/server1/share1 , and when Gnome opens up it will attempt to read that directory and thus mount the share. It should also mount it if you simply try to cd into that directory, too, like "cd /mnt/server1/share1".

    If it still doesn't mount, then it could be an authentication problem. You may have to check the logs for the clients that aren't working on the Samba server, in /var/log/samba/.

Similar Threads

  1. Problem mounting NFS volumes with dash in the name
    By hymolina in forum Servers & Networking
    Replies: 0
    Last Post: 18th June 2009, 09:11 PM
  2. Manually Mounting Logical Volumes
    By Nagglfar in forum Using Fedora
    Replies: 1
    Last Post: 18th February 2009, 05:20 AM
  3. Problem with mounting CIFS share with autofs on F7
    By richi1801 in forum Installation, Upgrades and Live Media
    Replies: 2
    Last Post: 8th June 2007, 11:45 AM
  4. Mounting volumes as a user: HAL trouble
    By KermitTheFragge in forum Using Fedora
    Replies: 4
    Last Post: 18th July 2006, 11:46 AM
  5. Help mounting network volumes
    By kennon in forum Servers & Networking
    Replies: 0
    Last Post: 22nd June 2005, 12:21 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
[[template footer(Guest)]]