14

Possible Duplicate:
Access to original contents of mount point

I have a directory d containing some file f and I mount a drive on directory d. Is there a way of accessing file f without unmounting?

howard
  • 1,342
  • 1
  • 11
  • 16

1 Answers1

13

Yes, bind the original fs to a different position, and you can access it:

mount --bind "$(df -P d | awk '/\/dev/ {print $1}')" /tmp/oldroot

And files would be accessible through /tmp/oldroot/XX/f

daisy
  • 54,555
  • 1
    Nice trick! I would have expected the answer: “No, it's shadowed by the other file system unless you unmount it.” – Marco Sep 28 '12 at 09:20
  • 1
    @Marco: The directory in the original mount is shadowed, but bind mounting the device itself somewhere else makes everything on it available elsewhere. – Ignacio Vazquez-Abrams Sep 28 '12 at 15:18
  • 2
    This does not appear to work on redhat/centOS 7. It works on 6.x. In 7 it will just show the mounted dir. – MikeKulls Feb 01 '16 at 00:50