[arch-projects] [PATCH 2/2] swapoff: umount swap-backed fs before switching off swap
C Anthony Risinger
anthony at xtfx.me
Mon Oct 31 01:22:03 EDT 2011
On Sat, Oct 29, 2011 at 8:54 PM, Dave Reisner <d at falconindy.com> wrote:
>
> So, as we discussed, I does not like your umount_all. It'll be really
> nice when umount can do this on its own, but until then, something such
> as the following should suffice:
>
> umount_all() {
> while read -r fstype options target; do
> # match only targetted fstypes
> if [[ $1 && $1 != "$fstype" ]]; then
> continue
> fi
>
> # don't unmount API filesystems
> if [[ $target = /@(proc|sys|run|dev)?(/*) ]]; then
> continue
> fi
>
> # avoid networked devices
> IFS=, read -ra opts <<< "$options"
> if in_array _netdev "${opts[@]}"; then
> continue
> fi
>
> mounts+=("$target")
> done < <(findmnt -runRo FSTYPE,OPTIONS,TARGET / | tac)
> }
hey,
i only recently joined/realized i could post to this list ... if there
is an established etiquette/procedure that i'm breaking (now or ever),
just lmk.
... btw, you should be able to eliminate the call to `tac` via
`findmnt -d backward [...]`.
however, i wrote a simple routine semi-recently for a project that may
be useful -- it reads `/proc/self/mountinfo` directly (like findmnt),
but it also makes use of `tsort` to automatically order the umounts
properly (findmnt doesn't seem to do this) -- it can handle any
arbitrary depth, original mount order, `--bind`, and `--move` (the
latter will unsort the mountinfo table):
-------------------------------------------------------------------
# cat umountall.sh
#!/bin/bash
IFS=;
mnts=$(sort -k1n /proc/self/mountinfo | tr -s ' ' '\t');
topo=$(echo ${mnts} | cut -f1,2 | tsort | nl -w1 | sort -k2n);
join -o1.1,2.5 -t$'\t' -12 -21 - <(echo ${mnts}) <<<${topo} | sort -k1n;
# ./umountall.sh
1 /run
2 /dev/shm
3 /dev/pts
4 /sys/fs/cgroup/systemd
5 /sys/fs/cgroup/cpuset
6 /sys/fs/cgroup/cpu,cpuacct
7 /sys/fs/cgroup/memory
8 /sys/fs/cgroup/devices
9 /sys/fs/cgroup/freezer
10 /sys/fs/cgroup/net_cls
11 /sys/fs/cgroup/blkio
12 /proc/sys/fs/binfmt_misc
13 /var/run
14 /var/lock
15 /dev/mqueue
16 /dev/hugepages
17 /sys/kernel/security
18 /sys/kernel/debug
19 /media
20 /boot
21 /home/anthony/.gvfs
22 /sys/fs/fuse/connections
23 /sys/fs/cgroup
24 /proc
25 /dev
26 /boot
27 /sys
28 /
-------------------------------------------------------------------
execution shows you [a] proper umount order -- not the best example
because my system is not that interesting, but it really should work
for *anything* so long as the kernel doesn't lie.
more fields added by modifying the `join` command, eg. `join
-o1.1,2.5,2.6` additionally outputs the mount options.
pathnames are octal(?) encoded, thus easy to handle, but need to be
expanded before actual umount (`echo -e` or `printf`[?] or ???)
all binaries are in `coreutils` package
there was mention of a shudown hook after a pivot_root recently --
this should work well for that. if there is a simpler way to
accomplish this, i'd love to here that as well.
this isn't my original but it's tested and functions the same. the
original just did a little more like unmount everything under a
specific path, or filter stuff out (eg. /proc, /dev, ...) by using the
unique mount id; can provide all that if interested.
--
C Anthony
More information about the arch-projects
mailing list