大网数据广告活动
服务器运维问答

Unmount a rbind mount without affecting the original mount

· 52CE 我爱测

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_d…

问题原文

原帖链接 · icando · CC BY-SA 3.0

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?

Thanks.

社区高分解答

原帖链接 · sourcejedi · CC BY-SA 3.0

Found it. https://unix.stackexchange.com/a/276700/29483

Try --make-rprivate:

mount --make-rprivate A_dir
umount -R A_dir

Note: systemd people, who set your described behaviour as the new default, recommend that you would not make the rbind mount private initially. It's ok to do just before unmount though.

It's because when you clone all the mounts, you might e.g. then need to eject a CD. If it was mounted at clone-time, enabling propagation means you only need to run umount on one location only (e.g. outside the rbind mount, just like normal), and then you'll be able to eject it.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-02-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。