Recursive umount after rbind mount
This worked for me correctly -- https://unix.stackexchange.com/a/264488/4319:
mount --rbind /dev /mnt/test
mount --make-rslave /mnt/test
umount -R /mnt/test
It was important to have the two first commands as two separate commands: do not combine --rbind
and --make-rslave
in one invocation of mount.
Without --make-rslave
, the behavior was unwanted (and not successful):
umount -l
would affect the original old mountpoints, too,- and
umount -R
would be affected by the busy (open) files under the original old mountpoints. (Very unexpected...)
The credit goes to Gilles for this answer; Gilles noted in the question comments that the '-n' switch ignores the mtab and unmounts anything listed in /proc/mounts.
From the manpage:
-n Unmount without writing in /etc/mtab.
So to answer my question of how to unravel a --rbind mount, this is the full command that worked for me:
grep /mnt/chroot/sys /proc/mounts | cut -f2 -d" " | sort -r | xargs umount -n
Merci, Gilles!
Since util-linux v2.23 (25-Apr-2013) the umount
command supports the -R, --recursive
option.
Here is what the man page says:
Recursively unmount each specified directory. Recursion for each directory will stop if any unmount operation in the chain fails for any reason. The relationship between mountpoints is determined by
/proc/self/mountinfo
entries. The filesystem must be specified by mountpoint path; a recursive unmount by device name (or UUID) is unsupported.
For filesystems mounted with --rbind
it might be needed to run mount --make-rslave
before trying to unmount them if umount
complains about device is busy
.