-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Linux] psutil.disk_partitions() returns /dev/root on Ubuntu 20.04 on AWS #1999
Comments
In here it says that |
Actually it seems it's more complicated than that: https://unix.stackexchange.com/questions/17563/find-out-what-device-dev-root-represents-in-linux/431968 |
This should do it: import os
def get_fs_device(path):
pmap = {}
with open("/proc/partitions") as f:
for line in f.readlines()[2:]:
fields = line.split()
major = int(fields[0])
minor = int(fields[1])
name = fields[3]
pmap[(major, minor)] = name
dev = os.stat(path).st_dev
name = pmap[(os.major(dev), os.minor(dev))]
return "/dev/%s" % name
print(get_fs_device("/")) On my Linux it prints |
I can confirm this does return the right device for me ( Is this something that |
Something like this will eventually have to be included in psutil, but in case of error we should probably return "/dev/root" instead of crashing. Also, I see there are multiple variants of the above code online (read /sys fs, use readlink(), parse /proc/cmdline, ...). We will probably have to implement these variants, and the code should try them all before (silently) giving up. |
Signed-off-by: Giampaolo Rodola <[email protected]>
Fixed in #2000. Out of curiosity, can you please paste the output of |
That was awesomely fast, thanks a ton! Here you have the output you requested:
And the same on the actual disk:
|
What about |
|
Summary
Description
On a default AWS instance running Ubuntu 20.04,
psutil.disk_partitions()
returns/dev/root
instead of/dev/xvda1
.This is because
/proc/mounts
contain this entry:However, the actual root disk device is
/dev/xvda1
. Bothmount
andfindmnt
do return the right device:I found some people doing a workaround to call
findmnt
manually in this case, but I think this should be handled by psutil.The text was updated successfully, but these errors were encountered: