Schmorp's POD Blog a.k.a. THE RANT
a.k.a. the blog that cannot decide on a name

This document was published 2016-03-16 11:47:21, and since then has not been materially modified.

Tidbits: looking underneath a mount point in GNU/Linux

Here's a tiny thing I learned from b_jonas a while ago, while we discussed mount point detection. It's also a great example of how you can passively know something, yet can't remember it when actively needing it - in this case, I knew about this property of bind mounts, but it took somebody else to tell me to use it in a specific use case.

Anyway, in what is probably so far the shortest and most redundant entry in this blog (I blog about it because this is the kind of content I'd like to see here), a (non-recursive) bind mount let's you look underneath a mountpoint:

mount --bind /some/fs /mnt
ls -l /mnt/mountpoint

The reason this works is quite simple: the bind mount mounts only the filesystem given by the source path (/some/fs), not any filesystems mounted on top of one of it's directories (at /some/fs/mountpoint), so in the destination (/mnt), you can see what's underneath a mount point, as the mount points turn into normal directories again.

Underneath is not exactly the same thing as directly underneath though - the bind mount shows the directory on the bind-mounted filesystem - when there are multiple mounts on the same directory, there is no such easy trick to look into them.