diff options
author | Tom Gundersen <teg@jklm.no> | 2011-10-29 17:26:26 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2011-11-04 22:49:34 +0100 |
commit | 34714bf34e5928479e5ec4367e5e79902876dfa3 (patch) | |
tree | 61a7340d18fed727ff292b5094baa93590e1e940 /functions | |
parent | 3fd0222be7868096e9ed6d97ccee1b3c1ae4d394 (diff) |
swapoff: umount swap-backed fs before switching off swap
Factor out umounting. Explicitly skip umounting API directories, rather
than matching on fs type. This allows us to e.g. unmount all tmpfs but leaving
/run and /dev/shm alone.
v3: fixed some regressions in v2, made 'API filesystems' less general
v2: new umount_all implementation based on proposal by Dave and input from
Anthony. Also, ignore ramfs as it is not backed by swap.
Cc: Dave Reisner <d@falconindy.com>
Cc: C Anthony Risinger <anthony@xtfx.me>
Signed-off-by: Tom Gundersen <teg@jklm.no>
Diffstat (limited to 'functions')
-rw-r--r-- | functions | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -460,6 +460,36 @@ mount_all() { mount -a -t "nosysfs,no${NETFS//,/,no}" -O no_netdev } +umount_all() { + # $1: restrict to fstype + + local mounts + + while read -r target fstype options; do + + # match only targetted fstypes + if [[ $1 && $1 != "$fstype" ]]; then + continue + fi + + # don't unmount API filesystems + if [[ $target = /@(proc|sys|run|dev|dev/pts) ]]; then + continue + fi + + # avoid networked devices + IFS=, read -ra opts <<< "$options" + if in_array _netdev "${opts[@]}"; then + continue + fi + + mounts+=("$target") + done < <(findmnt -runRo TARGET,FSTYPE,OPTIONS / | tac) + + umount -r ${mounts[@]} + +} + remove_leftover() { stat_busy "Removing Leftover Files" # handle this separately until we declare the non-symlinks obsoleted |