| 1 |
#! /bin/sh |
| 2 |
### BEGIN INIT INFO |
| 3 |
# Provides: umountfs |
| 4 |
# Required-Start: |
| 5 |
# Required-Stop: umountroot |
| 6 |
# Default-Start: |
| 7 |
# Default-Stop: 0 6 |
| 8 |
# Short-Description: Turn off swap and unmount all local file systems. |
| 9 |
# Description: |
| 10 |
### END INIT INFO |
| 11 |
|
| 12 |
PATH=/usr/sbin:/usr/bin:/sbin:/bin |
| 13 |
. /lib/init/vars.sh |
| 14 |
|
| 15 |
. /lib/lsb/init-functions |
| 16 |
|
| 17 |
umask 022 |
| 18 |
|
| 19 |
do_stop() { |
| 20 |
PROTECTED_MOUNTS="$(sed -n ':a;/^[^ ]* \/ /!{H;n;ba};{H;s/.*//;x;s/\n//;p}' /proc/mounts)" |
| 21 |
WEAK_MTPTS="" # be gentle, don't use force |
| 22 |
REG_MTPTS="" |
| 23 |
TMPFS_MTPTS="" |
| 24 |
while read -r DEV MTPT FSTYPE REST; do |
| 25 |
echo "$PROTECTED_MOUNTS" | grep -qsF "$DEV $MTPT " && continue |
| 26 |
case "$MTPT" in |
| 27 |
/ | /usr | /proc | /dev | /.dev | /dev/pts | /dev/shm | /dev/.static/dev | /proc/* | /sys | /sys/* | /run | /run/lock | /run/shm | /run/rpc_pipefs | /dev/vcs) |
| 28 |
continue |
| 29 |
;; |
| 30 |
esac |
| 31 |
case "$FSTYPE" in |
| 32 |
proc | procfs | linprocfs | sysfs | securityfs | usbfs | usbdevfs | devpts) |
| 33 |
continue |
| 34 |
;; |
| 35 |
tmpfs) |
| 36 |
TMPFS_MTPTS="$MTPT $TMPFS_MTPTS" |
| 37 |
;; |
| 38 |
*) |
| 39 |
if echo "$PROTECTED_MOUNTS" | grep -qs "^$DEV "; then |
| 40 |
WEAK_MTPTS="$MTPT $WEAK_MTPTS" |
| 41 |
else |
| 42 |
REG_MTPTS="$MTPT $REG_MTPTS" |
| 43 |
fi |
| 44 |
;; |
| 45 |
esac |
| 46 |
done </proc/mounts |
| 47 |
|
| 48 |
# |
| 49 |
# Make sure tmpfs file systems are umounted before turning off |
| 50 |
# swap, to avoid running out of memory if the tmpfs filesystems |
| 51 |
# use a lot of space. |
| 52 |
# |
| 53 |
if [ "$TMPFS_MTPTS" ]; then |
| 54 |
if [ "$VERBOSE" = no ]; then |
| 55 |
log_action_begin_msg "Unmounting temporary filesystems" |
| 56 |
fstab-decode umount --recursive $TMPFS_MTPTS |
| 57 |
log_action_end_msg $? |
| 58 |
else |
| 59 |
log_daemon_msg "Will now unmount temporary filesystems" |
| 60 |
fstab-decode umount --recursive -v $TMPFS_MTPTS |
| 61 |
log_end_msg $? |
| 62 |
fi |
| 63 |
fi |
| 64 |
|
| 65 |
# |
| 66 |
# Deactivate swap |
| 67 |
# |
| 68 |
if [ "$VERBOSE" = no ]; then |
| 69 |
log_action_begin_msg "Deactivating swap" |
| 70 |
swapoff -a >/dev/null |
| 71 |
log_action_end_msg $? |
| 72 |
else |
| 73 |
log_daemon_msg "Will now deactivate swap" |
| 74 |
swapoff -a -v |
| 75 |
log_end_msg $? |
| 76 |
fi |
| 77 |
|
| 78 |
# |
| 79 |
# Unmount local filesystems |
| 80 |
# |
| 81 |
if [ "$WEAK_MTPTS" ]; then |
| 82 |
# Do not use -f umount option for WEAK_MTPTS |
| 83 |
if [ "$VERBOSE" = no ]; then |
| 84 |
log_action_begin_msg "Unmounting weak filesystems" |
| 85 |
fstab-decode umount -r -d $WEAK_MTPTS |
| 86 |
log_action_end_msg $? |
| 87 |
else |
| 88 |
log_daemon_msg "Will now unmount weak filesystems" |
| 89 |
fstab-decode umount -v -r -d $WEAK_MTPTS |
| 90 |
log_end_msg $? |
| 91 |
fi |
| 92 |
fi |
| 93 |
if [ "$REG_MTPTS" ]; then |
| 94 |
if [ "$VERBOSE" = no ]; then |
| 95 |
log_action_begin_msg "Unmounting local filesystems" |
| 96 |
fstab-decode umount -f -r -d $REG_MTPTS |
| 97 |
log_action_end_msg $? |
| 98 |
else |
| 99 |
log_daemon_msg "Will now unmount local filesystems" |
| 100 |
fstab-decode umount -f -v -r -d $REG_MTPTS |
| 101 |
log_end_msg $? |
| 102 |
fi |
| 103 |
fi |
| 104 |
} |
| 105 |
|
| 106 |
case "$1" in |
| 107 |
start | status) |
| 108 |
# No-op |
| 109 |
;; |
| 110 |
restart | reload | force-reload) |
| 111 |
echo "Error: argument '$1' not supported" >&2 |
| 112 |
exit 3 |
| 113 |
;; |
| 114 |
stop) |
| 115 |
do_stop |
| 116 |
;; |
| 117 |
*) |
| 118 |
echo "Usage: $0 start|stop" >&2 |
| 119 |
exit 3 |
| 120 |
;; |
| 121 |
esac |
| 122 |
|
| 123 |
: |