LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Auto mount Windows shares (http://www.linuxquestions.org/questions/linux-server-73/auto-mount-windows-shares-4175428773/)

yzfr1 09-24-2012 07:40 AM

Auto mount Windows shares
 
I have a Windows Server 2008 file server with a few network shares configured, and I'm having problems finding a good stable way to mount them using linux clients. The clients all use Debian; one Squeeze and a few Wheezy.

Up until now I've been using the following to manually mount each share:
Code:

mount -t cifs //<server>/<share> <mount dir> -o username=<username>,password=<password>
That works for the moment, but not as well as I'd like. The first issue is that when forgetting to unmount the share before shutdown/reboot the shutdown procedure gets stuck for a really long time on "Stopping rsyslogd". It gets shut down eventually, but may take up to 10-15 minutes at times.
Another issue I've been having is that sometimes, when the share has been mounted for a long time (a day or two) or if it's been in sleep mode for a while, the mount 'stops responding'; if you run a ls command in the mounted directory it just gets stuck and you have to abort it with Ctrl-C. When this happens not even the umount command works, nor can I remount the share. Normally I'm then forced to reboot it before I can get it to work again. This latter problem has only occured on clients connected over wireless network so that may play a part in it I suppose.

So, what I'm looking for is basically the "right" way to set up a persistent mount, kind of the way Windows does its "Map network drive". Is it possible to have it automatically mount on startup? What happens if the wireless network is a bit slow to connect, can you somehow make it *wait* for a connected network interface before mounting the drive?

414N 09-24-2012 08:18 AM

To automatically mount something at boot, put the relevant information in /etc/fstab and add the auto option, like this:
Code:

//<server>/<share>    <mount dir>    cifs    username=<username>,password=<password>,auto    0    0
I've got no Debian knowledge whatsoever, so I guess you'll have to wait for some Debian-expert to jump in to have your other answers.

pan64 09-24-2012 08:28 AM

I would suggest you to use automounter, it will also unmount if the drive was not used for a while.
The problem cannot be solved, an unavailable share will always cause such troubles (you must umount before disconnect)

yzfr1 09-24-2012 08:29 AM

Quote:

Originally Posted by 414N (Post 4787975)
To automatically mount something at boot, put the relevant information in /etc/fstab and add the auto option, like this:
Code:

//<server>/<share>    <mount dir>    cifs    username=<username>,password=<password>,auto    0    0
I've got no Debian knowledge whatsoever, so I guess you'll have to wait for some Debian-expert to jump in to have your other answers.

Thanks for your answer mate. Generally speaking, if it takes a few seconds to establish the network connection (due to, for example, a slow wifi router), will this still work? Is there a command to *refresh* fstab if you want it to reattempt the mounting at a later time?

TobiSGD 09-24-2012 10:29 AM

Quote:

Originally Posted by yzfr1 (Post 4787985)
Generally speaking, if it takes a few seconds to establish the network connection (due to, for example, a slow wifi router), will this still work?

Usually the boot process should wait until the network connection is established when network is available.
Quote:

Is there a command to *refresh* fstab if you want it to reattempt the mounting at a later time?
Yes, you can use the mount command for that. For example,
Code:

mount -a
will try to mount everything it finds in /etc/fstab, maybe with complaining if something is already mounted. You can also use
Code:

mount -a -t cifs
to only mount those entries in fstab that have the filesystem declared as cifs.

yzfr1 09-24-2012 10:43 AM

Thanks for the explanations!

I tried using the line specified by 414N above in fstab and mounting the shares worked beautifully on all my clients, so thanks for that!

Something a bit odd though, on my laptop the share doesn't seem to get unmounted properly before reboot, it still gets stuck on "Stopping rsyslogd" when rebooting. Works if I manually use the umount command before rebooting. The laptop runs Debian Wheezy with X installed. On my other Debian client it does, however, get unmounted correctly using the exact same fstab line, which runs Squeeze backports without X and connected over Ethernet.

Any ideas?

414N 09-24-2012 10:53 AM

I suppose this should be handled by your distribution service scripts.
In Slackware there is a specific phase during system shutdown which makes sure that all NFS (it should be trivial to use it for cifs/smbfs too) mounts are unmounted and, if there's a process still keeping a file open on them, it is killed:
Code:

# Kill any processes (typically gam) that would otherwise prevent
# unmounting NFS volumes:
unset FUSER_DELAY
for dir in $(/bin/mount | grep 'type nfs' | cut -d ' ' -f 3 ) ; do
  echo "Killing processes holding NFS mount $dir open..."
  # Background this to prevent fuser from also blocking shutdown:
  /usr/bin/fuser -k -m $dir &
  FUSER_DELAY=5
done
# If fuser was run, let it have some delay:
if [ ! -z "$FUSER_DELAY" ]; then
  sleep $FUSER_DELAY
fi

# Unmount any NFS, SMB, or CIFS filesystems:
echo "Unmounting remote filesystems."
/bin/umount -v -a -l -f -r -t nfs,smbfs,cifs

Maybe you can add something similar to your shutdown scripts, if there's not already a more Debian-ish way to do it ;)

yzfr1 09-25-2012 06:13 AM

I did a bit of digging and found the 'debian way' to do it. It's a shutdown script called umountnfs.sh and after a adding a few well-placed echo statements I found that the script hangs running the following command, right at the end of this script (/mnt/server is where I have the share mounted):

Code:

fstab-decode umount -f -l /mnt/server
The strange thing though is that the command is identical to that being run on my Debian Squeeze machine, but on that it works..


All times are GMT -5. The time now is 07:03 PM.