Shamless Shamless - 1 year ago 70
Linux Question

detecting bind mounts on linux

I am looking for a way to determine if a given path is a bind mount point (on linux). The standard techniques for detecting regular mount points don't seem to work. Even the mountpoint command fails to detect bind mounts.

Answer Source

I'm not sure there is supposed to be a way to do that (except perhaps thru /etc/mtab or /etc/fstab) because I understand that bind mounts are sort-of "hard links" in the mount space (not the file hierarchy), and there is no way (once the bind mount happened) to distinguish the source and the target mount points.

And why are asking that? Bind mounts are (IMHO) mostly useful to hide such things from the application's point of view (otherwise you would use symlinks -or even hard links, in the rare cases they are possible- for directories)

And mountpoint which I just discovered thanks to your question seems to see something:

% grep /home /etc/fstab
UUID=000008-0003-000c-9ecd-0f1a /home           ext3    defaults        0       2
% grep /usr/src /etc/fstab
/home/Src /usr/src none bind 0 0
% mountpoint /usr/src
/usr/src is a mountpoint
% mountpoint /home/Src
/home/Src is not a mountpoint

By strace-ing mountpoint I find that it is doing lstat,stat and fstat syscalls on directories like /usr/src & /usr/src/..

(added in november 2016:)

See also /proc/mounts e.g. proc(5)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download