Unmount Samba filesystems before shutdown or reboot
Merry Christmas, everyone!
This post is essentially an addendum to my earlier post, Mount Samba Shares on a GNU/Linux machine. I found that my system was hanging toward the end of a shutdown because the Samba shares I had mounted weren’t being unmounted properly. I was seeing strange console messages saying things like “CIFS VFS: no response for cmd 50…” and the system would sit there, apparently unresponsive, for several minutes before actually turning off or restarting. I apologize if my earlier post created this problem for anybody.
The solution is to unmount the Samba shares a little earlier in the shutdown process, when networking is still available. This is as easy as adding a couple of symbolic links to the runlevels for shutdown and reboot that point to the /etc/init.d/umountnfs.sh script, which unmounts virtual filesystems.
Note: the following instructions are distribution-specific; they should work on Debian and Ubuntu GNU/Linux, and probably any other distribution with a System V-style init script system. If you have a different distribution, particularly one with a BSD-style init system, check its documentation on how scripts are run when changing runlevels.
To unmount Samba shares before shutting down network services, run the following commands as root:
ln -s /etc/init.d/umountnfs.sh /etc/rc0.d/K15umountnfs.sh
ln -s /etc/init.d/umountnfs.sh /etc/rc6.d/K15umountnfs.sh
This will create two symbolic links to the umountnfs.sh script, one in runlevel 0 (shutdown) and one in runlevel 6 (reboot). The links have a “K” prefix to let the init system know that the script should be called with “stop” as an argument, and they have a priority of 15 to ensure that they are run before avahi-daemon and dhcdbd are stopped, which I believe was what was causing my problem. (For more information about runlevels and the symbolic link naming scheme, see this article on Debian Administration. Note that the Debian policy manual states that new runlevel links should have a default priority of 20, but I found that 20 was too low a priority; 15 seems to work.)
By the way, if you’re looking for a more automated way to manage your runlevels, try the update-rc.d utility. I think it would be more of a burden in this case than just creating the links by hand, but you may find it useful for more general runlevel management tasks.
Everything seems to be working smoothly now! Again, sorry for the trouble created by my incomplete earlier post. Please let me know if this works for you.
Hello! Could you post your umountnfs.sh ? =) (Maybe Email it to me.)
Simon
December 30, 2007 at 8:59 am
[…] causing the following error when you shut down your Ubuntu box (a fuller explanation can be found here): CIFS VFS: no response for cmd […]
The World According to Marcus Furius » Mount a NAS device at startup in Ubuntu (8.04)
April 26, 2008 at 4:42 am
works like a charm! thanks for sharing dude!
hans
May 2, 2008 at 8:00 pm
Didnt help for me, and the other 100 solutions also dont fix this. If Im connected by eth0, no problem, but if Im connected by wlan, cpu will hang.
kari
March 7, 2010 at 4:39 am
Works ok on lucid 10.04 ! Thanx
Derf
May 10, 2010 at 2:44 pm
[…] Well, the next bug is not new to hardy heron, but at least very annoying. Having some samba filesystem mounted the reboot/ shutdown process lasts longer as expected. When you disable the splash screen you can read the message CIFS VFS: no response for cmd 50…. I found the solution here: Unmount Samba filesystems before shutdown or reboot. […]
gauda.de » Blog Archive » Gotchas and Bugs in Kubuntu Hardy Heron (8.4)
May 3, 2008 at 6:51 am
Nice! that’s one of the easiest fixes I’ve had to do all week!
elustran
May 8, 2008 at 4:23 pm
thank you so much – no more nights without sleep and no more worn out fingertips – i´m a mouse freak.
gesders
May 16, 2008 at 8:18 am
Hi, my Kubuntu box has in rc0.d and rc6.d folders symlinks to /init.d/umountnfs.sh but with the name of S31umountnfs.sh. which is rigth?
Sotiris
June 15, 2008 at 5:21 am
Hi, in rc0.d/ and rc6.d/ folders I changed the symlinks to S15umountnfs.sh and works fine! I dont know why it works or if it should work but it does. Now the reason I did this was because the script name was unmountnfs.sh, so it had to start to unmount the network shares not kill the umnount of network shares in shutdown or reboot. Anyway I am running Kubuntu 8.04 on a Fukitsu Siemens Amilo Xi1546 using kernel 2.6.24-19-generic. I hope my comment helps to, like the original post did.
Sotiris
June 17, 2008 at 12:55 pm
Thanks. Worked beautifully on Ubuntu that is connected to a Win2k server. Regards
Brendan
Brendan
September 29, 2008 at 3:44 am
the only problem is that its hard to realize why the thing wont shutdown in the first place.
thanks a lot.
l337
October 10, 2008 at 4:39 pm
[…] On shutdown I get a error about CIFS that causes a lockup of about a minute. It’s caused because Ubuntu tries to unmount Samba shares after shutting down network services. (see here for a fix. […]
Tom Fotherby’s Blog » Blog Archive » New release of Ubuntu - “Intrepid Ibex”
November 2, 2008 at 6:48 pm
Perfect!
Thanks, worked like a charm!
Jay
December 31, 2008 at 12:20 am
[…] meantime, the problem can be mitigated (although not entirely erased) by following the instructions here. I found other instructions, etc., online, but this was the simplest of them. I also figured out, […]
Permanently Mounting Network Hard Drives « Positronic Brain
January 12, 2009 at 2:16 am
[…] on how to do this in the Ubuntu forums but I found a good blog with all this info in one place here. The code you need to run to make the symbolic links is here. ln -s /etc/init.d/umountnfs.sh […]
0wn th3 1n73r.net » Blog Archive » Error with CIFS on shutdown in Linux
January 20, 2009 at 1:04 am
The fix worked like a charm on kubuntu 8.04. It does nothing for the kubuntu 8.10 though. The links are in place, but i still get CIFS errors on shutdown.
Any help would be much appreciated.
Alan
January 29, 2009 at 7:42 am
Thanks for the fix. It works perfectly in Ubuntu 8.10 64bit edition.
I wonder why since this been an issue for the past 2+ years didn’t they include this fix in the current releases?!?!?!
Scott
February 17, 2009 at 12:26 am
[…] already disconnected your lan connection before smbfs could unmount your shares. There is however a work around. I have been using the work around for several weeks without adverse side effects. « […]
Automatically Mount Samba Shares via Fstab « Ash’s Blog
March 5, 2009 at 2:50 am
[…] It’s unbelievable that this still isn’t fixed in Jaunty, and I’ve never really got the workarounds working. But the most common is to move the unmounting command up the stack of priorities when shutting down or suspending. To do this, as The World shows: […]
Ubuntu bug with Samba shares unmounting « The Crane Has Landed
July 4, 2009 at 8:14 pm
Your solution didnt work for me :S
So i made up a little shell program to solve the problem. Maybe it will help someone else.
Is an installer in fact, so just put it on a text file called install.sh with chmod+x and run it on a terminal:
#!/bin/bash
echo “Empieza!”
echo ‘#!/bin/bash
#
# desmontartodo – Unmounts samba-cifs filesystems
# -> convenience script to be called in the shutdown/reboot sequence of Ubuntu Dapper
# as K02desmontartodo
# Written by Max Durden
# max.durden@gmail.com
#
start() {
echo “desmontartodo: nothing to do!”
}
stop() {
echo “Unmounting all filesystems but root…”
umount -a
}
status() {
echo “Mounted samba-cifs filesystems…”
mount -l
}
restart() {
echo “restart …”
start
}
reload() {
echo “start …”
start
}
force_reload() {
echo “force-reload …”
start
}
case $1 in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
reload)
reload
;;
force-reload)
force_reload
;;
*)
echo “Usage: c {start|stop|restart|reload|force-reload|status}”
;;
esac
exit 0′ > desmontartodo.sh
direccionInit=”/etc/init.d”
direccionR0=”/etc/rc0.d”
direccionR6=”/etc/rc6.d”
sudo cp ./desmontartodo.sh “$direccionInit”
sudo chmod 777 “$direccionInit”/desmontartodo.sh
sudo ln -s “$direccionInit”/desmontartodo.sh “$direccionR0″/K01aadesmonador
sudo ln -s “$direccionInit”/desmontartodo.sh “$direccionR6″/K01aadesmonador
sudo rm ./desmontartodo.sh
echo “Listo!”
Antilope
September 26, 2009 at 6:32 am
i forgot to say that i based on someone elses solution (a guy called Max Durden in fact)
And here is a remover:
#!/bin/bash
direccionInit=”/etc/init.d”
direccionR0=”/etc/rc0.d”
direccionR6=”/etc/rc6.d”
sudo rm “$direccionR0″/K01aadesmonador
sudo rm “$direccionR6″/K01aadesmonador
sudo rm “$direccionInit”/desmontartodo.sh
echo “Fue eliminado”
Antilope
September 26, 2009 at 6:35 am
[…] https://whereofwecannotspeak.wordpress.com/2007/12/25/unmount-samba-filesystems-before-shutdown-or-re… […]
Démonter les partages Samba avant l'arrêt du système | Ta vie on s'en fout!
October 7, 2009 at 6:41 am
Thx dude!! help me allot!
sebastian
October 20, 2009 at 10:04 am
Thank you for that info, and the links.
Very succinct and clear instructions, which I found worked fine under Ubuntu 9.04.
Without such admirable support, Linux would be dead in the water.
Kindest Regards,
Phil
(Old Swan Band, UK)
Phil Headford
March 22, 2010 at 4:36 am
[…] https://whereofwecannotspeak.wordpress.com/2007/12/25/unmount-samba-filesystems-before-shutdown-or-re… […]
ter Smitten's » How to resolve the “CIFS VFS: Server not responding” error on shutdown
July 24, 2010 at 8:52 am
[…] 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 […]
System hangs on shutdown if Windows network drive in fstab Drija
November 16, 2010 at 12:49 am
[…] causing the following error when you shut down your Ubuntu box (a fuller explanation can be found here): CIFS VFS: no response for cmd […]
Mount a NAS in Hardy Heron | Marcus Furius Development
March 3, 2011 at 4:51 pm
Thanks for this article. While a bit old meanwhile, it helped me to fix the slow shutdown process on my Ubuntu 11.10 machine.
Arnaud
January 10, 2012 at 1:15 pm
[…] have followed the wiki on this topic and applied this solution to fix the hang on shutdown and referred to a few other posts on here but can’t get a […]
How to permanently mount a network folder? - ubuntutextbook
September 9, 2016 at 10:40 am