The following sequence of commands will fail on CentOS 7 (kernel version: 3.10.0-327.10.1.el7.x86_64):
[hidden]$ mkdir -p A B/a C/b [hidden]$ sudo mount --bind A B/a [hidden]$ sudo mount --rbind B C/b [hidden]$ sudo mount --make-rslave C/b [hidden]$ sudo umount C/b/a [hidden]$ sudo umount C/b [hidden]$ rmdir C/b rmdir: failed to remove ‘C/b’: Device or resource busy
sudo fuser C/b shows any process using the directory
stat C/b shows it is different inode than
B, meaning it has already been unmounted successfully.
These commands are the smallest example to reproduce an issue I found when I tried to rbind
/proc to a sandbox, and failed when I tried to destroy the sandbox.
make-rslave is necessary here, otherwise submounts under
/dev/ will be unmounted, which messes up the system.
These commands work for Ubuntu 14.04 (kernel version 3.13.xx) and Fedora 23 (kernel version 4.x).
My question is, if I have to stick to CentOS 7 for some reason, how do I work around the issue and destroy the sandbox cleanly?