Get drives and partitions list (Linux)

Peter Hansen peter at engcorp.com
Sun Jun 12 21:56:52 EDT 2005


cantabile wrote:
> Hi, I'd like to get drives and partitions (and their size too) with
> python under Linux. So far, I thought of reading /proc/partitions but
> maybe i could use fdsik also ?
> How would I do that in python ?

Somebody else posted a very similar question quite recently.  A Google 
Groups search would probably lead you to the answers pretty quickly. 
(Try "partition proc sfdisk" or something like that.)

My previous answer was to call sfdisk, using os.popen().  Others 
suggested reading /proc/partitions.  I doubt fdisk (if that's what you 
meant) is a good idea.

There is no pure Python solution, so far as I know, probably because 
there may not be any standardized way of finding this information.

-Peter



More information about the Python-list mailing list