1

I'm fairly new to Ubuntu and Linux in general, and I'm working on a small project in which I'm coming up against something new to me.

I'm adding a second disk to a ubuntu VM, and I want to mount it to /media/recordings I'm pretty sure I've got that process nailed down, but I was wondering what happens to files that are already in the /media/recordings folder.

Out of curiosity, I wrote a text file into the /media/recordings directory before mounting /dev/sdb1 to it. I mounted the disk, and that text file was gone. I wrote a new text file to the disk, and then unmounted and rebooted. I check the /media/recordings directory, and my original text file was there, and not the new one (as expected).

I guess my question is what happens to the original directory when the disk is mounted? I guess I was expecting the two locations to be merged, not "overwritten".

Josh D
  • 13
  • 4
    They're masked (hidden). The partition is mounted over the existing contents, which become inaccessible by normal means. They can be accessed by bind mounting the original directory elsewhere, or by other roundabout methods. – muru Oct 13 '17 at 03:50

2 Answers2

2

They're masked (hidden). The partition is mounted over the existing contents, which become inaccessible by normal means. They can be accessed by bind mounting the original directory elsewhere, or by other roundabout methods.

If you want to merge the contents, you need to use something like (see How do I use OverlayFS?, Example OverlayFS Usage). Otherwise, only the contents of the mount source are visible on the mountpoint.


Example of accessing the original contents using bind mounts:

$ ls foo
2017
$ sudo mount -t tmpfs none foo
$ ls -l foo
total 0
$ mkdir bar
$ sudo mount -o bind . bar
$ ls bar/foo
2017
muru
  • 197,895
  • 55
  • 485
  • 740
1

When you mount a partition to a folder, that folder in effect become a link to the mounted partition.
Because of this, the files that were originally in that folder can not be seen.

Similarly, When a partition is mounted to a folder, any file written to that folder are put on the mounted partition.
When you unmount the partition you can no longer see the files on the partition because the folder now points to the original place.

ravery
  • 6,874