[Linux] Filesystem mounts
linux@flux.org
linux@flux.org
Mon, 25 Feb 2008 22:46:16 -0500
On Mon, Feb 25, 2008 at 10:47 AM, kwan@digitalhermit.com
<+flux+simicich+404a9771d3.kwan#digitalhermit.com@spamgourmet.com>
wrote:
> Hello All:
> I've run into this problem before but can't remember the exact Google
> incantation I used to get the answer:
>
> I have a filesystem mounted at /foo/bar. At some point the filesystem
> might have been unmounted. Files that would normally go to the
> /foo/bar filesystem would then end up being written to the ./bar
> directory located on the /foo filesystem.
>
> Question is, without unmount /foo/bar, how can I view the directory
> contents of the mount point /foo/bar.
Behold:
[root@quickdraw njs]# mkdir /tmp/bar1
[root@quickdraw njs]# touch /tmp/bar1/baz1
[root@quickdraw njs]# mkdir /tmp/bar2
[root@quickdraw njs]# touch /tmp/bar2/baz2
[root@quickdraw njs]# ls -l /tmp/bar1
total 0
-rw-r--r-- 1 root root 0 Feb 25 22:13 baz1
[root@quickdraw njs]# mount --bind /tmp/bar2 /tmp/bar1
[root@quickdraw njs]# ls -l /tmp/bar1
total 0
-rw-r--r-- 1 root root 0 Feb 25 22:13 baz2
[root@quickdraw njs]# mkdir /tmp/bar3
[root@quickdraw njs]# mount --bind /tmp /tmp/bar3
[root@quickdraw njs]# ls -l /tmp/bar3/bar2
total 0
-rw-r--r-- 1 root root 0 Feb 25 22:13 baz2
[root@quickdraw njs]# ls -l /tmp/bar3/bar1
total 0
-rw-r--r-- 1 root root 0 Feb 25 22:13 baz1
[root@quickdraw njs]# ls -l /tmp/bar1
total 0
-rw-r--r-- 1 root root 0 Feb 25 22:13 baz2
[root@quickdraw njs]#
Narriative:
We have a directory /tmp/bar1 containing file baz1.
We have a directory /tmp/bar2 containing file baz2.
Using mount, we mount the directory /tmp/bar2 over /tmp/bar1. We see
that the contents of bar1(baz1) is hidden and now bar1 contains baz2.
We want access to baz1 by some name.
We create a new directory and we mount a parent directory of /tmp/bar1
that is still in the same filesystem on this new directory.
Now the contents of that directory (without anything mounted onto it)
is available. There is also a --rbind option for mount, but that
would carry submounts which is not what you want here.
In your case, /foo and /foo/bar (before the mount) are in the same
filesystem, mkdir /tmp/foo and then mount --bind /foo /tmp/foo should
let you see things that might have been hidden by the mount. This
will not affect your application which is running and using the files
in the filesystem mounted on /tmp/foo. Make sure you clean up the
mounts when you are done, and also make sure that nothing cleans up
the /tmp filesystem unexpectedly. Maybe do the mounts into your home
directory or some safe place.
--
A man can't live in the everglades
Where a man can hide and never be found and have no fear of the bayin' hound
But he better keep movin' and don't stand still
If the skeeters don't get him then the gators will