5

My shutdown takes quite a long time (I'm on Debian 8.1) and I found out that it can be fixed by unmounting the network drive before shutting down the system. Apparently the network gets disconnected before all the drives are unmounted.

To do this automatically I tried to create a systemd service but it doesn't work, i.e. it doesn't seem to do the unmount in time and the shutdown process still takes quite long. My approach is inspired by the answers to this questions as well as some browsing of the systemd.service man pages...

[unit]
description=Unmount network drives on shutdown
Before=shutdown.target reboot.target halt.target network.target

[Service]
type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=/bin/sh umount /media/networkdrive1 /media/networkdrive2

[Install]
WantedBy=multi-user.target

Edit

The network drives are mounted in /etc/fstab with the following lines:

//192.168.1.5/networkdrive1 /media/nw1 cifs _netdev,uid=myuser,credentials=/home/myuser/.credfile
//192.168.1.5/networkdrive2 /media/nw2 cifs _netdev,uid=myuser,credentials=/home/myuser/.credfile
  • Here someone said in 2008: "it is a very old and well known problem". It is 2017 and I still suffer from this issue. Did anyone find a working solution? – SkyRaT Apr 22 '17 at 12:56
2

Add the _netdev mount option to the remote filesystems in /etc/fstab. After a systemctl daemon-reload this should make your network mounts dependencies of the remote-fs.target; check it with systemctl list-dependencies remote-fs.target. Such filesystems are unmounted before network is brought down.

  • 1
    I have this in my fstab already, see edit above. The drives also show up in the dependencies list. However if I shutdown without manually unmounting the drives, it takes ~2 mintues or so. If I unmount the drives manually before shutting down, the PC turns down nearly instantly.... – pandita Aug 30 '15 at 20:12
  • Interesting. You could try following the official debug instructions. – Ferenc Wágner Sep 14 '15 at 11:35
2

After 3 days of searching and testing, I developed a working solution -- this is for a Debian-Jessie, Linux Mint, i386 (32-bit) installation. I have network cifs shares, that hang shutdown or reboot for 120 seconds if these are not umounted first. With this script, I don't have to manually umount the shares before reboot or shutdown.

Auto cifs umount script, runs on shutdown and reboot

  • create the following script as /etc/init.d/aaaumount (scripts are executed in number, and alpha order, that's why the aaa, so this runs first):

    #!/bin/sh
    
    #
    # aaaumount initscript
    #
    ### BEGIN INIT INFO
    # Provides:          aaaumount
    # Required-Start:    $local_fs $remote_fs
    # Required-Stop:     $remote_fs
    # Default-Start:     S
    # Default-Stop:      0 1 6
    # Short-Description: umounts cifs shares
    # Description:       This script unmounts cifs shares
    ### END INIT INFO
    
    case "$1" in
     stop)
                umount -t cifs -af
    esac
    
  • make it executable:

    sudo chmod 755 /etc/init.d/aaaumount
    
  • make symbolic link to the service in /lib/systemd/system/:

    cd /lib/systemd/system/
    sudo ln -s /dev/null aaaumount.service
    
  • make symbolic links in both /etc/rc0.d and /etc/rc6.d (0 and 6 are shutdown/reboot run levels):

    sudo ln -s /etc/init.d/aaaumount /etc/rc0.d/K01aaaumount 
    sudo ln -s /etc/init.d/aaaumount /etc/rc6.d/K01aaaumount 
    
  • activate it:

    sudo systemctl enable aaaumount.service
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.