10

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?

4

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).

  • mount gives rootfs on / type rootfs (rw) for initrd and /dev/root on / type ext2 (rw,relatime,block_validity,barrier,user_xattr) for ext2 hard disk with this setup. – Ciro Santilli 新疆改造中心996ICU六四事件 Jan 30 at 15:47
  • /dev/root is used by some implementations of initramfs but not others - in these cases it is not due to the kernel. When not using an initramfs, it seems to be a placeholder value used by the kernel. (Maybe it could be removed in some later kernel version though). stackoverflow.com/questions/37310046/… – sourcejedi Mar 8 at 13:39
3

Gentoo has a patch that does exactly this (ensures the real root device is shown). You can find it here: https://lkml.org/lkml/2013/1/31/574

2

In Linux, /dev/root, if present, is a symlink to the actual device created at boot time.

You either use readlink /dev/root or cat /proc/cmdline to see the root parameter of the booted kernel, and thus find out the real device behind it.

From man dracut(8)

However, to continue with a successful boot, the objective is to locate your root volume and create a symlink /dev/root which points to the file system.

  • I am not entirely sure if /dev/root is an artefact of RedHat based distributions. – Rui F Ribeiro Jul 11 '16 at 6:11
  • Well, my Debian 8 doesn't have /dev/root/. On an old CentOS it seems to be an actual device node instead of a symlink. – ilkkachu Jul 11 '16 at 9:22
  • 1
    Well, OpenEmbedded's base-files recipe's fstab mentions /dev/root, so it isn't just distros originating from Red Hat that are using it. – ack Nov 16 '16 at 14:03

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.