What does Linux do with existing files in a mount point?
Solution 1:
It will just be mounted, and the files disappear, coming back when the folder is umounted.
Solution 2:
When you mount a filesystem on a directory /mount-point
, you can no longer access files under /mount-point
directly. They still exist, but /mount-point
now refers to the root of the mounted filesystem, not to the directory that served as a mount point, so the contents of this directory cannot be accessed, at least in this way. For example:
# touch /mount-point/somefile
# ls /mount-point/somefile
/mount-point/somefile
# mount /dev/something /mount-point
# ls /mount-point/somefile
ls: cannot access /mount-point/somefile: No such file or directory
There are ways to get a merged view of the mounted filesystem and the data that was already present, but you need an extra layer called a union filesystem.
Under Linux, there is a way to see the hidden files. You can use mount --bind
to get another view of the filesystem where the mount point is. For example
mount --bind / /other-root-view
You'll see all the files in the root filesystem under /other-root-view
.
# cat /other-root-view/etc/hostname
darkstar
In particular, /mount-point
will now be accessible as /other-root-view/mount-point
, and since /other-root-view/mount-point
is not a mount point, you can see its contents there:
# ls /mount-point/somefile
ls: cannot access /mount-point/somefile: No such file or directory
# ls /other-root-view/mount-point/somefile
/other-root-view/mount-point/somefile