Posts Tagged ‘unmount’

unmount network/encrypted storgage when suspending

Friday, May 13th, 2011

Some file systems hangs on resume from suspend/hibernate, especially network file systems and FUSE-filesystems(encfs by example). I've created a script to unmount file systems when suspending/hibernating:

1
2
3
sudo touch /etc/pm/sleep.d/20_unmount_storage
sudo chmod +x /etc/pm/sleep.d/20_unmount_storage
sudo nano /etc/pm/sleep.d/20_unmount_storage

/etc/pm/sleep.d/20_unmount_storage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
#
# Script which unmounts network storage before suspend and hibernate.
#
# Arve Seljebu 7. May 2011
 
PATH=/sbin:/usr/sbin:/bin:/usr/bin
 
# Which mountpoints we want to umount
MOUNTPOINT[0]=/media/storage/encfs
MOUNTPOINT[1]=/media/storage
#MOUNTPOINT[2]=/media/storage2
# User to run from (user who mounted them)
USER=username
 
if [ ! -x /bin/mountpoint ]; then
  echo "Did not find executable /bin/mounpoint"
  exit 0
fi
 
case "${1}" in
  hibernate|suspend)
    for i in "${MOUNTPOINT[@]}"
    do
    # check if the mountpoint is mounted
    echo "Checking if mountpoint $i is mounted..."
    sudo -u $USER mountpoint $i > /dev/null
    if [ "$?" == "0" ]; then
      # try to umount with fusermount, if not succsessful, try with umount
      echo "Mountpoint $i mounted, umounting..."
      fusermount -u $i
      if [ "$?" != "0" ];
      then umount $i
      fi
    fi
  done
  echo "Done..."
  exit 0
  ;;
  resume|thaw)
  # nothing
  ;;
esac