#! /bin/sh ### BEGIN INIT INFO # Provides: umountfs # Required-Start: # Required-Stop: umountroot # Default-Start: # Default-Stop: 0 6 # Short-Description: Turn off swap and unmount all local file systems. # Description: ### END INIT INFO setvar PATH = "/sbin:/usr/sbin:/bin:/usr/bin" source /lib/init/vars.sh source /lib/lsb/init-functions umask 022 proc do_stop { setvar PROTECTED_MOUNTS = "$(sed -n ':a;/^[^ ]* \/ /!{H;n;ba};{H;s/.*//;x;s/\n//;p}' /proc/mounts)" setvar WEAK_MTPTS = """" # be gentle, don't use force setvar REG_MTPTS = """" setvar TMPFS_MTPTS = """" while read -r DEV MTPT FSTYPE REST { echo $PROTECTED_MOUNTS | grep -qs "^$DEV $MTPT " && continue match $MTPT { with /|/proc|/dev|/.dev|/dev/pts|/dev/shm|/dev/.static/dev|/proc/*|/sys|/sys/*|/run|/run/*|/dev/vcs continue } match $FSTYPE { with proc|procfs|linprocfs|sysfs|usbfs|usbdevfs|devpts continue with tmpfs setvar TMPFS_MTPTS = ""$MTPT $TMPFS_MTPTS"" with * if echo $PROTECTED_MOUNTS | grep -qs "^$DEV " { setvar WEAK_MTPTS = ""$MTPT $WEAK_MTPTS"" } else { setvar REG_MTPTS = ""$MTPT $REG_MTPTS"" } } } < /proc/mounts # # Make sure tmpfs file systems are umounted before turning off # swap, to avoid running out of memory if the tmpfs filesystems # use a lot of space. # if test $TMPFS_MTPTS { if test $VERBOSE = no { log_action_begin_msg "Unmounting temporary filesystems" fstab-decode umount $TMPFS_MTPTS log_action_end_msg $Status } else { log_daemon_msg "Will now unmount temporary filesystems" fstab-decode umount -v $TMPFS_MTPTS log_end_msg $Status } } # # Deactivate swap # if test $VERBOSE = no { log_action_begin_msg "Deactivating swap" swapoff -a >/dev/null log_action_end_msg $Status } else { log_daemon_msg "Will now deactivate swap" swapoff -a -v log_end_msg $Status } # # Unmount local filesystems # if test $WEAK_MTPTS { # Do not use -f umount option for WEAK_MTPTS if test $VERBOSE = no { log_action_begin_msg "Unmounting weak filesystems" fstab-decode umount -r -d $WEAK_MTPTS log_action_end_msg $Status } else { log_daemon_msg "Will now unmount weak filesystems" fstab-decode umount -v -r -d $WEAK_MTPTS log_end_msg $Status } } if test $REG_MTPTS { if test $VERBOSE = no { log_action_begin_msg "Unmounting local filesystems" fstab-decode umount -f -r -d $REG_MTPTS log_action_end_msg $Status } else { log_daemon_msg "Will now unmount local filesystems" fstab-decode umount -f -v -r -d $REG_MTPTS log_end_msg $Status } } } match $1 { with start|status # No-op with restart|reload|force-reload echo "Error: argument '$1' not supported" >&2 exit 3 with stop do_stop with * echo "Usage: $0 start|stop" >&2 exit 3 } :