Discussion:
[PATCH] init: fix name of root device in /proc/mounts
William Hubbs
2013-01-31 22:51:39 UTC
Permalink
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.

Signed-off-by: William Hubbs <***@gmail.com>
---
init/do_mounts.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/init/do_mounts.c b/init/do_mounts.c
index 1d1b634..efc37d2 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -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
}
--
1.7.12.4
H. Peter Anvin
2013-01-31 23:22:09 UTC
Permalink
Post by 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
William Hubbs
2013-02-01 17:14:53 UTC
Permalink
Post by H. Peter Anvin
Post by 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...
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
H. Peter Anvin
2013-02-01 19:03:20 UTC
Permalink
Post by William Hubbs
Post by H. Peter Anvin
Post by 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...
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
--
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel. I don't speak on their behalf.
Rob Landley
2013-02-05 02:42:21 UTC
Permalink
Post by William Hubbs
Post by 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
Post by William Hubbs
determine which file systems are mounted since /dev/root is not a
valid
Post by William Hubbs
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
Post by William Hubbs
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--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
H. Peter Anvin
2013-02-05 02:54:32 UTC
Permalink
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.)
Post by Rob Landley
Post by William Hubbs
Post by 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
Post by William Hubbs
determine which file systems are mounted since /dev/root is not a
valid
Post by William Hubbs
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
Post by William Hubbs
the kernel command line.
Let me also point out that most of the time, the kernel actually has
a
Post by William Hubbs
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...)
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
--
Sent from my mobile phone. Please excuse brevity and lack of formatting.
William Hubbs
2013-02-05 04:19:53 UTC
Permalink
Post by 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
Post by H. Peter Anvin
Post by Rob Landley
Post by William Hubbs
Post by 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
Post by William Hubbs
determine which file systems are mounted since /dev/root is not a
valid
Post by William Hubbs
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
Post by William Hubbs
the kernel command line.
Let me also point out that most of the time, the kernel actually has
a
Post by William Hubbs
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...)
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
--
Sent from my mobile phone. Please excuse brevity and lack of formatting.
William Hubbs
2013-03-17 22:23:24 UTC
Permalink
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
William Hubbs
2013-03-19 22:28:22 UTC
Permalink
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
H. Peter Anvin
2013-03-19 23:17:11 UTC
Permalink
Post by 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.
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
--
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel. I don't speak on their behalf.
William Hubbs
2013-03-20 00:20:17 UTC
Permalink
Post by H. Peter Anvin
Post by 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.
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
H. Peter Anvin
2013-03-20 00:24:36 UTC
Permalink
Post by 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
--
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel. I don't speak on their behalf.
Rob Landley
2013-03-20 07:03:20 UTC
Permalink
Post by William Hubbs
Post by H. Peter Anvin
Post by 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,
Post by H. Peter Anvin
Post by William Hubbs
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
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--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
H. Peter Anvin
2013-03-20 15:02:41 UTC
Permalink
Yes, but the current udev maintainer refuses to.
Post by Rob Landley
Post by William Hubbs
Post by H. Peter Anvin
Post by 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
Post by William Hubbs
Post by H. Peter Anvin
Post by William Hubbs
past, udev created a symbolic link from /dev/root to the
appropriate block device, but it does not do this any longer.
Also,
Post by H. Peter Anvin
Post by William Hubbs
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
Post by William Hubbs
Post by H. Peter Anvin
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
(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
--
Sent from my mobile phone. Please excuse brevity and lack of formatting.
William Hubbs
2013-03-20 21:11:25 UTC
Permalink
Post by Rob Landley
Post by William Hubbs
Post by H. Peter Anvin
Post by 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,
Post by H. Peter Anvin
Post by William Hubbs
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
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
(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.: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
Kay Sievers
2013-03-20 21:46:53 UTC
Permalink
Post by William Hubbs
Post by Rob Landley
Post by William Hubbs
Post by H. Peter Anvin
Post by 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,
Post by H. Peter Anvin
Post by William Hubbs
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
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
(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.: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, 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
Rob Landley
2013-03-22 03:00:46 UTC
Permalink
Post by William Hubbs
Post by Rob Landley
Post by William Hubbs
Post by H. Peter Anvin
Post by William Hubbs
The issue is that /dev/root appears in /proc/mounts if you do
not
Post by Rob Landley
Post by William Hubbs
Post by H. Peter Anvin
Post by William Hubbs
boot with an initramfs, but /dev/root is not a device node.
In the
Post by Rob Landley
Post by William Hubbs
Post by H. Peter Anvin
Post by William Hubbs
past, udev created a symbolic link from /dev/root to the
appropriate block device, but it does not do this any longer.
Also,
Post by H. Peter Anvin
Post by William Hubbs
devtmpfs does not create this symbolic link.
This is causing bugs with software that depends on the
existence
Post by Rob Landley
Post by William Hubbs
Post by H. Peter Anvin
Post by William Hubbs
of /dev/root [2] for example.
Seems okay to me, although even better would be to use the udev
name
Post by Rob Landley
Post by William Hubbs
Post by H. Peter Anvin
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
(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
Post by Rob Landley
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
Post by Rob Landley
do it in 2006 (udev started doing so shortly thereafter). Busybox
git
Post by Rob Landley
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?
Post by William Hubbs
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--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

William Hubbs
2013-02-09 21:32:59 UTC
Permalink
Post by 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
Loading...