Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On linux, there is a /dev/root device node. This will be the same block device as another device node, like /dev/sdaX. How can I resolve /dev/root to the 'real' device node in this situation, so that I can show a user a sensible device name?

For example, I might encounter this situation when parsing /proc/mounts.

I'm looking for solutions that would work from a shell/python script but not C.

share|improve this question

migrated from stackoverflow.com Jul 28 '11 at 23:05

This question came from our site for professional and enthusiast programmers.

have you checked here ? linux-diag.sourceforge.net/Sysfsutils.html It recommends way to query the kernel about attached devices of all kinds, not sure, if its what you are looking for ! – user702846 Jul 28 '11 at 23:02
up vote 9 down vote accepted

Parse the root= parameter from /proc/cmdline.

share|improve this answer
Wow, lightning reactions :-) – kdt Jul 28 '11 at 23:00
So much safer than dereferencing a symbolic link. +1 :) – Tim Post Jul 29 '11 at 2:38
This works on the three distros (fc14, rhel5, ubuntu 11.04) that I've looked at, with the slight caveat that there is an extra step needed to deal with root=UUID= type arguments. – kdt Jul 29 '11 at 10:16
I'm interested in why this is safer than the readlink solution, could someone elaborate? – opello Jun 26 '13 at 13:53

On the systems I've looked at, /dev/root is a symlink to the real device, so readlink /dev/root (or readlink -f /dev/root if you want the full path), will do it.

share|improve this answer
Or just ls -l /dev/root - shorter to type :) – rozcietrzewiacz Jul 29 '11 at 6:32
@jankes, but then you have to parse the output of ls (he asked for something to use in a script). – cjm Jul 29 '11 at 7:17
Ah, sorry - overlooked that. – rozcietrzewiacz Jul 29 '11 at 7:46
Nope -- on my RHEL5 machine it's definitely not a symlink, although on an FC14 or ubuntu 11.04 machine it is. – kdt Jul 29 '11 at 10:15
Does not work on archlinux. – g33kz0r Jul 30 '13 at 18:31

Well /dev/root is just a symbolic link to the real device, so you can use readlink(2) to find out where it points from a program, or readlink(1) to do the same thing from a shell script.

share|improve this answer
No. Does not work on archlinux – g33kz0r Jul 30 '13 at 18:31

Maybe I'm missing something, but what about:

mount|grep ' / '|cut -d' ' -f 1
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.