Read Linux Mount Namespaces with /proc/self/mountinfo
You will inspect the mounts visible to your current process, identify the filesystem behind a mount point, and recognise mount-propagation markers without modifying the machine. Allow about ten minutes. You need a Linux shell with procfs mounted; the examples use the local proc_pid_mountinfo(5) from the manpages package, version 6.7-2.
The route
Jump straight to the step you need, or tick off Done means at the end.
This is a read-only workflow. None of the commands below needs sudo, and none mounts, unmounts or changes namespace state.
1. Confirm the file and the namespace
/proc/pid/mountinfo describes the mounts in the process's mount namespace. Use self for the shell running the command. Check that the file exists and record the namespace identity:
$ test -r /proc/self/mountinfo && echo "mountinfo is readable"
mountinfo is readable
$ readlink /proc/self/ns/mnt
mnt:[4026531841]
The number is host-specific. It is useful when comparing two processes: different namespace identifiers normally mean that their mount views can differ. A process can also have access restrictions that affect what it can see, so do not treat this file as a complete inventory of every mount on the host.
Checkpoint
If the first command fails, stop here. Check that procfs is mounted and that you are reading the intended environment, such as a container or chroot. Do not work around a permission error by blindly using root.
2. Read a complete record
Print a few records before filtering anything. Long lines are normal:
$ sed -n '1,5p' /proc/self/mountinfo
24 29 0:22 / /sys rw,nosuid,nodev,noexec,relatime shared:7 - sysfs sysfs rw
25 29 0:23 / /proc rw,relatime shared:12 - proc proc rw
26 29 0:5 / /dev rw,nosuid,relatime shared:2 - devtmpfs udev rw,size=16280608k,nr_inodes=4070152,mode=755,inode64
27 26 0:24 / /dev/pts rw,nosuid,noexec,relatime shared:3 - devpts devpts rw,gid=5,mode=620,ptmxmode=000
28 29 0:25 / /run rw,nosuid,nodev,noexec,relatime shared:5 - tmpfs tmpfs rw,size=3264464k,mode=755,inode64
Each line has a stable core separated by a single hyphen. Before that separator are, in order: mount ID, parent mount ID, device major:minor, filesystem root, mount point, per-mount options, and zero or more optional fields. After it come the filesystem type, mount source and per-superblock options.
Do not split a record into exactly eleven whitespace fields. Optional fields vary in number, and mount sources or paths can contain escaped characters. Find the separator first, then interpret the fields on either side.
3. Find a mount by its visible path
The mount point is field 5 in the part before the separator. This read-only filter shows the record for the proc filesystem as seen by the current shell:
$ awk '$5 == "/proc" { print }' /proc/self/mountinfo
25 29 0:23 / /proc rw,relatime shared:12 - proc proc rw
Your IDs and options can differ. The useful confirmation is that the mount point column is /proc and the post-separator filesystem type is proc. The path is relative to the process's root directory, not necessarily the host's root directory.
For a quick count of records, use:
$ wc -l < /proc/self/mountinfo
36
The count is a snapshot. Mounts can appear or disappear while another process changes its namespace, so a monitoring tool should tolerate records changing between reads.
4. Distinguish per-mount and filesystem-wide options
In the example, rw,relatime immediately before the hyphen are per-mount options. The final rw is a superblock option. Do not combine the two lists when diagnosing access behaviour: one mount can have different per-mount options from another view of the same filesystem, while superblock options describe the underlying filesystem instance.
The device number in column 3 is the st_dev value in major:minor form. The mount source is not always a device path. Pseudo-filesystems commonly report names such as proc, sysfs or none.
5. Check mount propagation
Optional fields appear between the per-mount options and the hyphen. The local output includes fields such as shared:12. The documented fields are shared, master, propagate_from and unbindable. Their presence describes propagation relationships; it does not itself change them.
$ awk '$5 == "/proc" { for (i = 7; i <= NF; i++) { if ($i == "-") break; printf "%s%s", $i, (i + 1 < NF ? " " : "\n") } }' /proc/self/mountinfo
shared:12
That loop deliberately stops at the hyphen instead of assuming that the optional fields start or end at a fixed column. A parser should ignore optional field names it does not recognise, because the format can grow.
Safety boundary
Commands such as mount, umount and unshare can change mount state or create a different namespace. They are not needed to inspect mountinfo, so do not add them to a diagnostic script unless you have separately reviewed the privilege and service impact.
6. Handle the common traps
- A missing parent ID record is not automatically corruption. The parent mount can lie outside the process's root directory and therefore be hidden from this file.
- Mount IDs are unique while useful, but the manual warns that an ID may be reused after
umount. Do not use an old ID as a permanent identity. - The root mount can list itself as its parent. That is the documented marker for the top of this mount tree.
- Paths and other fields can contain escaped characters. Preserve the raw record if you need to build a robust parser; do not assume that every visible path is represented as a literal, unescaped shell word.
- A process's mount view is not a promise about another process. Compare
/proc/$PID/ns/mntand/proc/$PID/mountinfofor the process you are actually investigating.
Done means
- You confirmed that
/proc/self/mountinfois readable and recorded the current mount namespace. - You can locate a mount by field 5 and interpret the filesystem fields after the hyphen.
- You can separate per-mount options, optional propagation fields and superblock options.
- Your parser searches for the separator and ignores unknown optional fields.
- You have not changed mounts, namespaces or service state while investigating.