Linux - SoftwareThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
# 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 !!!
Distribution: Slackware, CentOS. Red Hat Enterprise Linux
Posts: 216
Rep:
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
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.
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...
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' ?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.