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.

  • 2
    Thanks... Here's a litlle experiment I just tried, which pre-emptively gives me access to the hidden files (I can't see why it would be of any use, but it does work):-- mntDir1 has file1 and mntDir2 is empty -- mount mntDir1 mntDir2 (mntDir2 now shows file1) -- mount /dev/sdc1 mntDir1 (mntDir1 show only sdc1 files.. and mntDir2 still shows file1 which is "normally" accessible) -- Just a point of interest :) – Peter.O Nov 4 '10 at 3:18
  • 2
    Interesting workaround =) but why wouldn't you just mount /dev/sdc1 to mntDir2? – Nick Pascucci Nov 4 '10 at 3:26
  • I guess it might be useful if the files on /dev/sdc1 need to be available at the mntDir1 path for some reason, but you still want access to the original files that were there... (of course, it still sounds more like a temporary workaround than something you want to use long-term). – JanC Nov 4 '10 at 11:57
  • Another workaround: use hard links on the files inside the directory of the mount point – moala Nov 4 '10 at 12:25
  • Thanks for clarity. This is indeed funny and unbelievable that such a bizarre way of making set of file invisible without letting user know, is allowed by such a proven system – Atul Apr 12 '20 at 13:58

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.