-1

How can mount a partition in an already existent folder of my linux tree? What happens with the already created file and can I move these to the new disk in the process?

I am using a Ubuntu 16.04 with an SSD and HD disk, I would like to mount the ~/Documents or $HOME in the HD moving the files already created and free the SSD to the main files of the operation system (in this moment all the files are in the SSD and the HD is only formatted as Ext4).

Cœur
  • 37,241
  • 25
  • 195
  • 267
hildogjr
  • 754
  • 2
  • 6
  • 17
  • If before o the procedure, I move all the file to the HD and after mount (using the Disks utility in Ubuntu), is the better way? – hildogjr Aug 25 '17 at 13:15

1 Answers1

0

The moment you mount the new parition on top off ~/Documents you cant access the Files anymore, but there are some Options:

Mount the HD somewhere else first and move the files. (code is just an example, it is not supposed to be executable as is)

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

Use a bindmount, to still be able to access the files after mounting:

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

Use a unionfs, and move the files over Time. 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.

Samuel Kirschner
  • 1,135
  • 1
  • 12
  • 18