How to view files hidden by a mount on Debian 6

I have been trying for a while to view files, hidden by a mount on my device sporting Debian 6, to no avail, and being new to Linux, I am compelled to ask the question: How do you view files hidden by a mount on Debian 6?

I have gone over the many duplicates I came across as I was drafting this question the first 1 or 10 times and the following answers did not help in my case:

  1. Answer to “Access to original contents of mount point”
  2. Answer to “Where do the files go if you mount a drive to a folder that already contains files?”
  3. Answer to “What happened to the old files if we mount a drive to the directory? [duplicate]”

I also found this, but it was a little intimidating to try that with my limited knowledge of what I am even doing.

I also asked Linux users around me, who all (both) say that it’s impossible to see my files without umounting.

So just to make things clear, this is what I am working with:

/tmp # mkdir FOO
/tmp # cd FOO/
/tmp/FOO # touch abc
/tmp/FOO # cd
~ # mount /dev/sda1 /tmp/FOO/
~ # ls /tmp/FOO/
bbb
~ # cd /tmp/
/tmp # mkdir BAR
/tmp # cd
~ # mount --bind / /tmp/BAR
~ # cd /tmp/BAR/
/tmp/BAR # ls
bin      etc      lib      media    proc     sbin     sys      usr
dev      home     linuxrc  mnt      root     selinux  tmp      var
/tmp/BAR # cd tmp/
/tmp/BAR/tmp # ls
/tmp/BAR/tmp #

@John1024:

~ # mount | grep /tmp/
/dev/sda1 on /tmp/FOO type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=cp932,iocharset=cp932,errors=remount-ro)
/dev/root on /tmp/BAR type jffs2 (ro,relatime)

What and to where should I mount --bind to see the files that were in /tmp/somefolder? Could the functionality of the solutions linked above be related to what build of Debian I am using?

Edit: For clarification, these are some of the commands I tried:

~ # mount --bind /tmp/somefolder /tmp/anotherfolder
~ # mount --bind / /tmp/anotherfolder
~ # mount --bind /dev/sda1 /tmp/anotherfolder
Asked By: Adam Jensen

||

As I understand it, you want to see the files, if any, hidden by the mount /dev/sda1 /tmp/somefolder command. Assuming that /tmp is part of the / filesystem, run:

mount --bind / /tmp/anotherfolder
ls /tmp/anotherfolder/tmp/somefolder

If /tmp is not part of / but is a separate filesystem, run:

mount --bind /tmp /tmp/anotherfolder
ls /tmp/anotherfolder/somefolder
Answered By: John1024

Since /tmp is a separate filesystem,
you want to get an unblemished view of the contents of that filesystem
(without the interference from the /dev/sda1 filesystem,
which is mounted on the subordinate /tmp/FOO mount point),
so you need to do a bind mount on /tmp:

mount --bind /tmp /tmp/BAR

Now /tmp/BAR should show you the contents of /tmp,
and /tmp/BAR/FOO should show you the contents of /tmp/FOO,
which had been hidden by the mount on /tmp/FOO.

Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.