3

Not sure on how to phrase the question easily.

I have a directory /mnt/bla in it MAYBE I have many files and directories.

On top of that directory, I mounted some nfs mount.

Is there a way to check if there are files in the directory underlying the mount without unmounting it?

  • Seems like a duplicate of https://unix.stackexchange.com/questions/4426/access-to-original-contents-of-mount-point – user535733 Apr 25 '20 at 17:54
  • This question is very similar to yours and my answer will work for you, of course, you have to adapt the name of the mountpoint to /mnt/bla in the bind mount command. – mook765 Apr 25 '20 at 17:56
  • @mook765 Please expand your comment to a full answer using the correct directory names from OP's case. I found it slightly confusing to read your original answer while mapping it on OP's problem :-) – Jos Apr 26 '20 at 08:39
  • 1
    @Jos You're right, it's a bit confusing, also another mountpoint than /mnt needs to be used since a filesystem is mounted to a subdirectory of /mnt. Asnwer is ready. – mook765 Apr 26 '20 at 09:22

1 Answers1

6

You can do so using a bind-mount. First you need to create a directory which we use as mount point for the bind-mount:

sudo mkdir /mnt/mymountpoint

(We cannot use /mnt here as suggested in the links in the comments since you have a filesystem mounted on /mnt/bla)

Next step:

sudo mount --bind / /mnt/mymountpoint

Browse to /mnt/mymountpoint/mnt/bla to see what's in the folder. What you see here is the content of /mnt/bla as if nothing were mounted to it.

Move the content of /mnt/mymountpoint/mnt/bla to the location you want or remove the content completely.

Unmount the bind-mount with

sudo umount /mnt/mymountpoint

and remove the mountpoint with

sudo rmdir /mnt/mymountpoint

That's it.

mook765
  • 15,925