在 Linux 中,“绑挂”(bind mount)是指把一个已经挂载的目录或文件,再挂载到另一个位置,让两个路径看到相同的内容。常用于容器、chroot、共享目录等场景。
下面按常见用法说明。
mkdir /source
mkdir /target
mount --bind /source /target
此时:
/target 的内容会变成 /source/target 的修改会同步到 /sourcemount | grep bind
或
findmnt
umount /target
mount --bind /source /target
mount -o remount,ro /target
或一次性:
mount --bind -o ro /source /target
touch /etc/config.conf
cp /etc/config.conf /tmp/config.conf
mount --bind /etc/config.conf /tmp/config.conf
常用于:
/source /target none bind 0 0
/source/file /target/file none bind 0 0
bind mount 默认只在当前 mount namespace 生效,常见于:
unsharesystemd-nspawn示例:
unshare --mount --fork bash
mount --bind /source /target
⚠️ bind mount 不会递归挂载子挂载点
mount --bind /mnt /target
# /mnt/usb 不会自动出现在 /target/usb
如需递归:
mount --rbind /mnt /target
如果你有具体场景(如 Docker、chroot、NFS、容器、systemd),可以告诉我,我可以给更针对性的示例。