以下命令序列将在 CentOS 7(内核版本: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
mount
、cat /proc/mounts
、cat /etc/mtab
、sudo lsof
、均未sudo fuser C/b
显示任何使用该目录的进程C/b
;stat C/b
显示它与 inode 不同B
,这意味着它已经成功卸载。
这些命令是重现我尝试 rbind/dev
和/proc
沙箱时发现的问题的最小示例,但当我尝试销毁沙箱时失败。 make-rslave
这里是必要的,否则下面的子安装/dev/
将被卸载,这会弄乱系统。
这些命令适用于 Ubuntu 14.04(内核版本 3.13.xx)和 Fedora 23(内核版本 4.x)。
我的问题是,如果由于某种原因我必须坚持使用 CentOS 7,我该如何解决这个问题并彻底销毁沙箱?
答案1
尝试在环境umount -a
内做chroot
;然后退出,umount -l
如果umount -R
失败。
(chroot) # umount -a
(chroot) # exit
(liveos) #
(liveos) # umount -R /mnt/point/
(liveos) # umount -l /mnt/point/
-R, --recursive
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.
-l, --lazy
Lazy unmount. Detach the filesystem from the file hierarchy now, and clean up all references to this
filesystem as soon as it is not busy anymore. (Requires kernel 2.4.11 or later.)