About Me

My photo
I know the last digit of PI

Monday, May 07, 2018

Unmount all cifs shares before sleep/hibernate/suspend

I noticed when I close the lid of my laptop and there are mounted cifs shares, it takes 2 minutes before I am able to login after resume. I track down the problem to samba trying to reconnect mounted shares. The easiest way to fix that is to unmount everything before Fedora is going to sleep. Just create a script in /usr/lib/systemd/system-sleep/mounts with following content:
#!/bin/bash

case "${1}" in
  pre)
  # your command to umount here
    for m in `mount | grep /mnt | grep // | grep cifs | awk '{print $3}'`; do 
      echo "Unmounting $m"
      umount -f $m
    done 
  ;;
  post)
  # (possibly) your command to mount here
  ;;
esac