Ubuntu – How to unmount nfs on shutdown of system via Network Manager

15.04mountnetwork-managernfsshutdown

I use network manager and mount a NFS drive via a custom script

/etc/NetworkManager/dispatcher.d/99nfs.sh:

#!/bin/sh

IF=$1
STATUS=$2

if [ "${IF}" = "eth0" ] && [ "${STATUS}" = "up" ]; then

        mount /media/media
        exit $?

elif [ "${IF}" = "eth0" ] && [ "${STATUS}" = "down" ]; then
        umount /media/media
fi

But when I shutdown my computer it does not switch of. Pressing ESC revealed that the stop job for unmounting /media/media does not stop running.

How can I properly umount on shutdown? I think the unmount has to happen before NetworkManager disconnects.

Best Answer

Based on adonis' comment I was able to fix this as follows:

  • create a new file /etc/NetworkManager/dispatcher.d/pre-down.d/99nfs.sh
  • make it executable
  • contents:

    #!/bin/sh
    
    logger "down: unmounting nfs shares PREDOWN"
    umount /media/media
    

of course I could also have checked for the interface, but I did not this time.

edit This solution broke. See Networkmanager: dispatcher.d/pre-down.d is not executed on shutdown anymore for followup.

Related Question