2

What is the meaning of the root column in /proc/pid/mountinfo file?

As per the manual, it says

 (4)  root: the pathname of the directory in the filesystem which forms the root of this mount.

It is not very clear from the documentation. Can someone please explain this? May be with an example?

codego123
  • 143
  • 2

1 Answers1

2

Instead of always mounting the root of a filesystem (e.g. mount /dev/sda3 /mnt would normally attach "/" of the sda3 filesystem onto /mnt), Linux allows mounting only a sub-path (subdirectory or even a file).

While there is no direct way of doing so1 for a fresh mount, the most common use is bind mounts. For example, if you have something mounted on /mnt/a, doing mount --bind /mnt/a/foo /mnt/b would duplicate the mount and would set /foo as the root for the /mnt/b mount.

If the original device on /mnt/a was e.g. /dev/sda3, then the "root" column would show / for the original /mnt/a mount but /foo for the /mnt/b mount, and findmnt show /dev/sda3[/foo] as being mounted on /mnt/b.

(Note that bind mounts are not limited to directories – while /mnt/a/foo is a directory in this example, it can also be a file, in which case it can be mounted on top of another file.)

# mkdir /mnt/a
# mount /dev/sda3 /mnt/a

mkdir /mnt/a/foo

touch /mnt/a/foo/bar

mkdir /mnt/b

mount --bind /mnt/a/foo /mnt/b

findmnt

umount /mnt/a

ls -la /mnt/b

(The two resulting mounts are equals – /mnt/b is not a "child" of the /mnt/a mount in any way, and you can unmount /mnt/a without affecting /mnt/b.)

Some filesystems such as Btrfs have custom mount options that work in a similar way; for example, Btrfs has subvol= – which only works for paths that indeed represent the root of a Btrfs subvolume, but at VFS level it looks the same. Mounting a Btrfs filesystem with subvol=home would cause /home to be shown as the "root" of this mount.


1 Although util-linux 'mount' has X-mount.subdir=, but it achieves this by mounting the root as usual, then doing a bind mount of the desired subdirectory, then unmounting the root.

grawity
  • 501,077