Is it possible to access files "shadowed" by a mount?

Solution 1:

You can use the mount command to access the underlying filesystem.

$ mkdir /mnt/root
$ sudo mount --bind / /mnt/root
$ cat /mnt/root/foo/bar

There is no issue with corruption with doing this, but it does require permission to mount the file system.

Solution 2:

If you have root, you can mount --move the mounted filesystem on top of a temporary directory, then move it back afterwards.

mkdir /bar
mount --move /foo /bar

Having root also allows accessing the underlying block devices, if any, directly. For ext4, you can use debugfs to export files.

Read-only access can never corrupt the filesystem.


Directories can have handles, or file descriptors, obtained for them. The "current directory" is a handle too, not a path. If you have a handle to a directory, you can access files inside even if that location has been mounted over. This does not need special privileges, only special preparation.