Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I added a Windows network drive (accessed using WiFi) in my fstab about a month ago:

//Server/Location/foo/bar /media/myNetworkDrive/ cifs auto,iocharset=utf8,uid=umang,credentials=/root/.cifscredentials,file_mode=0775,dir_mode=0775 0 0

and it works perfectly well, except it takes about a full minute for the system to shutdown. I have tried the solutions posted on the help wiki, the team wiki and on this blog. One of them worked for a few shutdowns but then the system went back to taking a minute to shutdown again.

EDIT: I'd like a working working around for this problem. Currently, I have a script that unmounts (password required for super-user priviledges) and then shuts down the computer, but I'd like to be able to shutdown the usual way and have it shutdown as fast.

share|improve this question

3 Answers 3

This is a well known bug : https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/211631?comments=all

It's one of those thankfully-rare, but nonetheless embarrassing, high impact, over-two-years-old bugs that negatively impact Ubuntu's sheen.

It should only affect WIFI connections, but I don't see any detail about that in your question. If you're experiencing this over a wired connection then something else is in play here.

Until Network Manager is fixed (it shuts down wifi connections too quickly - before any of the init scripts are triggered), the only feasible workaround I could find is to use AutoFS.

Paraphrased from http://www.howtoforge.com/accessing_windows_or_samba_shares_using_autofs

sudo apt-get install autofs

Create /etc/auto.cifs with these file contents :

#!/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,file_mode=0644,dir_mode=0755,uid=user,gid=users"
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 }
        '

(edit the mountops line to reflect your real user name)

Make it exectuable with sudo chmod 755 /etc/auto.cifs

Then add this line to your /etc/auto.master, at the bottom :

/smb /etc/auto.cifs --timeout=60 --ghost

Finally, restart autofs with this line (or a reboot would work, of course) :

sudo service autofs restart

And you should then be able to open nautilus to /smb/server/share (or ls -l /smb/Server/Share)

Shutdown, suspend, hibernate should all be seamless.

If you use passwords to connect to your shares, you have to add another file in /etc/ for each server you connect to, with username and password specified. Do a "man autofs" for more detail on that, but here's the gist :

You need one credentials file for each password-protected share that you're connecting to. In your case, your server is called "Server", so create the relevant file with gksudo gedit /etc/auto.smb.Server. Then put this into that file :

username=myusername
password=mypassword

(obviously editing the fields as required).

Then you'll need to make sure that this file is only readable by root with sudo chmod 600 /etc/auto.smb.Server.

Then restart autofs as above and try browsing /smb/Server - you should see a list of your shares.

If you connect using an IP address, you'll need to repeat this process for /etc/auto.smb.192.168.1.10 or whatever.

share|improve this answer
    
Thanks for your answer. I've updated my question and mentioned WiFi there. I will not and cannot access that network for a couple weeks. I shall try your solution and accept/comment on this answer when I can. –  Umang Dec 14 '10 at 6:10
    
I wasn't able to do it exactly the way you suggested, but when I did something similar to ubuntuforums.org/showthread.php?t=1494525 it still takes quite a while to shutdown/restart. –  Umang Jan 14 '11 at 4:15
    
That's disappointing. Autofs shouldn't trigger this bug at all. I have three samba shares specified, I use one of those every minute of every day, but my shutdown is near-instant (certainly never longer than 10 seconds). How's your suspend/resume (if you use it)? –  Scaine Jan 14 '11 at 8:58
    
Suspend/resume is fine, but IIRC it was never troublesome when I had my share in fstab. BTW, I removed the share from my fstab when I started using autofs. I was supposed to do that, right? –  Umang Jan 17 '11 at 16:15
    
Yep - autofs doesn't use /etc/fstab at all. Did you specify the timeout option? If you don't, I think you might still get the CIFS VFS errors. –  Scaine Jan 17 '11 at 16:48

You should use the guide which shows you how to make an unmount shutdown script and make sure that it's still switch on. Upgrades or updates could theoretically have knocked it off it's perch. Check that your script is in /etc/rc0.d and that it's named S01smb_umount or similar so it runs as the first order of business.

Otherwise you may end up with it unmounting the samba drive normally (waiting, waiting) and then running your script. Which would do nothing.

share|improve this answer
    
I've got the following link: /etc/rc0.d/K15umountnfs.sh -> ../init.d/umountnfs.sh. This does not help though. –  Umang Nov 13 '10 at 6:26
    
Is K15 enough? Shouldn't it be S01? Have you tried? –  Martin Owens -doctormo- Nov 13 '10 at 7:02
    
Sorry for my late reply, but I've got /etc/rc0.d/S01smb_umount.sh -> /etc/init.d/umountnfs.sh and /etc/rc6.d/S01smb_umount.sh -> /etc/init.d/umountnfs.sh and have removed the K15 ones. Still facing this problem, after three restarts. –  Umang Nov 20 '10 at 17:22
    
Then I don't know, it needs attention from an upstart developer on the platform team, please report bug. –  Martin Owens -doctormo- Nov 20 '10 at 21:23

I had the same problem with a Win2003 server samba share and following this guide fixed the problem.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.