10

Asked on serverfault but didn't get enough attention, so reposted here, with the hope some people here know the answer.

There is another question discussing about umounting rbind mounts, but the solution has unwanted effect. Consider the following directory layout:

.
├── A_dir
│   └── mount_b
├── B_dir
│   └── mount_c
└── C_dir

Now I bind C_dir to B_dir/mount_c and rbind B_dir to A_dir/mount_b:

[hidden]$ sudo mount --bind C_dir B_dir/mount_c
[hidden]$ sudo mount --rbind B_dir A_dir/mount_b
[hidden]$ mount | grep _dir | wc -l
3

Now umount A_dir/mount_b will fail, which is not surprising. According to the answers everywhere on the web, we need to umount A_dir/mount_b/mount_c first then umount A_dir/mount_b. However, umount A_dir/mount_b/mount_c will also unmount B_dir/mount_c, which is unwanted:

[hidden]$ sudo umount A_dir/mount_b/mount_c
[hidden]$ mount | grep _dir | wc -l
1

Now my question is, how do I unmount A_dir/mount_b but leaving B_dir unaffected, i.e. there is still a bind B_dir/mount_c to C_dir?

EDIT: this problem doesn't seem to appear in Ubuntu. More specifically, it works fine on my Ubuntu 14.04 but not working on Fedora 23 and CentOS 7. Why there is the difference and what's the work around for Fedora and CentOS?

EDIT: some more information on the actual problem that I am trying to solve. I tried to create a sandbox and used --rbind to mount the /dev and /proc to the sandbox. When destroying the sandbox, it seems I can't cleanly destroy it because unmounting <sandbox-root>/dev/pts in FC23 and CentOS7 will unmount /dev/pts, after which my shell and SSH connections hang and I have to reboot the machine. That's why I am asking if there is a way to unmount the --rbind mounts without affecting submounts.

8

I found the solution myself. I simply just need to use --make-rslave to make any changes in A_dir/mount_b not propagate back to B_dir:

sudo mount --make-rslave A_dir/mount_b
sudo umount -R A_dir/mount_b

See mount man page section The shared subtree operations.

  • 1
    In some systems, one can even combine mount --rbind src target --make-rslave in one call; some systems used to disallow this for me. – imz -- Ivan Zakharyaschev Apr 9 '18 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.