1

Running Ubuntu I've recently encountered an issue with shutting down the computer - it simply hangs whenever I shutdown, whether from the GUI or command line with sudo shutdown -hP now

~$ uname -a
Linux mythbuntu 3.0.0-17-generic #30-Ubuntu SMP x86_64 x86_64 GNU/Linux

I have a handful of cifs entries in my /etc/fstab which are set to auto so that they mount on boot.

~$ cat /etc/fstab | grep cifs
//remoteserver/stuff    /mnt/remoteserver/stuff cifs ro,username=myuser,password=mypass,nobootwait,auto 0 0
//remoteserver/public   /mnt/remoteserver/public cifs rw,username=myuser,user,suid,noatime,nobootwait,auto 0 0

I added nobootwait but it seems to make no difference (advice on a different forum)

When I change auto for noauto the system doesn't hang, but I want these mounts to be attempted on startup.

I've hunted the internet for information on fixes, and there are plenty of suggestions but no concrete answers. The messages I see on shutdown seem to suggest that unattended-upgrades service is trying to use mountall after the network service has already come down, and failing to mount the network shares. The last bit of output mentions starting then almost immediately stopping an apache2 webserver for some reason. I've also seen this error on shutdown umount //proc/fs/nfsd: device is busy There are no nfs mounts in my fstab.

Am I trying to use CIFS incorrectly? Is there a better way to mount shares on the network that doesn't suffer from this problem? (Its for a media centre type config, so everything should be automatic)

2 Answers 2

4

Based on uSlackr's answer, I modified the mount_shares_locally script (below)

  • I created this file as /etc/init.d/mount_shares_locally
  • Then chmod 755 /etc/init.d/mount_shares_locally to make it executable
  • I created a directory sudo mkdir /var/lock/subsys/
  • I added noauto to each of my cifs shares options, to prevent them being automatically mounted during a mountall
  • Made sure that sudo service mount_shares_locally restart gave no errors
  • And finally added it to the startup/shutdown runlevels with sudo update-rc.d mount_shares_locally defaults

#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          mount_shares_locally
# Required-Start:    $network $local_fs $remote_fs smb mysqld
# Required-Stop:     $network $local_fs $remote_fs smb
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: mount Samba shares locally
### END INIT INFO

if [ -f /etc/rc.d/init.d/functions ]; then  # "/lib/lsb/init-functions" on Ubuntu
    . /etc/rc.d/init.d/functions
fi

start () {  
    echo -n "Mounting Samba shares locally:\n"

    cat /etc/fstab | grep 'cifs.*\(password\|credentials\)' | while read -r remoteServer localMount type options;
    do
        echo Mounting $remoteServer to $localMount
        mount $localMount
    done

    touch /var/lock/subsys/mount_shares_locally
    echo
    return 0
}

stop () {
    echo -n "Unmounting locally mounted Samba shares:\n"

    cat /etc/fstab | grep 'cifs.*\(password\|credentials\)' | while read -r remoteServer localMount type options;
    do
        echo Unmounting $localMount
        umount $localMount
    done

    rm -f /var/lock/subsys/mount_shares_locally

    echo
    return 0
}

restart () {
    stop
    start
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac

exit $?

I also had to add another script to the upstart model, so that mount_shares_locally gets called at the right time during startup (after the network is up):

/etc/init/mount_shares_locally.conf

# mount_shares_locally - Mount any cifs shares in /etc/fstab when network comes online
#

description "Mount CIFS shares"

start on (local-filesystems and net-device-up IFACE=eth0)
stop on (runlevel [!12345] or net-device-down IFACE=eth0)

respawn
console none

pre-start script
    mkdir -p -m0755 /var/run/mount_shares_locally
    exec /etc/init.d/mount_shares_locally start
end script

post-stop script
    mkdir -p -m0755 /var/run/mount_shares_locally
    exec /etc/init.d/mount_shares_locally stop
end script
2

You could create a "service" that unmaps these during shutdown. I use a script on my Fedora/Amahi server to do this. It will need to be tweaked for Ubuntu, but the theory works.

More here: http://wiki.amahi.org/index.php/Mount_Shares_Locally

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .