1

Consider i have files in /mnt i am mounting an nfs share to /mnt. After that i can find the nfs share contents in /mnt. But the preexisted files are missing. Is there any way to access both the preexisting and mounted files simultaneously?

Unnikrishnan
  • 1,307
  • 2
  • 12
  • 24

2 Answers2

1

Strictly speaking: No you cannot see Filesystem contents for lower mounted filesystems.

Nevertheless there are some solutions to the problems. The few that spring to mind being:

  • unionfs - takes few FS and presents a merged view of them
  • aufs - same thing as unionfs but more mature

Best practice is NOT to mount multiple filesystems on one mountpoint. If it is required to be accessible under a single tree either make directories inside the mountpoint and mount it there or mount them one under the other e.g. /mnt/nfs/< nfs share files >

zeridon
  • 404
  • 2
  • 4
0

I don't think you can. (see EDIT) The easiest way to do this is to create a subdirectory in /mnt and then mount the nfs share in the subdirectory. If, for example, you have the file1.txt and file2.txt in /mnt and you have file3.txt and file4.txt in the nfs share.

# mkdir /mnt/nfs
# mount <nfs-share> /mnt/nfs

Then

# ls /mnt
file1.txt file2.txt nfs
# ls /mnt/nfs
file3.txt file4.txt

EDIT: This was the closest thing I could find

What does Linux do with existing files in a mount point?

The general idea is to bind mount the parent directory of /mnt (i.e. /) so that the actual contents of /mnt can be accessed.

# mkdir /fakeroot
# mount --bind / /fakeroot
# mount <nfs-share> /mnt

Now:

# ls /mnt
file3.txt file4.txt
# ls /fakeroot/mnt
file1.txt file2.txt

If you want to see both the files in /mnt and the files in the nfs share in /mnt you will probably need a union filesystem.

Moyamo
  • 261
  • 2
  • 8