当路径上安装了另一个文件系统时,是否可以删除文件?

刚刚写了关于将/ usr移动到新分区的答案我想知道一旦安装了新分区就删除了文件。 要使用问题中的示例,是否可以在/usr上安装新分区,然后删除根分区上/usr下的所有文件以释放根分区上的空间。

不是直接的 ,但有一种解决方法: mount --bind是你的朋友:

 # Existing directory with a couple files in it root@nkubuntu1004:~/test# ls testdir bar foo # Mount a filesystem over existing directory root@nkubuntu1004:~/test# mount -o loop testfs testdir root@nkubuntu1004:~/test# ls testdir lost+found # Bind mount root filesystem to another directory root@nkubuntu1004:~/test# mount --bind / bindmnt # Can now get to contents of original directory through the bind mount root@nkubuntu1004:~/test# ls bindmnt/root/test/testdir/ bar foo # Remove a file root@nkubuntu1004:~/test# rm bindmnt/root/test/testdir/bar root@nkubuntu1004:~/test# ls bindmnt/root/test/testdir/ foo root@nkubuntu1004:~/test# ls testdir lost+found # Unmount filesystem root@nkubuntu1004:~/test# umount testdir # Observe the change having taken effect root@nkubuntu1004:~/test# ls testdir foo root@nkubuntu1004:~/test# 

另请参阅man mount – 搜索“bind mounts”。