how to get partition information of a hard disk with python

Nobody nobody at nowhere.com
Thu Sep 30 06:01:32 EDT 2010


On Thu, 30 Sep 2010 11:41:48 +0300, Anssi Saari wrote:

>>> I'm looking for a possibility to access the partiton inforamtion of a
>>> hard disk of my computer from within a python program.
>>
>> Have you considered parsing /proc/partitions?
> 
> One could also just read the partition table directly, it's on the
> first sector usually. (Assuming a PC without a GUID partition
> table...) The partition table is just 64 bytes at offset 446 into the
> sector. In unixlikes you can just open the disk with file.open()...
> Then again, unixlikes other than Linux have somewhat different ideas
> about partitioning...

Apart from the portability issues, you usually need elevated privileges
to read the disk directly, while /proc/partitions is normally readable by
anyone.

OTOH, many of the tasks for which partition information is necessary would
require root privilege anyhow.




More information about the Python-list mailing list