Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

mount has an option --make-shared as described here. However, how do I find out if a particular mount point has been made shared?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Linux exposes information about mounted filesystems in /proc/mounts. The sharing options are too recent to show up in that file, but they do show up in /proc/self/mountinfo¹. The documentation for this file is in filesystems/proc.txt in the kernel documentation. The file is generated by show_mountinfo in fs/namespace.c. A sample line looks like this:

42 18 98:0 / /mount_point rw shared:1 - ext3 /dev/sda1 rw,errors=continue
                             ^^^^^^^^

The format of the first 6 fields is fixed. Then come zero or more tagged fields, such as shared:GROUP, master:GROUP, propagate_from:GROUP or unbindable, indicating the mount's role in a peer group if any. The - introduces the filesystem-specific part, always composed of the filesystem type name, device name and filesystem-specific mount options.

Thus:

</proc/self/mountinfo awk -vmount_point='/mount/point' '
$5 == mount_point {
    i = 7;
    while ($i != "-") {if ($i ~ /^shared:/) exit 0; ++i}
    exit 1;
}'

¹ On recent enough Linux kernels, each process has its own filesystem namespace and /proc/mounts is a symbolic link to /proc/self/mounts.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.