I have two network shares I mount on my Wheezy laptop via fstab. But when they are mounted my laptop hangs on poweroff of reboot. The cause is that the network part of the system is stopped before the shares are unmounted. The solution is to unmount the shares before the network part is stopped.

The shares I am mounting are Samba shares but I’ve also experienced this with nfs shares. I have two of them; one is mounted on /home/vorkbaard/vorkbaard and the other on /home/vorkbaard/media.

First create a script to unmount the shares and put the script in the designated directory of /etc/init.d/. Let’s call the script unmount_shares.sh. Put this in it:

#!/bin/bash
umount /home/vorkbaard/vorkbaard
umount /home/vorkbaard/media
exit

Make the script executable:

chmod +x /etc/init.d/unmount_shares.sh

Now, I want this script to be executed:
– before the networking is stopped;
– in runlevels 0 (poweroff) and 6 (reboot).

Let’s see which priority the networking has in those runlevels (checkling poweroff for now):

ls /etc/rc0.d/

Networking is the 25th item in the list on my system so I need to run my script with a lower priority, for example 10.

Now that I have the unmount script and I know what priority to give it, I should make symlinks to the appropriate runlevels. I can use update-rc.d for that:

update-rc.d unmount_shares.sh start 10 0 6

‘Start’ here just means: execute the script. 10 is the priority and 0 and 6 the runlevels.

After this my Wheezytop happily powers down or reboots \o/