Linux Root Filesystem – Why Does Root Filesystem Appear as /dev/root Instead of /dev/ in mtab?

linuxroot-filesystem

I've seen on various Linux systems where instead of the real device node (for example: /dev/sda1), the root device appears as /dev/root, or instead of the real filesystem, mtab says it is a filesystem called rootfs (which appears as a real filesystem in /proc/filesystems, but doesn't have code in <linux-kernel-source-tree>/fs). Various utilities have been made to use certain attributes to determine the real root device node (such as rdev, and the Chromium OS rootdev). I can find no logical explanation to this other than reading somewhere that very-small embedded devices don't always have to have a /dev device node for their root device. (Is this true, and if so, is that the answer to my question?) Why does mtab sometimes say /dev/root (and I think I might have seen it say rootdev once) instead of the real device node, and how can I make it always say the real device node? The kernel first mounts the root device following the root parameter in the cmdline, then init/systemd re-mounts it according to the fstab, correct? If so, then I presume init maintains mtab. If my theory is correct, how can I make init write the real root device node to mtab? I noticed that /etc/mtab is actually a symbolic link to /proc/mounts, which would mean mtab is maintained by the kernel. So how do I configure/patch a kernel to, instead of saying the root devices node path is /dev/root, have mtab contain the real device node?

Best Answer

This is generally an artifact of using an initramfs.

From the kernel documentation (https://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt)

What is rootfs?

Rootfs is a special instance of ramfs (or tmpfs, if that's enabled), which is always present in 2.6 systems. You can't unmount rootfs for approximately the same reason you can't kill the init process; rather than having special code to check for and handle an empty list, it's smaller and simpler for the kernel to just make sure certain lists can't become empty.

Most systems just mount another filesystem over rootfs and ignore it. The amount of space an empty instance of ramfs takes up is tiny.

Thus rootfs is the root filesystem that was created for the initramfs, and can't be unmounted.

In regards to /dev/root, I'm less certain on this, but if I recall correctly /dev/root is created when using an initrd (not the same as an initramfs).

Related Question