Score:0

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

us flag

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.

Score:4
cz flag

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.

Score:1
my flag

"and is there a way to ensure they all physically reside on the new disk I added?"

It is a problem that happens: if, for some reason, the disk is NOT mounted, the data will be written silently to the old disk, inside the directory where it should have been mounted.

Normally I use two different techniques: the first is to create, inside the "real" disk, a special folder (eg rar). Then I check its existence: if there is, then the disk is actually mounted, otherwise not

DIR="/monta/v-server_condivisioni/rar/"
if [ -d "$DIR" ]; then
  echo "Mounted"
else
  echo "NOT mounted"
fi

The second is something like that (Unix, on Linux it is very similar), to check if /monta/vserver_condivisioni is mounted (via smb in this example) or not

df | grep -q /monta/v-server_condivisioni
if [ $? = 0 ]; then
    else
            /bin/date +"%R ----------/monta/v-server_condivisioni NOT mounted!"
            /usr/sbin/mount_smbfs -N -I 10.1.2.3 //theuser@v-server/condivisioni /monta/v-server_condivisioni
fi
R2Bleep2 avatar
us flag
Useful info @Franco Corbelli
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.