Skip to contentSkip to conversation

init: fix name of root device in /proc/mounts

PATCH In review William Hubbs 5 participants 18 messages Jan 31, 2013 – Mar 22, 2013 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 init: fix name of root device in /proc/mounts

On a system that does not use an initramfs, /dev/root was always listed in /proc/mounts. This breaks software which scans /proc/mounts to determine which file systems are mounted since /dev/root is not a valid device name.

This changes that processing so that "/dev/root" is only added to /proc/mounts if a root device is not specified with the root= option on the kernel command line.

---
 init/do_mounts.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
init/do_mounts.c +11 -3
index 1d1b634..efc37d2 100644
@@ -480,7 +480,10 @@ void __init change_floppy(char *fmt, ...)
 	va_start(args, fmt);
 	vsprintf(buf, fmt, args);
 	va_end(args);
-	fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
+	if (saved_root_name[0])
+		fd = sys_open(saved_root_name, O_RDWR | O_NDELAY, 0);
+	else
+		fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
 	if (fd >= 0) {
 		sys_ioctl(fd, FDEJECT, 0);
 		sys_close(fd);
@@ -523,8 +526,13 @@ void __init mount_root(void)
 	}
 #endif
 #ifdef CONFIG_BLOCK
-	create_dev("/dev/root", ROOT_DEV);
-	mount_block_root("/dev/root", root_mountflags);
+	if (saved_root_name[0]) {
+		create_dev(saved_root_name, ROOT_DEV);
+		mount_block_root(saved_root_name, root_mountflags);
+	} else {
+		create_dev("/dev/root", ROOT_DEV);
+		mount_block_root("/dev/root", root_mountflags);
+	}
 #endif
 }
 
Signature · 1 line
1.7.12.4
#1 lore raw
Quoted 10 lines · William Hubbs

On a system that does not use an initramfs, /dev/root was always listed in /proc/mounts. This breaks software which scans /proc/mounts to determine which file systems are mounted since /dev/root is not a valid device name.

This changes that processing so that "/dev/root" is only added to /proc/mounts if a root device is not specified with the root= option on the kernel command line.

Let me also point out that most of the time, the kernel actually has a udev device name for an actual device...

-hpa

#2 lore raw
Quoted 6 lines · H. Peter Anvin
Quoted 5 lines · William Hubbs

On a system that does not use an initramfs, /dev/root was always listed in /proc/mounts. This breaks software which scans /proc/mounts to determine which file systems are mounted since /dev/root is not a valid device name.

Quoted 8 lines
Quoted 5 lines

This changes that processing so that "/dev/root" is only added to /proc/mounts if a root device is not specified with the root= option on the kernel command line.

Let me also point out that most of the time, the kernel actually has a udev device name for an actual device...

I'm not sure what you mean. If you mean /dev/root is not an actual device and should not be listed in /proc/mounts, that is correct and that is why I am proposing this patch.

William

#3 lore raw
Quoted 11 lines · William Hubbs
Quoted 10 lines · H. Peter Anvin
Quoted 9 lines · William Hubbs

On a system that does not use an initramfs, /dev/root was always listed in /proc/mounts. This breaks software which scans /proc/mounts to determine which file systems are mounted since /dev/root is not a valid device name.

This changes that processing so that "/dev/root" is only added to /proc/mounts if a root device is not specified with the root= option on the kernel command line.

Quoted 9 lines
Quoted 4 lines
Quoted 1 line

Let me also point out that most of the time, the kernel actually has a udev device name for an actual device...

I'm not sure what you mean. If you mean /dev/root is not an actual device and should not be listed in /proc/mounts, that is correct and that is why I am proposing this patch.

What I meant is that even if you *don't* specify a root= device the modern kernel will generally have a usable name.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#4 lore raw
In reply to H. Peter Anvin
Quoted 10 lines · H. Peter Anvin
Quoted 2 lines · William Hubbs

On a system that does not use an initramfs, /dev/root was always listed in /proc/mounts. This breaks software which scans

/proc/mounts to

Quoted 1 line

determine which file systems are mounted since /dev/root is not a

valid

Quoted 4 lines

device name.

This changes that processing so that "/dev/root" is only added to /proc/mounts if a root device is not specified with the root=

Quoted 7 lines

option on

Quoted 3 lines

the kernel command line.

Let me also point out that most of the time, the kernel actually has a udev device name for an actual device...

So your software is broken by overmounts? /dev/root is just one example of this. (And you can specify a root= on the kernel command line and have that be parsed by initramfs. I vaguely recall klibc does this...)

For an example of how to parse this stuff, how about:

http://landley.net/hg/toybox/file/4ffb735aea59/toys/posix/df.c

I.E. parse from the end of the list (most recent match is the overmount), and eliminate synthetic filesystems. Note that code is from 2006, other people have managed to cope all this time...

Rob

#5 lore raw

The difference is that it used to be customary to have a /dev/root symlink; iirc udev created one. Devtmpfs does not (for largely valid reasons, but it does break some userspaces.)

Quoted 35 lines · Rob Landley
Quoted 8 lines · H. Peter Anvin
Quoted 2 lines · William Hubbs

On a system that does not use an initramfs, /dev/root was always listed in /proc/mounts. This breaks software which scans

/proc/mounts to

Quoted 1 line

determine which file systems are mounted since /dev/root is not a

valid

Quoted 2 lines

device name.

Quoted 8 lines
Quoted 2 lines

This changes that processing so that "/dev/root" is only added to /proc/mounts if a root device is not specified with the root=

option on

Quoted 3 lines

the kernel command line.

Let me also point out that most of the time, the kernel actually has

a

Quoted 1 line

udev device name for an actual device...

So your software is broken by overmounts? /dev/root is just one example

of this. (And you can specify a root= on the kernel command line and have that be parsed by initramfs. I vaguely recall klibc does this...)

For an example of how to parse this stuff, how about:

http://landley.net/hg/toybox/file/4ffb735aea59/toys/posix/df.c

I.E. parse from the end of the list (most recent match is the overmount), and eliminate synthetic filesystems. Note that code is from

2006, other people have managed to cope all this time...

Rob

Signature · 1 line
Sent from my mobile phone. Please excuse brevity and lack of formatting.
#6 lore raw
Quoted 1 line · H. Peter Anvin

The difference is that it used to be customary to have a /dev/root symlink; iirc udev created one. Devtmpfs does not (for largely valid reasons, but it does break some userspaces.)

Correct. The /dev/root symlink is not created any longer. If you boot with an initramfs this path does not show up in /proc/mounts. If you boot without one, however, it does.

This patch just makes the /dev/root path not show up at all in /proc/mounts, regardless of whether an initramfs is used.

Thanks,

William

Quoted 40 lines
Quoted 35 lines · Rob Landley
Quoted 8 lines · H. Peter Anvin
Quoted 2 lines · William Hubbs

On a system that does not use an initramfs, /dev/root was always listed in /proc/mounts. This breaks software which scans

/proc/mounts to

Quoted 1 line

determine which file systems are mounted since /dev/root is not a

valid

Quoted 2 lines

device name.

Quoted 8 lines
Quoted 2 lines

This changes that processing so that "/dev/root" is only added to /proc/mounts if a root device is not specified with the root=

option on

Quoted 3 lines

the kernel command line.

Let me also point out that most of the time, the kernel actually has

a

Quoted 1 line

udev device name for an actual device...

So your software is broken by overmounts? /dev/root is just one example

of this. (And you can specify a root= on the kernel command line and have that be parsed by initramfs. I vaguely recall klibc does this...)

For an example of how to parse this stuff, how about:

http://landley.net/hg/toybox/file/4ffb735aea59/toys/posix/df.c

I.E. parse from the end of the list (most recent match is the overmount), and eliminate synthetic filesystems. Note that code is from

2006, other people have managed to cope all this time...

Rob

Signature · 1 line
Sent from my mobile phone. Please excuse brevity and lack of formatting.
#7 lore raw
In reply to H. Peter Anvin

All,

I haven't heard any more on this patch, so I wanted to ping the thread again and find out the status.

The original message is linked below[1].

The issue is that /dev/root appears in /proc/mounts if you do not boot with an initramfs, but /dev/root is not a device node. In the past, udev created a symbolic link from /dev/root to the appropriate block device, but it does not do this any longer. Also, devtmpfs does not create this symbolic link.

This is causing bugs with software that depends on the existence of /dev/root [2] for example.

Do you need any more information on this patch, or is there some reason it can't go in?

Thanks much,

William

[1] https://lkml.org/lkml/2013/1/31/574
[2] https://bugs.gentoo.org/show_bug.cgi?id=438028

#8 lore raw
In reply to H. Peter Anvin

All,

I haven't heard any more on this patch, so I wanted to ping the thread again and find out the status.

The original message is linked below[1].

The issue is that /dev/root appears in /proc/mounts if you do not boot with an initramfs, but /dev/root is not a device node. In the past, udev created a symbolic link from /dev/root to the appropriate block device, but it does not do this any longer. Also, devtmpfs does not create this symbolic link.

This is causing bugs with software that depends on the existence of /dev/root [2] for example.

Do you need any more information on this patch, or is there some reason it can't go in?

Thanks much,

William

[1] https://lkml.org/lkml/2013/1/31/574
[2] https://bugs.gentoo.org/show_bug.cgi?id=438028

#9 lore raw
Quoted 13 lines · William Hubbs

All,

I haven't heard any more on this patch, so I wanted to ping the thread again and find out the status.

The original message is linked below[1].

The issue is that /dev/root appears in /proc/mounts if you do not boot with an initramfs, but /dev/root is not a device node. In the past, udev created a symbolic link from /dev/root to the appropriate block device, but it does not do this any longer. Also, devtmpfs does not create this symbolic link.

Quoted 6 lines

This is causing bugs with software that depends on the existence of /dev/root [2] for example.

Do you need any more information on this patch, or is there some reason it can't go in?

Seems okay to me, although even better would be to use the udev name of the device in question.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#10 lore raw
Quoted 7 lines · H. Peter Anvin
Quoted 6 lines · William Hubbs

The issue is that /dev/root appears in /proc/mounts if you do not boot with an initramfs, but /dev/root is not a device node. In the past, udev created a symbolic link from /dev/root to the appropriate block device, but it does not do this any longer. Also, devtmpfs does not create this symbolic link.

Quoted 5 lines
Quoted 2 lines

This is causing bugs with software that depends on the existence of /dev/root [2] for example.

Seems okay to me, although even better would be to use the udev name of the device in question.

I'm not following what you mean.

The problem is that "/dev/root" should not be in /proc/mounts, since there is always another entry that points to the root file system.

William

#11 lore raw
Quoted 7 lines · William Hubbs

I'm not following what you mean.

The problem is that "/dev/root" should not be in /proc/mounts, since there is always another entry that points to the root file system.

You are getting the name from the root= command line option.

The other option is to take the name from the mounted device number, and look up the udev name (which is known by the kernel). That way it works even if the user specifies a numeric device, or the default device is used.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#12 lore raw
In reply to William Hubbs
Quoted 12 lines · William Hubbs
Quoted 5 lines · H. Peter Anvin
Quoted 4 lines · William Hubbs

The issue is that /dev/root appears in /proc/mounts if you do not boot with an initramfs, but /dev/root is not a device node. In the past, udev created a symbolic link from /dev/root to the appropriate block device, but it does not do this any longer.

Also,

Quoted 5 lines
Quoted 4 lines

devtmpfs does not create this symbolic link.

This is causing bugs with software that depends on the existence of /dev/root [2] for example.

Quoted 8 lines
Quoted 2 lines

Seems okay to me, although even better would be to use the udev name of the device in question.

I'm not following what you mean.

The problem is that "/dev/root" should not be in /proc/mounts, since there is always another entry that points to the root file system.

What gave you that idea?

wget http://landley.net/aboriginal/bin/system-image-i686.tar.bz2
extract it and ./run-emulator.sh and in there:

(i686:1) /home # cat /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / squashfs ro,relatime 0 0
proc /proc proc rw,relatime 0 0
sys /sys sysfs rw,relatime 0 0
dev /dev devtmpfs rw,relatime,size=63072k,nr_inodes=15768,mode=755 0 0 dev/pts /dev/pts devpts rw,relatime,mode=600 0 0
/tmp /tmp tmpfs rw,relatime 0 0
/home /home tmpfs rw,relatime 0 0

Userspace can totally determine what /dev/root points to, I made mdev do it in 2006 (udev started doing so shortly thereafter). Busybox git commit a7e3d052.

Heck, the userspace "stat /" command says "Device: 801h" and /dev/sda1 is 08:01 on my netbook.

Rob

#13 lore raw

Yes, but the current udev maintainer refuses to.

Quoted 48 lines · Rob Landley
Quoted 4 lines · William Hubbs
Quoted 3 lines · H. Peter Anvin
Quoted 2 lines · William Hubbs

The issue is that /dev/root appears in /proc/mounts if you do not boot with an initramfs, but /dev/root is not a device node. In

the

Quoted 9 lines
Quoted 2 lines
Quoted 2 lines

past, udev created a symbolic link from /dev/root to the appropriate block device, but it does not do this any longer.

Also,

Quoted 6 lines
Quoted 4 lines

devtmpfs does not create this symbolic link.

This is causing bugs with software that depends on the existence of /dev/root [2] for example.

Seems okay to me, although even better would be to use the udev

name

Quoted 7 lines
Quoted 1 line

of the device in question.

I'm not following what you mean.

The problem is that "/dev/root" should not be in /proc/mounts, since there is always another entry that points to the root file system.

What gave you that idea?

wget http://landley.net/aboriginal/bin/system-image-i686.tar.bz2
extract it and ./run-emulator.sh and in there:

(i686:1) /home # cat /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / squashfs ro,relatime 0 0
proc /proc proc rw,relatime 0 0
sys /sys sysfs rw,relatime 0 0
dev /dev devtmpfs rw,relatime,size=63072k,nr_inodes=15768,mode=755 0 0 dev/pts /dev/pts devpts rw,relatime,mode=600 0 0
/tmp /tmp tmpfs rw,relatime 0 0
/home /home tmpfs rw,relatime 0 0

Userspace can totally determine what /dev/root points to, I made mdev do it in 2006 (udev started doing so shortly thereafter). Busybox git commit a7e3d052.

Heck, the userspace "stat /" command says "Device: 801h" and /dev/sda1

is 08:01 on my netbook.

Rob

Signature · 1 line
Sent from my mobile phone. Please excuse brevity and lack of formatting.
#14 lore raw
In reply to Rob Landley
Quoted 37 lines · Rob Landley
Quoted 12 lines · William Hubbs
Quoted 5 lines · H. Peter Anvin
Quoted 4 lines · William Hubbs

The issue is that /dev/root appears in /proc/mounts if you do not boot with an initramfs, but /dev/root is not a device node. In the past, udev created a symbolic link from /dev/root to the appropriate block device, but it does not do this any longer.

Also,

Quoted 5 lines
Quoted 4 lines

devtmpfs does not create this symbolic link.

This is causing bugs with software that depends on the existence of /dev/root [2] for example.

Quoted 8 lines
Quoted 2 lines

Seems okay to me, although even better would be to use the udev name of the device in question.

I'm not following what you mean.

The problem is that "/dev/root" should not be in /proc/mounts, since there is always another entry that points to the root file system.

What gave you that idea?

wget http://landley.net/aboriginal/bin/system-image-i686.tar.bz2
extract it and ./run-emulator.sh and in there:

(i686:1) /home # cat /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / squashfs ro,relatime 0 0
proc /proc proc rw,relatime 0 0
sys /sys sysfs rw,relatime 0 0
dev /dev devtmpfs rw,relatime,size=63072k,nr_inodes=15768,mode=755 0 0 dev/pts /dev/pts devpts rw,relatime,mode=600 0 0
/tmp /tmp tmpfs rw,relatime 0 0
/home /home tmpfs rw,relatime 0 0

Quoted 3 lines

Userspace can totally determine what /dev/root points to, I made mdev do it in 2006 (udev started doing so shortly thereafter). Busybox git commit a7e3d052.:4

There are situations where it doesn't work though -- suppose that root is btrfs for example.

Also, the other message that answered you is correct, the udev maintainers say we should not be relying on /dev/root at all so to make it work distro packagers have to add a rule themselves.

Kay,

if you are reading, canyou jump in and explain why /dev/root is a bad idea?

Thanks,

William

#15 lore raw
Quoted 45 lines · William Hubbs
Quoted 37 lines · Rob Landley
Quoted 12 lines · William Hubbs
Quoted 5 lines · H. Peter Anvin
Quoted 4 lines · William Hubbs

The issue is that /dev/root appears in /proc/mounts if you do not boot with an initramfs, but /dev/root is not a device node. In the past, udev created a symbolic link from /dev/root to the appropriate block device, but it does not do this any longer.

Also,

Quoted 5 lines
Quoted 4 lines

devtmpfs does not create this symbolic link.

This is causing bugs with software that depends on the existence of /dev/root [2] for example.

Quoted 8 lines
Quoted 2 lines

Seems okay to me, although even better would be to use the udev name of the device in question.

I'm not following what you mean.

The problem is that "/dev/root" should not be in /proc/mounts, since there is always another entry that points to the root file system.

What gave you that idea?

wget http://landley.net/aboriginal/bin/system-image-i686.tar.bz2
extract it and ./run-emulator.sh and in there:

(i686:1) /home # cat /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / squashfs ro,relatime 0 0
proc /proc proc rw,relatime 0 0
sys /sys sysfs rw,relatime 0 0
dev /dev devtmpfs rw,relatime,size=63072k,nr_inodes=15768,mode=755 0 0 dev/pts /dev/pts devpts rw,relatime,mode=600 0 0
/tmp /tmp tmpfs rw,relatime 0 0
/home /home tmpfs rw,relatime 0 0

Quoted 3 lines

Userspace can totally determine what /dev/root points to, I made mdev do it in 2006 (udev started doing so shortly thereafter). Busybox git commit a7e3d052.:4

There are situations where it doesn't work though -- suppose that root is btrfs for example.

Quoted 8 lines

Also, the other message that answered you is correct, the udev maintainers say we should not be relying on /dev/root at all so to make it work distro packagers have to add a rule themselves.

Kay,

if you are reading, can you jump in and explain why /dev/root is a bad idea?

stat("/") is just the better approach for tools to find out what "root" is, there is not much point in doing symlinks here just because the kernel uses that name to mount internally.

/dev/root was never part of the default udev setup, it happened in the distros init scripts, and only some distributions added that.

Newer filesystems like btrfs do not have an 1:1 fs:device relation anyway, there cannot be a /dev/root symlink anymore, so tools need to catch up here anyway, and the sooner the better. /dev/root is a concept that will probably no longer exist in the future, because filesystems will work differently than they used to.

As Peter said, the kernel should internally just use the name of the kernel block device instead of inventing and exporting the name of an artificial /dev/root node, which does not exist later in the real system.

Kay

#16 lore raw
In reply to William Hubbs
Quoted 43 lines · William Hubbs
Quoted 4 lines · Rob Landley
Quoted 3 lines · William Hubbs
Quoted 2 lines · H. Peter Anvin
Quoted 1 line · William Hubbs

The issue is that /dev/root appears in /proc/mounts if you do

not

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

boot with an initramfs, but /dev/root is not a device node.

In the

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

past, udev created a symbolic link from /dev/root to the appropriate block device, but it does not do this any longer.

Also,

Quoted 3 lines
Quoted 3 lines

devtmpfs does not create this symbolic link.

This is causing bugs with software that depends on the

existence

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

of /dev/root [2] for example.

Seems okay to me, although even better would be to use the udev

name

Quoted 13 lines
Quoted 7 lines
Quoted 1 line

of the device in question.

I'm not following what you mean.

The problem is that "/dev/root" should not be in /proc/mounts, since there is always another entry that points to the root file system.

What gave you that idea?

wget http://landley.net/aboriginal/bin/system-image-i686.tar.bz2
extract it and ./run-emulator.sh and in there:

Quoted 6 lines

(i686:1) /home # cat /proc/mounts
rootfs / rootfs rw 0 0
/dev/root / squashfs ro,relatime 0 0
proc /proc proc rw,relatime 0 0
sys /sys sysfs rw,relatime 0 0
dev /dev devtmpfs rw,relatime,size=63072k,nr_inodes=15768,mode=755

0 0

Quoted 4 lines

dev/pts /dev/pts devpts rw,relatime,mode=600 0 0 /tmp /tmp tmpfs rw,relatime 0 0
/home /home tmpfs rw,relatime 0 0

Quoted 8 lines
Quoted 1 line

Userspace can totally determine what /dev/root points to, I made

mdev

Quoted 1 line

do it in 2006 (udev started doing so shortly thereafter). Busybox

git

Quoted 1 line

commit a7e3d052.:4

There are situations where it doesn't work though -- suppose that root is btrfs for example.

So you're saying there's a bug in btrfs?

Quoted 3 lines

Also, the other message that answered you is correct, the udev maintainers say we should not be relying on /dev/root at all so to make it work distro packagers have to add a rule themselves.

These udev maintainers?

http://lkml.indiana.edu/hypermail/linux/kernel/1210.0/01889.html

This is the udev that got Katamari'd into systemd, not one of the forks that ran screaming trying not to get sucked into the latest escapade of King of All Cosmos?

Look, if you want to add /dev/root to devtmpfs, that makes a certain amount of sense. But your patch seems to have missed do_mounts.c doing:

  if (strncmp(root_device_name, "/dev/", 5) == 0)
    root_device_name += 5;

Which means that if the user does "root=sda1" on the kernel command line you're not passing an absolute path to create_dev():

- create_dev("/dev/root", ROOT_DEV);
- mount_block_root("/dev/root", root_mountflags);
+ if (saved_root_name[0]) {
+ create_dev(saved_root_name, ROOT_DEV);

And last I checked that means /proc/mounts will have a relative path in it...

I.E. you're modifying kernel code you're not familiar with to fix a non-problem caused by your unfamiliarity with the corresponding userspace code. I'm really not seeing the upside here.

Rob

#17 lore raw
In reply to William Hubbs
Quoted 8 lines · William Hubbs

On a system that does not use an initramfs, /dev/root was always listed in /proc/mounts. This breaks software which scans /proc/mounts to determine which file systems are mounted since /dev/root is not a valid device name.

This changes that processing so that "/dev/root" is only added to /proc/mounts if a root device is not specified with the root= option on the kernel command line.

I want to follow up on this patch since I haven't heard anything for a while.

Again, the basic problem I am trying to address is that /dev/root is not a valid device (there isn't a device node for it in devtmpfs and udev doesn't create a symlink for it), so it should not appear in /proc/mounts, but currently it does if you boot a system without an initramfs.

Are there any more questions or concerns about this patch? If not, what is the status for getting it, or another fix for this issue, committed?

Thanks much,

William