Linux 如何处理挂载点中的现有文件?

Linux 如何处理挂载点中的现有文件?

如果我尝试挂载一个其中已经有文件的文件夹,linux 会给我一个错误消息还是继续显示已挂载的文件系统和文件夹中已有的文件?

答案1

它只会被挂载,并且文件会消失,当文件夹被卸载时才会恢复。

答案2

当您将文件系统挂载到目录 上时/mount-point,您无法再/mount-point直接访问 下的文件。它们仍然存在,但/mount-point现在指向的是挂载文件系统的根目录,而不是用作挂载点的目录,因此无法访问此目录的内容,至少不能以这种方式访问​​。例如:

# touch /mount-point/somefile
# ls /mount-point/somefile
/mount-point/somefile
# mount /dev/something /mount-point
# ls /mount-point/somefile
ls: cannot access /mount-point/somefile: No such file or directory

有多种方法可以获取已安装文件系统和已存在数据的合并视图,但你需要一个称为联合文件系统

在 Linux 下,有一种方法可以查看隐藏文件。您可以使用它mount --bind来获取挂载点所在的文件系统的另一种视图。例如

mount --bind / /other-root-view

您将看到根文件系统下的所有文件/other-root-view

# cat /other-root-view/etc/hostname 
darkstar

特别是,/mount-point现在可以作为 访问/other-root-view/mount-point,并且由于/other-root-view/mount-point不是挂载点,您可以在那里看到其内容:

# ls /mount-point/somefile
ls: cannot access /mount-point/somefile: No such file or directory
# ls /other-root-view/mount-point/somefile
/other-root-view/mount-point/somefile

相关内容