Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to find root partition? Missing /dev/root
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2513
Location: Silver City, NM

PostPosted: Fri Jan 03, 2014 2:40 am    Post subject: How to find root partition? Missing /dev/root Reply with quote

My /dev/root device is missing and without it I don't know of an easy way to figure out which partition is mounted at /.

I've looked through this thread Missing /dev/root I followed all of the suggestions and none of them worked.

I do have a big clue though. The /dev/root device went AWOL right after I started using PARTUUID in a boot parameter to tell the kernel where the root partition is:
Code:
root=PARTUUID=xxxxx
I did this following the instructions in the kernel (3.7.10) source in the root= entry in Documentation/kernel-parameters.txt which led me to the comment above name_to_dev_t in init/do_mounts.c. I'm using gpt instead of mbr in order to get a PARTUUID.

According to the thread I linked to above I can get the major and minor numbers of the root device with this udev arcanery:
Code:
 udevadm info --export --export-prefix=ROOT_ --device-id-of-file=/
ROOT_MAJOR=8
ROOT_MINOR=19

According to instructions here: Major and Minor Numbers the /dev/ device can be found by:
Code:
device    = [MINOR / 16] = 2
partition = MINOR mod 16 = 3
That works in this case. The root device is sdb3.

IMO this can be a rather vital piece of information. It seems insane that I would have to go through these back flips in order to get it; having to "readlink -f /dev/root" was bad enough. Is there an easier way? If not, why did they make this vital piece of information so obscure? IMO, the device should be in the output of the df command instead of the two useless / entries that are now given.
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 8291
Location: Saint Amant, Acadiana

PostPosted: Fri Jan 03, 2014 3:19 am    Post subject: Reply with quote

I can't say I understand your problem, but generally mount command output should tell you what is mounted and where.
_________________
My Gentoo installation notes.
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2513
Location: Silver City, NM

PostPosted: Fri Jan 03, 2014 3:45 am    Post subject: Reply with quote

Code:
$ mount  | grep " / "
/dev/root on / type ext4 (rw,relatime,discard,data=ordered)
$ ls /dev/root
ls: cannot access /dev/root: No such file or directory

This is the problem. Usually /dev/root is a symlink to a device like /dev/sdb3. I used to be able to use "readlink -f /dev/root" to find what the actual device was. Now that /dev/root is AWOL, the only way I know of is the rather arcane trick outlined in my first post using udevadm and juggling the minor (and perhaps major?) device number(s).
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 8291
Location: Saint Amant, Acadiana

PostPosted: Fri Jan 03, 2014 4:06 am    Post subject: Reply with quote

Not sure what is going on there, but methinks putting your .config into pastebin and posting your fdisk -l output (your fdisk is new enough to do GPT, right?) and cat /etc/fstab output will help us to help you.
_________________
My Gentoo installation notes.
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
Dr.Willy
Guru
Guru


Joined: 15 Jul 2007
Posts: 547
Location: NRW, Germany

PostPosted: Fri Jan 03, 2014 12:15 pm    Post subject: Reply with quote

Code:
grep root /etc/conf.d/udev

and
https://bugs.gentoo.org/show_bug.cgi?id=438380
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2513
Location: Silver City, NM

PostPosted: Fri Jan 03, 2014 9:13 pm    Post subject: Reply with quote

Thanks Dr. Willy. These two ideas were already mentioned in the thread I referred to in my first post. Since my problem was slightly different, I decided to start a new thread instead of revive that old thread. Perhaps that was a mistake.

Note /dev/root is *only* missing when I use "root=PARTUUID=xxxx" as a boot parameter instead of "root=/dev/sdb3" which means a simple misconfiguration in /etc/conf.d/udev is unlikely to be the cause. Although, as I already said, I had already checked that.

The bug report repeats information from that thread as well. It says /dev/root is deprecated and relying on it to find the underlying root device is now a bug that needs fixing. That's fine. My question is, without /dev/root then how the HECK am I supposed to find what the underlying root device is?

Are we all supposed to roll our own script like this one?
Code:
#!/usr/bin/perl

use strict;

my $cmd = "udevadm info --export --export-prefix=ROOT_ --device-id-of-file=/";

for ( `$cmd` ) {
    m/ROOT_MINOR=(\d+)/ or next;
    my $minor = $1;
    my $part = $minor % 16;
    my $drive = ($minor - $part) / 16;
    my $let = chr( ord('a') + $drive);
    print "/dev/sd$let$part\n";
    last;
}

ISTM there should be a much easier way to find the root device. I don't understand why this has become so difficult. It reminds me of working on Windows machines in decades past. Am I the only one who thinks this is insane? I'm still hoping there is a simple solution that I don't yet know about.

Ideally, the root device would show up in the output of the "mount" or "df" commands like it did for many many years. Next best would be the /dev/root symlink. Since both "mount" (and cat /proc/mounts, etc) and "df" are broken in this respect and since the /dev/root is symlink is deprecated, how are we supposed to find the root device?
Back to top
View user's profile Send private message
SlashBeast
Retired Dev
Retired Dev


Joined: 23 May 2006
Posts: 2922

PostPosted: Fri Jan 03, 2014 10:39 pm    Post subject: Reply with quote

Its not that simple when you deal with device mapper (cat /proc/devices) and others. If you can crawl /sys then i would do:

Code:
#!/bin/sh
what=$1
major_minor=$(mountpoint -d ${what})
readlink -f /dev/$(sed -r '/DEVNAME/!d; s%DEVNAME=(.*)%\1%' /sys/dev/block/${major_minor}/uevent)


Or you can add additional checks for /dev/dm-X and such. But it also can be /dev/mapper/XXX-YYY, depends on your /dev manager configuration, the /dev/dm-1 may be either symlink or device node.

Personally, I use root=UUID= covered by better-initramfs so my /proc/mounts have device address instead of /dev/root.

minor:major you can also get from /proc/1/mountinfo
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2513
Location: Silver City, NM

PostPosted: Fri Jan 03, 2014 11:05 pm    Post subject: Reply with quote

Thanks SlashBeast! That is certainly simpler than the Perl script I posted.

Do you have any idea why we are forced to jump through these hoops in order to find the root filesystem device? Why is such a vital piece of information made so obscure? It almost feels like we aren't all playing on the same team.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54450
Location: 56N 3W

PostPosted: Fri Jan 03, 2014 11:18 pm    Post subject: Reply with quote

BitJam,

Code:
$ df
Filesystem                1K-blocks      Used Available Use% Mounted on
/dev/dm-0                   1998672    665120   1212312  36% /
am I missing something here?
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2513
Location: Silver City, NM

PostPosted: Fri Jan 03, 2014 11:53 pm    Post subject: Reply with quote

NeddySeagoon, for quite a while (years, probably) I've gotten this output from df:
Code:
$ df
Filesystem      1K-blocks      Used  Available Use% Mounted on
rootfs           30963708  11366772   18024072  39% /
/dev/root        30963708  11366772   18024072  39% /
[etc.]

I used to be able to get the physical root partition from "readlink -f /dev/root" but with /dev/root gone (in some cases but certainly deprecated) I was asking how else can I find the physical root device. I'm not using device mapper nor am I setting the root device in an initramfs. Do I need to do this now?

My question is: if I'm using the root=PARTUUID=xxx boot parameter to have the kernel set the root device directly then is there as easy way to discover what the /dev/sd* root device is?

If I'm doing something wrong, I'd be happy to learn how to do it right.
Back to top
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54450
Location: 56N 3W

PostPosted: Sat Jan 04, 2014 12:01 am    Post subject: Reply with quote

BitJam,

I was missing something ... I always use LVM these days, so I have not come across this.
Code:
$ /sbin/blkid
/dev/sdb1: UUID="9392926d-6408-6e7a-8663-82834138a597" TYPE="linux_raid_member" PARTUUID="0553caf4-01"


You can get the root PARTUUID from your boot loader config and grep it in the output of blkid.
_________________
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2513
Location: Silver City, NM

PostPosted: Sat Jan 04, 2014 1:06 am    Post subject: Reply with quote

Thanks Neddy, the shortest version is:
Code:
 blkid -t PARTUUID="xxxxx" -o device
But this is not entirely satisfactory because it it is tied to a particular PARTUUID. I would really like a general purpose solution.

I suppose I could grab the PARTUUID from /proc/cmdline:
Code:
partuuid=$(sed -r 's/.*root=PARTUUID=([^\s]+) .*/\1/' /proc/cmdline)
blkid -t PARTUUID="$partuuid" -o device

Even using /proc/cmdline I still prefer SlashBeast's solution (or even my Perl script) because it makes fewer assumptions about how the system was booted. Imagine, for example, making a variant of the df program which replaces "/dev/root" with the actual device. How would this program discover the root device? We don't want to assume a specific PARTUUID nor even assume that a PARTUUID was given as a boot parameter.

It seems we are all left to fend for ourselves and each kludge together a script that will give the actual root device. While df is extremely useful in a number of ways, I've always felt that providing the physical root device was the most important feature. IMO telling me /dev/root is mounted at / provides zero useful information. Likewise telling me rootfs is mounted at / is nearly information-free. OTOH, telling me the actual device is both informative and useful.

Am I just being old fashioned wanting to use names like sdb3 instead of names like 6f8db673-09f4-464d-a2dc-db85b633bbca? Maybe there is a new "stable" device naming scheme coming down the pipe that will be similar to the "stable" network device naming scheme.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum