1
mkdir /home

then we mount something on /home.

Say /home already contains files.

What happen to the old files after a new drive is mounted to that directory?

user4951
  • 10,519

2 Answers2

6

The mount will hide any existing files in the directory used as a mountpoint. Nothing happens to the files themselves.

If you want to access the hidden files without unmounting /home, you can bind mount the underlying directory at another mountpoint:

$ mount --bind / /mnt

Now /mnt/home/ contains the files hidden by the /home mount.

Thomas Nyman
  • 30,502
  • 1
    So ideally the directory for mounting should be empty? – user4951 Sep 30 '13 at 07:30
  • 1
    Typically the mountpoint is empty prior to the mount, but it doesn't really matter unless you need to access any files that would be hidden by the mount. Keep in mind that the the disk space used by the hidden files is still reported by df (which accesses the used block counts from the file system), but wouldn't show up in du output (as du wouldn't be able to access the files to get their size). – Thomas Nyman Sep 30 '13 at 07:35
1

File stays there. Nothing happens to them. It is just hidden beneath the new layer.

But if you are looking for solution to see both file

a. directory /home content

b. mountpoint /home content

at the same time then you need to study aufs

SHW
  • 14,786
  • 14
  • 66
  • 101