0

From the proc manual it names the 4th column of mountinfo as "root", and describes it as "the pathname of the directory in the filesystem which forms the root of this mount". But how to understand it?

I thought the basic elements of a mount is the source and the target path, since the "mount source" is the 10th column and target at 5th column, then what does the root used for?

For most mount info, the root is just /, seem to be meaningless. I only find the bind mounts have a root different from /, so it's only useful in bind mounts? And in bind case, why not show the absolute path in root? For example, when bind the /run/test_dir/a to /run/test_dir/b, the root column shows /test_dir/a, why hiding the /run part?

3
  • Is your run directory a partition? – WGRM Mar 9 '20 at 14:05
  • yes, it's a tempfs mount – Tintervenor Mar 10 '20 at 2:36
  • Then you got your reason... – WGRM Mar 10 '20 at 6:30
0

It is hard to explain it with language elements (at least with my english skills) - so I decided to make an example based answer:

The root directory is often called the highest or uppest directory. This is only partially true. This directory is assumed as the highest directory. You could describe it with "from this directory I will start - I assume this is the highest directory and there is nothing above".

Some examples to clarify what "root" means:

  • Imagine you run a web server and set the root of a domain example.com to /var/www/html/example.com. Now you create a file /var/www/html/example.com/test.html. If you open https://example.com/test.html in your browser. you get the content of the created file. If you set /var/www/html as root, you must open https://example.com/example.com/test.html
  • If you chroot into the directory /home/test/testSystem/. The root of this environment would be /home/test/testSystem. If you do an ls inside the chrooted environment ls / you would get the content of /home/test/testSystem/

Mountpoint with root /

For example an USB contains:

/
├── dir1
│   ├── subfile1
│   └── subfile2
├── file1
├── file2
└── file3

If you mount this USB to /mnt you would get the normal output you expect because you use the / directory of the USB as root:

531 137 0:52 / /mnt rw,nosuid,nodev shared:75 - /dev/sdb [...]

So in the most cases, the root of mount points would be indeed /.

Mountpoint with different root than /

You can try this by yourself: Bind two directorys in you filesystem together with

$ mount --bind /var/test1 /var/test2

The output of mountinfo would be something like:

564 29 0:26 /var/test1 /var/test2 rw,relatime shared:1 - ext4 /dev/sda rw [...]

The root of mountpoint located under /var/test2 is /var/test1. The mount source (what you have mounted) is /dev/sda

Back to the USB example: If you now mount the content of /mnt/dir1 to something other, you would get the mount root /dir1 and the mount source would be /dev/sdb (the USB). The /mnt part is dropped here.

"Why hiding the /run part"

In short: /run is dropped because it is a tmpfs partition. Why are those parts removed?

In the USB example we mounted dir1 of /dev/sdb to /home/test/usbmnt/. The output would be:

564 29 0:26 /dir1 /home/test/usbmnt/ rw,relatime shared:1 - ext4 /dev/sdb rw [...]

You see we mounted the content of /dir1 (from the USB and NOT from your hard drive) to a directory called usbmnt. Maybe it is helpful to read it as /dev/sdb/dir1.

If the root would be given as /mnt/usb/dir1 we couldn't know what is the real location on the USB: It could be /dir1, /usb/dir1 or maybe /mnt/usb/dir1

2
  • Yoir example didn't drop "/var", so how did it tackle his problem? – WGRM Mar 9 '20 at 14:06
  • @WGRM oh your right. Didn't read the last passus of the question carefully. I will edit my answer. It isn't dropped because /var isn't a partition. You see this in the USB example – Maze Mar 9 '20 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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