Are pre-existing files in a mountpoint directory safe and uneffected?

I've noticed that pre-existing files in a "mountpoint" directory disappear when the mount command is applied... and then they re-appear when the directory is unmounted.

Are these files just on "holiday" for the duration of the mount period? ... are they safe? ... and is there some way to still access them while the mount is active?


Don't worry about your files, they won't be overwritten while the directory they're in is used as a mount point. Unfortunately, when you mount over that directory they are completely invisible to the system. There's no trivial way you can access them while the directory is being used as a mount point. If you need to use them, you'll have to unmount the filesystem there first.


Files are safe as mentioned in @codeMonks answer.

But there's a safer workaround to access the files. Let's say that you have existing directory /data/media/ with assorted media files (/data and /data/media are on the same filesystem)

Now mounting something like over /data/media will hide files that it contained. (lets assume that you've added usbdrive /dev/sdb1 and mounted it over /data/media)

To access files in /data/media: To be on the safe side, first create empty directory /mnt/mymedia and then use mount --bind (works on directory level)

sudo mount --bind  /data /mnt/mymedia/

Please note that you have to use the upperdir /data if you're mounting after usb drive! But if you used

sudo mount --bind  /data/media /mnt/mymedia/

before mounting said usbdrive you can still access you original files from /mnt/mymedia