How to obtain detailed device / partition info from file path on Linux (like UUID, hard drive serial etc.)

孤人 提交于 2019-12-03 11:46:16

This is a script on GitHub I came across earlier today that uses Python to fetch information about drive make and model (and lots of others).

/proc/partitions holds info on partitions; for more detailed information you'll have either to run a subprocess as you do now, or for example for GPT do the parsing yourself.

The best way to do that is via pyparted. Pyparted are python bindings to Parted maintained by one of the Parted developers. You can find the source code on github. Unfortunately UUID's cannot be found from parted so you have to parse blkid

sancelot

That would imply some utilities and anlyze output. Launched using os.popen, you can use bklkid to find uuids, reading /etc/mtab file permits to know which filesystem are mounted in your system and thus mountpoints. sfdisk -l output gives you disk anatomy.hdparm -I /dev/xxx will give you serial numbers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!