Shr*_*ray 14 filesystem umount mount bind
我很迷惑。Linux文件系统是一个树状结构,以根节点(起始节点)为根目录。现在让我们假设我有一个文件夹abc的位置 /home/abc和其他文件夹xyz的位置/home/xyz
文件夹xyz由其中的一些其他文件夹和文件组成。(例如def,mno是其中的文件夹)
/
??? home/
? ??? abc
? ??? xyz
? ??? def
? ??? mno
Run Code Online (Sandbox Code Playgroud)
当我运行命令时
mount --rbind /home/xyz /home/abc
Run Code Online (Sandbox Code Playgroud)
(rbind 是递归绑定)我xyz在abc. 现在,当我运行命令时
mount --bind /home/xyz /home/abc
Run Code Online (Sandbox Code Playgroud)
我仍然看到xyzin 的所有内容abc。
这是为什么?
--bind工作方式与--rbind.
Eli*_*gan 14
您已经正确地观察到,同时使用--bind和--rbind,您会看到绑定安装下的目录。
区别在于,使用--rbind而不是使用--bind,您会在绑定安装下看到其他绑定安装的内容。
适用于您的示例,为简单起见,假设/home/xyz/def和/home/xyz/mno是空目录。进一步假设您然后将它们用作绑定安装,即,您将它们用作mount --bind或 中的安装点mount --rbind。这会导致它们显示为非空。然后,假设你运行:
mount --bind /home/xyz /home/abc
Run Code Online (Sandbox Code Playgroud)
然后,/home/abc/def并且/home/abc/mno两者都存在,但它们看起来是空的,因为您使用了,这是非递归的。mount --bind
相反,假设您/home/abc通过运行以下命令进行了绑定安装:
mount --rbind /home/xyz /home/abc
Run Code Online (Sandbox Code Playgroud)
然后,/home/abc/def并且/home/abc/mno两者都存在并且它们看起来是非空的——它们具有/home/xyz/def和/home/xyz/mno绑定装载的内容——因为你使用了,这是递归的。mount --rbind
这是一个完整的示例:
ek@Gnar:~$ mkdir original
ek@Gnar:~$ touch original/a-regular-file
ek@Gnar:~$ mkdir original/a-directory
ek@Gnar:~$ mkdir parent-of-mountpoint
ek@Gnar:~$ mkdir parent-of-mountpoint/mountpoint
ek@Gnar:~$ sudo mount --bind ~/original ~/parent-of-mountpoint/mountpoint
ek@Gnar:~$ mkdir nonrecursive-other-mountpoint recursive-other-mountpoint
ek@Gnar:~$ sudo mount --bind ~/parent-of-mountpoint ~/nonrecursive-other-mountpoint
ek@Gnar:~$ sudo mount --rbind ~/parent-of-mountpoint ~/recursive-other-mountpoint
Run Code Online (Sandbox Code Playgroud)
ek@Gnar:~$ tree -F original/
original/
??? a-directory/
??? a-regular-file
1 directory, 1 file
ek@Gnar:~$ tree -F parent-of-mountpoint/
parent-of-mountpoint/
??? mountpoint/
??? a-directory/
??? a-regular-file
2 directories, 1 file
ek@Gnar:~$ tree -F nonrecursive-other-mountpoint/
nonrecursive-other-mountpoint/
??? mountpoint/
1 directory, 0 files
ek@Gnar:~$ tree -F recursive-other-mountpoint/
recursive-other-mountpoint/
??? mountpoint/
??? a-directory/
??? a-regular-file
2 directories, 1 file
Run Code Online (Sandbox Code Playgroud)
ek@Gnar:~$ mount | grep ~
/dev/sda2 on /home/ek/parent-of-mountpoint/mountpoint type ext4 (rw,relatime)
/dev/sda2 on /home/ek/nonrecursive-other-mountpoint type ext4 (rw,relatime)
/dev/sda2 on /home/ek/recursive-other-mountpoint type ext4 (rw,relatime)
/dev/sda2 on /home/ek/recursive-other-mountpoint/mountpoint type ext4 (rw,relatime)
Run Code Online (Sandbox Code Playgroud)
读man 8 mount。它说(强调):
绑定坐骑
在其他地方重新安装部分文件层次结构。通话内容是:
Run Code Online (Sandbox Code Playgroud)mount --bind olddir newdir或者使用此 fstab 条目:
Run Code Online (Sandbox Code Playgroud)/olddir /newdir none bind在此调用之后,可以在两个地方访问相同的内容。还可以重新挂载单个文件(在单个文件上)。还可以使用绑定挂载从常规目录创建挂载点,例如:
Run Code Online (Sandbox Code Playgroud)mount --bind foo foo绑定挂载调用仅附加单个文件系统(的一部分),而不是可能的子挂载。包括子安装在内的整个文件层次结构通过使用以下命令附加到第二位:
Run Code Online (Sandbox Code Playgroud)mount --rbind olddir newdir请注意,文件系统挂载选项将与原始挂载点上的选项保持相同。
| 归档时间: |
|
| 查看次数: |
15197 次 |
| 最近记录: |