LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 08-13-2006, 09:38 PM   #1
somebodycr
LQ Newbie
 
Registered: Aug 2003
Location: Costa Rica
Distribution: Slack
Posts: 7

Rep: Reputation: 0
Angry Mounting samba shares at startup


Hi everybody!

I've been trying to achieve this for about 2 weeks now... it's driving me crazy!!

I know there are a lot of posts about this, but I've read all of them (REALLY!) and I still can't figure out how to solve my problem.


I have 1 box with Slackware 10.1 and a XP box, I want the XP share to be mount at startup.

I created a local folder in linux to mount the share at /windows

Then I edited /etc/fstab, this is the line I use:

//xpbox/share /windows smbfs users,rw,password='',dmask=777,fmask=777 0 0

The only problem I have is that the share doesn't get mounted at startup, because any user can mount them when they log in, just by doing:

mount /windows

During boot when it tries to mount them it shows some errors:

#the network initializes fine...
...
dhcpcd: Your IP Address = 192.168.0.141

# this is done automaticaly... but fails...

Mounting remote (SMB) filesystems: /sbin/mount -a -t smbfs
104: tree connect failed: ERRDOS - ERRnoaccess (Acces denied.)
SMB connection failed
...
Starting Samba: /usr/sbin/smbd -D
/usr/sbin/nmbd -D
Starting gpm: /usr/sbin/gpm -m /dev/mouse -t -ms3

# I thought the error could be because Samba wasn't running yet...
# then I put this on /etc/rc.d/rc.local : mount /windows
# but it brings up the same error again !!!

104: tree connect failed: ERRDOS - ERRnoaccess (Acces denied.)
SMB connection failed
Starting X11 Session manager...
Then just after *any* user logs in, if I open a console window I just do:

mount /windows #--> the same line written in /etc/rc.d/rc.local

And the share mounts perfectly!!!

So... I don't know what to do...

Thanks in advance for the help...
 
Old 08-14-2006, 02:43 AM   #2
centauricw
Member
 
Registered: Dec 2005
Location: Lawrenceville GA
Distribution: Slackware, CentOS. Red Hat Enterprise Linux
Posts: 216

Rep: Reputation: 31
You can mount it after you login because smbmount needs to send a username and password to the Windows machine in order to mount the SMB file share. You don't have either of these when the system is booting. I've solved this problem by creating a script that will mount SMB file shares at boot time.

Code:
#!/bin/bash
#
# uncmount
# Script to mount a remote SMB file share using a standard UNC address.
#
# Written by Charles Rutledge
# Copyright (c) 2004 Centauri Computer Works, Inc.
#
# Version 1.00
#
# This program is licensed under the terms of the GNU General Public License,
# Version 2 (or at your option, any later version) as published by the Free
# Software Foundation, Inc., 59 Temple Place, Suite 220, Boston MA 0211, and
# available online at http://www.gnu.org/copyleft/gpl.html.
#
# THIS PROGRAM IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
# EXPRESSED OR IMPLIED.  YOU ASSUME ALL RISKS FOR THE USE OF THIS PROGRAM.

# -----------------------  LOCAL SITE VARIABLES  -----------------------
#
# This is the default credentials file that will be used to authenicate the
# remote connection if no credentials file is specified.
#
SMB_CREDENTIALS=/etc/smb-credentials

#
# This is the username and group that will be used for the mounted UNC file
# share.
#
MOUNT_AS_USER=root
MOUNT_AS_GROUP=users

# -------------  DO NOT MODIFY ANYTHING BELOW THIS LINE  --------------
#
# The first argument must be a valid (formatted, anyway) UNC file share.  It
# can include directories beyond the //server-name/file-share, but these will
# be silently ignored.
#
if [ -z "$1" ]; then
    echo "USAGE: uncmount <unc-file-share> [rw] [<credentials-file>]"
    exit 1
fi
if [ `echo $1 | cut -c1-2` = '\\' ]; then
    # --- Windows-style UNC format
    UNC_SERVER=`echo $1 | cut -d'\' -f3`
    UNC_SHARE=`echo $1 | cut -d'\' -f4`
    if [ -z $UNC_SHARE ]; then
        echo "ERROR: $1 is not a valid UNC file share."
        exit 1
    fi
elif [ `echo $1 | cut -c1-2` = '//' ]; then
    # --- UNIX-style UNC format
    UNC_SERVER=`echo $1 | cut -d'/' -f3`
    UNC_SHARE=`echo $1 | cut -d'/' -f4`
    if [ -z $UNC_SHARE ]; then
        echo "ERROR: $1 is not a valid UNC file share."
        exit 1
    fi
else
    echo "ERROR: $1 is not a valid UNC file share."
    exit 1
fi

#
# The second argument can either be the optional 'rw' parameter, indicating
# that the share should be mounted read-write (read-only is the default).  If
# the 'rw' parameter is omitted, then the second argument could specify the
# credentials files to use.
#
ACCESS_MODE="ro"
if [ -n "$2" ]; then
    if [ "$2" = "rw" ]; then
        ACCESS_MODE="rw"
        shift
    elif [ -n "$3" ]; then
        #
        # If a credendials file is specified in third argument, then this is a
        # syntax error.
        #
        echo "USAGE: uncmount <unc-file-share> [rw] [<credentials-file>]"
        exit 1
    fi
fi

#
# See if a credentials file was specified.  It will have been shifted into the
# second argument position by the preceeding step.  And we need to be sure the
# credentials file exists even if it is the default file.
#
[ -n "$2" ] && SMB_CREDENTIALS="$2"
if [ ! -r $SMB_CREDENTIALS ]; then
    echo "ERROR: Credentials file $SMB_CREDENTIALS does not exist."
    exit 1
fi

#
# See if the UNC file share is already mounted.
#
MOUNT_POINT=`echo "/mnt/smb/$UNC_SERVER/$UNC_SHARE" | tr -d [$]`
if [ `cat /etc/mtab | grep -cw $MOUNT_POINT` -eq 1 ]; then
        echo "UNC file share //$UNC_SERVER/$UNC_SHARE already mounted"
        exit 0
fi

#
# Mount the UNC file share on the mount point /mnt/smb/UNC_SERVER/UNC_SHARE,
# stripping off any trailing '$' which Windows uses to identify hidden shares.
# If the mount point does not already exist, it will be created on demand.
#
[ ! -d /mnt ] && mkdir /mnt
[ ! -d /mnt/smb ] && mkdir /mnt/smb
[ ! -d /mnt/smb/$UNC_SERVER ] && mkdir /mnt/smb/$UNC_SERVER
# --- Use MOUNT_POINT here to avoid a trailing '$' on the share name.
[ ! -d $MOUNT_POINT ] && mkdir $MOUNT_POINT
if [ "$ACCESS_MODE" = "rw" ]; then
    /sbin/mount.smbfs //$UNC_SERVER/$UNC_SHARE $MOUNT_POINT -o credentials=$SMB_CREDENTIALS,uid=$MOUNT_AS_USER,gid=$MOUNT_AS_GROUP,fmask=660,dmask=770,rw
else
    /sbin/mount.smbfs //$UNC_SERVER/$UNC_SHARE $MOUNT_POINT -o credentials=$SMB_CREDENTIALS,uid=$MOUNT_AS_USER,gid=$MOUNT_AS_GROUP,fmask=440,dmask=550,ro
fi
The syntax for the script is:

Code:
uncmount <smb-file-share> [rw] [<credentials-file>]
where <smb-file-share> is the file Windows share you want to mount using //<server>/<share> syntax, rw is an optional flag to make the mounted share on Linux read-write (the default is read-only and if the Windows file permissions are not read-write, you can't write the share even if you specify rw), and <credentials-file> is an optional credentials file with the username and password you should use to connect to the Windows file share. You will want to use this at boot.

The creditials file uses the format specified in the smbmount man page:

Code:
username = <value>
password = <value>
Call this from rc.local and your SMB file shares will be automagically mounted at system boot in the mount point /mnt/smb/<server>/<share>. If you don't like this mount point you can change the script or (better yet) use a symbolic link.

Cheers.
 
Old 08-14-2006, 12:56 PM   #3
somebodycr
LQ Newbie
 
Registered: Aug 2003
Location: Costa Rica
Distribution: Slack
Posts: 7

Original Poster
Rep: Reputation: 0
Tnx for the answer!...

I used your script and it worked perfectly...

... then I started looking what was I doing wrong... and found it :P

In the fstab line:

//xpbox/share /windows smbfs users,rw,password='',dmask=777,fmask=777 0 0

I have to put the username... like this:

//xpbox/share /windows smbfs users,rw,username='',password='',dmask=777,fmask=777 0 0

... and Voilá!...

this way I don't need a script, nor a credentials file... just by adding a line like that for each shared folder that I want mounted at startup it does the trick...

But again, thank's a lot, without your help I couldn't have figured it out...

 
Old 08-15-2006, 12:55 AM   #4
soulestream
Member
 
Registered: Nov 2005
Posts: 183

Rep: Reputation: 30
you can also use a credentials file

just make a file called "cred" or whatever

username=yourusername
password=yourpassword
domain=yourdomain or workgroup

then

//servername/share /mnt/mntpoint smbfs credentials=/path/to/cred,users,dmask=0777,fmask=0777 0 0

that way you can make your "cred" file only readable by root, so not every user can see your password.


Soule
 
Old 09-16-2010, 10:38 AM   #5
Charlie Evatt
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Rep: Reputation: 0
Permission issue for mounting

Hi Guys

I've been trying to sort this out myself too, by adding a mount command to rc.local.

Problem is that the mount command needs to have root permissions and this doesn't seem to work.

Is there something I'm missing?

It's basically this that works as root when I'm logged in and have done my su:

mount -t cifs //server/share -o username=me,password=blah /mnt/mountpoint

But if I put it in the rc.local then the whole system gets totally messed up cos I reckon it can't run that command without being root.

Surely the rc.local is executed at boot time by a root level user - or is that not the case?

This should be pretty straightforward - just need to connect to this share at startup!

Thanks in advance for your help.
 
Old 09-16-2010, 11:33 AM   #6
suprstar
Member
 
Registered: Aug 2010
Location: Atlanta
Distribution: ubuntu, debian
Posts: 142
Blog Entries: 2

Rep: Reputation: 21
rc.local runs as root, I put mount commands like that on some of my systems and have no issues whatsoever. What do you mean, exactly, by 'totally messed up' ?
 
Old 09-17-2010, 07:08 AM   #7
Charlie Evatt
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Rep: Reputation: 0
Basically it wouldn't log in - got jammed on the login screen.
 
Old 09-17-2010, 07:20 AM   #8
suprstar
Member
 
Registered: Aug 2010
Location: Atlanta
Distribution: ubuntu, debian
Posts: 142
Blog Entries: 2

Rep: Reputation: 21
The login screen happens AFTER rc.local runs. So if you add one mount command to rc.local, you get a login screen, but when you type in a login/password, you don't get your shell? Then if you remove it, everything works perfectly?

Or do you not get a login prompt? A mount in rc.local should work fine as long as the network is up. If it fails in rc.local, I'd expect the same command to fail on a command line after you log in as root.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mounting Samba Shares ad user hobz Linux - Software 1 06-17-2005 11:10 PM
mounting shares with samba darkleaf Linux - Software 1 02-13-2005 07:13 AM
Mounting Samba Shares w/ Solaris linux_pioneer Linux - Software 5 11-09-2003 01:59 AM
Mounting Samba shares and Samba Share Login time112852 Linux - Software 1 09-14-2003 03:23 PM
Mounting Win98 shares using SAMBA desbyleo Linux - Software 3 02-17-2002 08:47 PM


All times are GMT -5. The time now is 06:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration