Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 175243 - /proc/mounts references /dev/root for / but /dev/root does not exist
Summary: /proc/mounts references /dev/root for / but /dev/root does not exist
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: High normal (vote)
Assignee: udev maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-19 16:27 UTC by Doug Goldstein (RETIRED)
Modified: 2007-11-19 20:42 UTC (History)
7 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
blockdev_is_root.c (blockdev_is_root.c,1.02 KB, text/plain)
2007-04-19 17:28 UTC, Matthias Schwarzott
Details
use root= rather then hardcoding to /dev/root (dev-root-real-root.patch,883 bytes, patch)
2007-04-21 17:29 UTC, Doug Goldstein (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Doug Goldstein (RETIRED) gentoo-dev 2007-04-19 16:27:33 UTC
Basically if you look at /proc/mounts on a system booted with or without our initramfs, you will see that in /proc/mounts that the kernel says /dev/root is mounted as the / device. However there is no /dev/root device.

Straight from the mount(8) man page...

When the proc filesystem is mounted (say at /proc), the files /etc/mtab
       and /proc/mounts have very similar contents. The  former  has  somewhat
       more  information, such as the mount options used, but is not necessar-
       ily up-to-date (cf. the -n option below). It  is  possible  to  replace
       /etc/mtab  by  a symbolic link to /proc/mounts, and especially when you
       have very large numbers of mounts things will be much faster with  that
       symlink, but some information is lost that way, and in particular work-
       ing with the loop device will be less convenient, and using the  "user"
       option will fail.
Comment 1 Matthias Schwarzott gentoo-dev 2007-04-19 16:57:12 UTC
my suggestions are:

A: In hal init-script (or before: like end of udev-start): read major/minor of dir "/" and mknod /dev/root if it does not exist

B: let code search inside /dev for the device with that major/minor and link to it.

getting major/minor cannot use program stat (at least not in udev) as stat is in /usr.
We need a small helper call syscall stat and extract the info from there.

C: Adding a udev rule similar to this:
SUBSYSTEM=="block", PROGRAM=="check_if_i_am_root", SYMLINK="root"
and that program (check_if_i_am_root) compares major/minor of the device to that of "/" directory.

something like:

major=getenv("MAJOR");
minor=getenv("MINOR");
dev_t dev=stat("/");
if (major/minor == dev)
  return EXIT_SUCCESS;
else
  return EXIT_FAILURE;



D: Patching hal to do this:
if (device=="/dev/root") {
 device=lookup_real_name;
}

Comment 2 Daniel Drake (RETIRED) gentoo-dev 2007-04-19 17:11:32 UTC
I feel that hal shouldn't be relying on the devices listed in /proc/mounts existing. As /proc/mounts is kernel-space but filesystem contents are controlled in userspace (and operations are not really filtered by the kernel), there's no way consistency can be guaranteed.

Some examples for when these devices nodes might not exist:

 1. When the kernel mounts the root filesystem during boot. There is no userspace here and no /dev. The kernel has to choose a name for the node, or not list it at all. There is no guarantee that userspace will create the same name later.

 2. When a mounted usb flash drive is unplugged, the device goes away but the mount does not.

 3. The user could remove a mounted node, or /dev might be replaced by another layout entirely (this happens during initramfs pivot, for example).

 4. Many things in /proc/mounts don't correspond to device nodes anyway, e.g. sysfs

The kernel documentation does not comment on the accuracy of the device nodes listed in /proc/mounts. Neither does the mount documentation. FWIW, I also think a kernel documentation patch would be accepted to add some comments pointing out the obvious that device nodes referred to in /proc/mounts may not actually exist in userspace (because what userspace does in this sense is not kernel business). Maybe this would change your views on the solution here.

IMO hal should do something different. Even though creating /dev/root would workaround the majority of problems, I don't feel that it is a solution, and given our crazy user-base you'll probably get that one guy who files an obscure bug later for a different device node.
Comment 3 Matthias Schwarzott gentoo-dev 2007-04-19 17:28:54 UTC
Created attachment 116745 [details]
blockdev_is_root.c

calling the attached program from that udev-rule will create /dev/root:
SUBSYSTEM=="block", PROGRAM=="blockdev_is_root", SYMLINK+="root"
Comment 4 Chris Gianelloni (RETIRED) gentoo-dev 2007-04-19 18:28:52 UTC
I'm just curious why genkernel is on here.  We don't use udev (anymore) at all in our initramfs stuff, as we've replaced it with mdev from busybox to reduce size and complexity.  Of course, I might just be missing something important.  ;]
Comment 5 Doug Goldstein (RETIRED) gentoo-dev 2007-04-19 21:01:51 UTC
Because the initramfs needs to create the proper node as well.. whatever that's getting populated as. SuSE and RedHat's initramfs is doing the right thing and mounting the device for the kernel so it's a non-issue. But I don't know if your initramfs does this...
Comment 6 Paul Bredbury 2007-04-20 02:51:27 UTC
Arch Linux creates /dev/root by calling root-link.sh in /etc/udev/rules.d/udev.rules

$ grep root /etc/udev/rules.d/*
/etc/udev/rules.d/udev.rules:# fix /dev/root symlink
/etc/udev/rules.d/udev.rules:SUBSYSTEM=="block", RUN+="/lib/udev/root-link.sh"

The script and udev patches are at:
http://cvs.archlinux.org/cgi-bin/viewcvs.cgi/base/udev/?cvsroot=Current&only_with_tag=CURRENT
Comment 7 Christophe Saout 2007-04-20 22:02:31 UTC
My system doesn't show /dev/root in /proc/mount (because in my case it's mounted by initramfs, not the kernel itself), so the warning is bogus on my machine.
Comment 8 Charles G Waldman 2007-04-20 22:17:39 UTC
    An even better way to get the root device, rather than getting it from
    /proc/cmdline (which may not work, since if you use LILO the root device gets
    turned into a number), is to do 

    mount -fv / | cut -d' ' -f1

    or equivalently,

    mount -fv / | awk { print $1 ; }

Comment 9 Matthias Schwarzott gentoo-dev 2007-04-21 06:24:28 UTC
Discussion on hotplug-ML about that topic/suggested udev patch can be found 
here:
http://thread.gmane.org/gmane.linux.hotplug.devel/11277
Comment 10 Kfir Ozer 2007-04-21 11:13:41 UTC
thanks for your comments.

i added this to /etc/conf.d/local.start
ROOT_DEVICE=`mount -fv / | cut -d' ' -f1`
ln -s ${ROOT_DEVICE} /dev/root

do i need to create the device before hal is started, or is this a good method ?
Comment 11 Doug Goldstein (RETIRED) gentoo-dev 2007-04-21 17:28:30 UTC
I personally feel this is a kernel bug. Since we're instructing the kernel via root= what dev device it should use. It should respect that, after all it does for initramfs so why not for root=.

Attached is a patch to do such with the kernel.
Comment 12 Doug Goldstein (RETIRED) gentoo-dev 2007-04-21 17:29:36 UTC
Created attachment 116919 [details, diff]
use root= rather then hardcoding to /dev/root

The other advantage of this is that we don't have to search and compare every block device. It's also not a userspace hack to fix a kernel space bug.
Comment 13 Michael Croes 2007-04-27 19:37:16 UTC
I was just wondering... What's the exact goal of this /dev/root thing? Because if I'm using an initrd, my kernel command line option will be root=/dev/ram0, if I'm not, it will be /dev/sda6. I don't see the use for a /dev/root that is based on the way I boot, but I guess I'm missing something...

For me the warning is bogus too right now, there's no /dev/root in my /proc/mounts, the only references are:
rootfs / rootfs rw 0 0
/dev/sda6 / reiserfs rw,noatime 0 0

Please enlighten me...
Comment 14 Doug Goldstein (RETIRED) gentoo-dev 2007-04-27 20:40:43 UTC
Michael,

When you use an initramfs (initrd), the kernel does the right thing. As you can see there, your device for / is /dev/sda6.

This bug is for when there is no initramfs.
Comment 15 Andrew Gaffney (RETIRED) gentoo-dev 2007-11-17 02:59:32 UTC
Since this bug is for behavior that occurs when there is *not* an initramfs, I'm removing genkernel.
Comment 16 Matthias Schwarzott gentoo-dev 2007-11-19 20:42:30 UTC
This is fixed. udev handles it fine now so /dev/root will exist.