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.