Linux: Mounting a partition on a new physical drive to a directory - where does the data reside (physically)?

If I have a machine with a single physical disk and I partition and add a new disk to a directory (e.g. /usr/data) long after the OS has been installed and running, where do those files exist physically, and is there a way to ensure they all physically reside on the new disk I added?

Similarly, I have a utility that automatically backs up a my virtual drive in a virtual machine and I'd like to be sure that if I back up a vhd that I added, partitioned and mounted to a particular directory after the OS has been running for a while, that I'm backing up everything under that directory.


Solution 1:

If you mount a block device to a directory, then files you create under that directory are created on that block device. Full stop.

Note that if the directory contained files before you mounted a device to it, those files remain on the parent block device and are hidden and inaccessible while the device is mounted.

Similarly, if you write to that directory while your new block device is not mounted, such files end up on the parent block device.

All this suggests you should do a couple of things:

  1. If files exist in that directory and you want them to be accessible after mounting your new device, you should just rename the whole directory, create a new directory with the original name, mount your device, and then move the old files to the new device.

  2. You should ensure that your device is mounted at startup, e.g. by adding it to /etc/fstab.