7

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
Adam Jensen
  • 277
  • 2
  • 8

2 Answers2

5

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
John1024
  • 73,527
  • 11
  • 167
  • 163
  • When I try this, `/tmp/anotherfolder/tmp/somefolder` contains the files of the mounted FS (the usbdisk). I still can't see what has been hidden by mounting. – Adam Jensen Jul 25 '14 at 01:12
  • I tried this from a couple of locations with visibility of the usbdisk contents varying. From where are you ideally supposed to run these commands? – Adam Jensen Jul 25 '14 at 01:21
  • @AdamJensen It shouldn't do that. Would you document in your question _precisely_ what commands you run that result in the directory still being hidden? Leave nothing to the imagination. – John1024 Jul 25 '14 at 01:25
  • Ok, here goes nothing. – Adam Jensen Jul 25 '14 at 01:29
  • How do I know whether `/tmp` is a separate filesystem from `/`? Because that seemed to work for me. – Adam Jensen Jul 25 '14 at 02:05
  • 2
    @AdamJensen running `mount` will show you which filesystems are mounted, and their mountpoints. if `/tmp` is separate to `/` you'll seen an entry for `/tmp` – Lawrence Jul 25 '14 at 02:33
  • 1
    @AdamJensen The clue for me was when you ran `ls` in `/tmp/BAR/tmp`. If `/tmp` was part of `/` then both FOO and BAR should have been visible. Neither was. – John1024 Jul 25 '14 at 02:42
  • 1
    Top notch! Just used this to access my old disk-borne `/tmp`, which has been superseded by a `tmpfs`, and clear down the defunct old contents. I used `/mnt` since it's meant to be specifically for manual, temporary mounts (after checking _it_ was clear, of course...) – underscore_d Oct 06 '15 at 00:18
3

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.