Tuesday, January 4, 2011

findmnt(8) and submounts

I just applied (to the util-linux upstream) a patch that allows to list all submounts for defined filesystem(s). For example:
$ findmnt --submounts /sys
TARGET SOURCE FSTYPE OPTIONS
/sys /sys sysfs rw,relatime
├─/sys/fs/cgroup tmpfs tmpfs rw,nosuid,nodev,noexec,relat
│ ├─/sys/fs/cgroup/systemd cgroup cgroup rw,nosuid,nodev,noexec,relat
│ ├─/sys/fs/cgroup/cpuset cgroup cgroup rw,nosuid,nodev,noexec,relat
│ ├─/sys/fs/cgroup/ns cgroup cgroup rw,nosuid,nodev,noexec,relat
│ ├─/sys/fs/cgroup/cpu cgroup cgroup rw,nosuid,nodev,noexec,relat
│ ├─/sys/fs/cgroup/cpuacct cgroup cgroup rw,nosuid,nodev,noexec,relat
│ ├─/sys/fs/cgroup/memory cgroup cgroup rw,nosuid,nodev,noexec,relat
│ ├─/sys/fs/cgroup/devices cgroup cgroup rw,nosuid,nodev,noexec,relat
│ ├─/sys/fs/cgroup/freezer cgroup cgroup rw,nosuid,nodev,noexec,relat
│ ├─/sys/fs/cgroup/net_cls cgroup cgroup rw,nosuid,nodev,noexec,relat
│ └─/sys/fs/cgroup/blkio cgroup cgroup rw,nosuid,nodev,noexec,relat
├─/sys/kernel/security systemd-1 autofs rw,relatime,fd=22,pgrp=1,tim
├─/sys/kernel/debug systemd-1 autofs rw,relatime,fd=24,pgrp=1,tim
└─/sys/fs/fuse/connections fusectl fusectl rw,relatime
returns info about /sys and all /sys submounts.

Now you can implement recursive umount in shell, something like:
for d in $(findmnt --list --submounts $MOUNTPOINT -o TARGET -n | tac); do
umount $d
done
I hope that umount(8) will support something like this ASAP.

No comments:

Post a Comment