8

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
7
  • 1
    What error messages are you seeing when you run your mount --bind commands?
    – Warwick
    Commented Jul 25, 2014 at 1:00
  • No error messages. Commented Jul 25, 2014 at 1:07
  • @AdamJensen That is helpful. What is the output of mount | grep /tmp?
    – John1024
    Commented Jul 25, 2014 at 1:41
  • 1
    What do you get if you mount --bind /tmp /tmp/BAR? Commented Jul 25, 2014 at 1:46
  • @Scott Wow, that worked. :) ~ # ls /tmp/BAR/FOO shows abc Commented Jul 25, 2014 at 2:01

2 Answers 2

7

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
10
  • 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. Commented Jul 25, 2014 at 1: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? Commented Jul 25, 2014 at 1:21
  • 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
    Commented Jul 25, 2014 at 2: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
    Commented Jul 25, 2014 at 2: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...) Commented Oct 6, 2015 at 0:18
4

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .