在已存在的文件夹中装载分区 (linux)

Mount a partition (linux) in a already existent folder

如何在我的 linux 树的一个已经存在的文件夹中安装一个分区?已经创建的文件会发生什么情况,我可以在此过程中将它们移动到新磁盘吗?

我正在使用带有 SSD 和 HD 磁盘的 Ubuntu 16.04,我想在 HD 中安装 ~/Documents 或 $HOME 移动已经创建的文件并将 SSD 释放到主文件操作系统(此时所有文件都在SSD中,HD仅格式化为Ext4)。

将新分区挂载到顶层后 ~/Documents 您将无法再访问文件,但有一些选项:

先把硬盘挂载到别处,再移动文件。 (代码只是一个例子,它不应该是可执行的)

mount /dev/disks/by-lable/foo /media/temporary
mv /home/hildogjr/Documents/* /media/temporary
umount /media/temporary
mount /dev/disks/by-lable/foo /home/hildogjr/Documents

使用 bindmount,挂载后仍然可以访问文件:

mount --bind /home/hildogjr/Documents /media/Documents_on_ssd
mount /dev/disks/by-lable/foo /home/hildogjr/Documents
mv /media/Douments_on_ssd/* /home/hildogjr/Documents
umount /media/Documents_on_ssd

使用unionfs,随时间移动文件。 man unionfs:

It first tries to access the file on the top branch and if the file does not exist there, it continues on lower level branches. If the user tries to modify a file on a lower level read-only branch the file is copied to to a higher level read-write branch if the copy-on-write (cow) mode was enabled.