Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Why does 'df' print my root filesystem as '/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
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Mon Oct 26, 2020 1:02 pm    Post subject: Why does 'df' print my root filesystem as '/dev/root'? Reply with quote

df on my Gentoo machine shows the root filesystem as '/dev/root':
Code:
# df
Filesystem    1K-blocks      Used Available Use% Mounted on
/dev/root      82045336  22397696  55436952  29% /

df on a Debian machine shows the root filesystem with its partition name ('/dev/sda6'):
Code:
# df
Filesystem    1K-blocks      Used Available Use% Mounted on
/dev/sda6      38464044   3254560  33225896   9% /

Why does my Gentoo machine print '/dev/root'? What can I do to make my Gentoo machine show the partition name instead of '/dev/root'?
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3345
Location: Rasi, Finland

PostPosted: Mon Oct 26, 2020 2:43 pm    Post subject: Reply with quote

Does lsblk show the same?
What does
Code:
file /dev/root
tell?
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Mon Oct 26, 2020 3:01 pm    Post subject: Reply with quote

Code:
# file /dev/root
/dev/root: cannot open '/dev/root' (No such file or directory)

Code:
# lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0  74.5G  0 disk
├─sda1        8:1    0   200M  0 part /boot
├─sda2        8:2    0  60.9G  0 part
└─sda4        8:4    0  13.5G  0 part
nvme0n1     259:0    0 465.8G  0 disk
├─nvme0n1p1 259:1    0   200M  0 part
├─nvme0n1p2 259:2    0    80G  0 part /
└─nvme0n1p3 259:3    0 385.6G  0 part

Code:
# cat /proc/self/mountinfo      # that's what 'df' reads
...
20 1 259:2 / / rw,noatime shared:1 - ext4 /dev/root rw
...

Code:
# cat /proc/mounts
...
/dev/root / ext4 rw,noatime 0 0
...
Back to top
View user's profile Send private message
Etal
Veteran
Veteran


Joined: 15 Jul 2005
Posts: 1931

PostPosted: Mon Oct 26, 2020 3:12 pm    Post subject: Reply with quote

Could it be depending on whether if it was mounted by the kernel or by userspace (in initrd)?
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3345
Location: Rasi, Finland

PostPosted: Mon Oct 26, 2020 7:09 pm    Post subject: Reply with quote

I suspect (rather a wild guess) it's mounted in initrd from /dev/root, but after e?udev starts the dev nodes change and /dev/root goes missing/renamed but the earlier dev node name is already written into several places (mountinfo).
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Ionen
Developer
Developer


Joined: 06 Dec 2018
Posts: 2719

PostPosted: Mon Oct 26, 2020 7:54 pm    Post subject: Reply with quote

/dev/root is a device the kernel uses to do the mount specified by root=... by itself (e.g. without relying on an initramfs). If you had an initramfs that did the mount with commonly-named devices, then you'd get the normal device, I assume debian does something like that.

You can see it in the kernel source, like in init/do_mounts.c inside mount_root()
Code:
#ifdef CONFIG_BLOCK
        {
                int err = create_dev("/dev/root", ROOT_DEV);

                if (err < 0)
                        pr_emerg("Failed to create /dev/root: %d\n", err);
                mount_block_root("/dev/root", root_mountflags);
        }
#endif
Later gone as it gets replaced by the real /dev, (e)udev, and all that stuff.

I don't have an initramfs/initrd at all (Edit: my kernel is even built without support) and I get /dev/root shown in df output.


Last edited by Ionen on Mon Oct 26, 2020 8:02 pm; edited 3 times in total
Back to top
View user's profile Send private message
Tony0945
Watchman
Watchman


Joined: 25 Jul 2006
Posts: 5127
Location: Illinois, USA

PostPosted: Mon Oct 26, 2020 8:00 pm    Post subject: Reply with quote

It used to show the actual device but a bout a year ago showed the useless /dev/root. Wow, root is mount on /dev/root, whoda thunk it?

EDIT:
Seems to be failure to follow the symlink:
Code:
tony@Casti ~ $ ls -l /dev/root
lrwxrwxrwx 1 root root 4 Oct 25 17:12 /dev/root -> sdb3
Back to top
View user's profile Send private message
Ionen
Developer
Developer


Joined: 06 Dec 2018
Posts: 2719

PostPosted: Mon Oct 26, 2020 8:06 pm    Post subject: Reply with quote

Tony0945 wrote:
EDIT:
Seems to be failure to follow the symlink:
Code:
tony@Casti ~ $ ls -l /dev/root
lrwxrwxrwx 1 root root 4 Oct 25 17:12 /dev/root -> sdb3

In my case the file doesn't even exist (devtmpfs+eudev+openrc+no initramfs)
Code:
$ ls -l /dev/root
ls: cannot access '/dev/root': No such file or directory
But df still shows /dev/root, not that "personally" consider this a problem. I know what /dev/root means and I'm not using that output to find the root device. I could create the symlink with a simple udev rule if I wanted too.
Back to top
View user's profile Send private message
Tony0945
Watchman
Watchman


Joined: 25 Jul 2006
Posts: 5127
Location: Illinois, USA

PostPosted: Mon Oct 26, 2020 8:34 pm    Post subject: Reply with quote

Ionen wrote:
In my case the file doesn't even exist (devtmpfs+eudev+openrc+no initramfs)

Sounds like my system except I am using an old out of tree version of openrc. Someday I will analyze the later changes in OpenRC and see if they were bugfixes, enhancements, or just tinkering. I'm discounting for the moment claims that they were deliberate breakage to advance systemd, because of lack of evidence of intent.

Also an old eudev. Does this section of /lib/udev/rules.d/60-persistent-storage.rules do anything?
Code:

# add symlink to GPT root disk
ENV{ID_PART_ENTRY_SCHEME}=="gpt", ENV{ID_PART_GPT_AUTO_ROOT}=="1", SYMLINK+="gpt-auto-root"
Back to top
View user's profile Send private message
Tony0945
Watchman
Watchman


Joined: 25 Jul 2006
Posts: 5127
Location: Illinois, USA

PostPosted: Mon Oct 26, 2020 8:38 pm    Post subject: Reply with quote

Snippet from /etc/init.d/udev
Code:
# This is here because some software expects /dev/root to exist.
# For more information, see this bug:
# https://bugs.gentoo.org/show_bug.cgi?id=438380
dev_root_link()
{
        local RULESDIR=/run/udev/rules.d
        [ -d $RULESDIR ] || mkdir -p $RULESDIR
          eval $(udevadm info --export --export-prefix=ROOT_ --device-id-of-file=/ ||
                true)
        [ "$ROOT_MAJOR" -a "$ROOT_MINOR" ] || return 0

        # btrfs filesystems have bogus major/minor numbers
        [ "$ROOT_MAJOR" != 0 ] || return 0

        echo 'ACTION=="add|change", SUBSYSTEM=="block", ENV{MAJOR}=="'$ROOT_MAJOR'", ENV{MINOR}=="'$ROOT_MINOR'", SYMLINK+="root"' > $RULESDIR/61-dev-root->
}


Clear as mud.

EDIT: additional data
Code:
tony@Casti ~ $ equery b  /etc/init.d/udev
 * Searching for /etc/init.d/udev ...
sys-fs/udev-init-scripts-27-r1 (/etc/init.d/udev)

tony@Casti ~ $ eix udev-init-scripts
[I] sys-fs/udev-init-scripts
     Available versions:  27^t[1] 27-r1^t{tbz2}[1] [m]33^t [m]34^t [m]**9999*l^t
     Installed versions:  27-r1^t{tbz2}[1](02:08:16 PM 01/27/2019)
     Homepage:            https://wiki.gentoo.org/wiki/No_homepage
     Description:         udev startup scripts for openrc

[1] "oldgentoo" /var/lib/layman/oldgentoo

Back to top
View user's profile Send private message
Ionen
Developer
Developer


Joined: 06 Dec 2018
Posts: 2719

PostPosted: Mon Oct 26, 2020 8:47 pm    Post subject: Reply with quote

The gpt-auto-root thing was removed 3 years ago, dev_root_link() was moved out of init.d/udev to init.d/udev-trigger 6 years ago.

Edit:
For me seems the script runs, creates the udev rule, but is never triggered to actually make the symlink (maybe due to how I got other things setup). This process can also be disabled by a config option but is enabled by default. Missing /dev/root never caused me problems so I guess doesn't matter on my system anyway.
Code:
$ cat /run/udev/rules.d/61-dev-root-link.rules
ACTION=="add|change", SUBSYSTEM=="block", ENV{MAJOR}=="259", ENV{MINOR}=="2", SYMLINK+="root"

Edit2:
Code:
# We can create a /dev/root symbolic link to point to the root device in
# some situations. This is on by default because some software relies on
# it,. However, this software should be fixed to not do this.
# For more information, see
# https://bugs.gentoo.org/show_bug.cgi?id=438380.
# If you are not using any affected software, you do not need this, so
# feel free to turn it off.
#rc_dev_root_symlink="YES"
So I guess not having it is more "proper", might as well just change this to "no" (not that this have anything to do with what df will display, see earlier post instead)

Last edited by Ionen on Mon Oct 26, 2020 9:11 pm; edited 3 times in total
Back to top
View user's profile Send private message
Tony0945
Watchman
Watchman


Joined: 25 Jul 2006
Posts: 5127
Location: Illinois, USA

PostPosted: Mon Oct 26, 2020 9:05 pm    Post subject: Reply with quote

Yes, I run an old eudev as well as an old OpenRC.
Back to top
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Mon Oct 26, 2020 10:54 pm    Post subject: Reply with quote

@Zucca, @Etal, @Ionen, @Tony0945: thanks for your answers!

Ionen wrote:
You can see it in the kernel source, like in init/do_mounts.c inside mount_root()
Code:
#ifdef CONFIG_BLOCK
    {
        int err = create_dev("/dev/root", ROOT_DEV);

        if (err < 0)
            pr_emerg("Failed to create /dev/root: %d\n", err);
        mount_block_root("/dev/root", root_mountflags);
    }
#endif

Later gone as it gets replaced by the real /dev, (e)udev, and all that stuff.

You're right. I modified that code block ( s%/dev/root%/dev/rant% ) and recompiled the kernel. Amazingly enough, my kernel still boots. And now I get:
Code:
# df
Filesystem    1K-blocks      Used Available Use% Mounted on
/dev/rant      82045336  22391140  55443508  29% /

And it's true: my Gentoo machine boots without initrd and my Debian machine boots with initrd.

What happens during initrd that changes '/dev/root' to the device name? Can I do it without initrd?
Back to top
View user's profile Send private message
Ionen
Developer
Developer


Joined: 06 Dec 2018
Posts: 2719

PostPosted: Mon Oct 26, 2020 11:29 pm    Post subject: Reply with quote

Well, a initramfs is technically your rootfs until it mounts the real one and switch (the primary reason it exists if need modules/lvm/cryptstuff/etc.. to mount it), it can have a normal /dev, mount program, etc... If it runs a mount command with normal devices, then the kernel's /dev/rant doesn't mean anything.

Without that the kernel has to mount your real rootfs before /dev even exists, so guess it just makes something up :) I guess it could be handled more elegantly given it still knows "expected" device names but well.

Not that I've messed with initramfs much myself, I've never really needed them for how I do things.
Back to top
View user's profile Send private message
Tony0945
Watchman
Watchman


Joined: 25 Jul 2006
Posts: 5127
Location: Illinois, USA

PostPosted: Mon Oct 26, 2020 11:59 pm    Post subject: Reply with quote

Well, I see the df just reads /proc/self/mountinfo in read_file_system_list in file lib/mountlist.c, so I shouldn't fault it for not following the symlink.

It would have to be patched tp check for /dev/root and then find the link target.

EDIT:
A lot easier to just make a local scripy to run df, then "ls -l /dev/root". A script wizard code run "ls" first, extract the value. run df in into a tempfile, use awk or sed to change the file then echo the file to stdout and delete it.

It ain't me It ain't me. I ain't no fortunate son.
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 3345
Location: Rasi, Finland

PostPosted: Tue Oct 27, 2020 7:00 pm    Post subject: Reply with quote

This one break the formatting:
Code:
df | awk '{if ($1 ~ /^\//) {"realpath " $1 | getline realdev; close("realpath " $1); $1 = realdev} print}'
... so one would need to modify $0 directly... via sub() maybe.

EDIT: It was quite easy
Code:
df | awk '{if ($1 ~ /^\//) {"realpath " $1 | getline realdev; close("realpath " $1); sub($1,realdev)} print}'
Pretty? No.
_________________
..: Zucca :..
Gentoo IRC channels reside on Libera.Chat.
--
Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Tony0945
Watchman
Watchman


Joined: 25 Jul 2006
Posts: 5127
Location: Illinois, USA

PostPosted: Tue Oct 27, 2020 8:56 pm    Post subject: Reply with quote

pretty, yes!
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