Linux – Accessing a Shadowed Mount Point

linuxmount

A mount point /mnt/sub is shadowed by another mount point /mnt. Is it always possible to access the mounted filesystem?

Root access is a given. The system is a reasonably recent Linux.

Example scenario: accessing the branches of an overlay root

The basic sequence of operations is:

mount device1 /mnt/sub
mount device2 /mnt

After this /mnt/sub is a file on device2 (if it exists). The question is how to access files on device1.

Some devices can be mounted twice, so mount device1 /elsewhere would work. But this doesn't work for all devices, in particular not for FUSE filesystems.

This differs from the already covered case where a subdirectory is shadowed by a mount point, but the mount point of the subdirectory is itself visible, and a bind mount can create an unobscured view. In the example above, mount --bind / /elsewhere lets us see the /mnt/sub directory from the root filesystem on /elsewhere/mnt/sub, but this question is about accessing the filesystem on device1.

Best Answer

# unshare --mount  # this opens a sub-shell
# cd /
# umount /mnt

do what thou wilt

# exit  # close the sub-shell
Related Question