Script finding partition on Linux

I want write script in Python which check partition on disk and return type, begin. I write code and I can get info about primary partition, but I don't have info about extended partition yet. How I can get info about it? This is my code:

#! /usr/bin/python

import struct

f=open('/mnt/ewf/ewf1')
mbr = bytearray()
mbr = f.read(512)
for disc in range(0,4):
    print("File type " + str(mbr[0x1BE+4 + disc*16]).encode('hex'))
    x = struct.unpack("<i", mbr[(0x1BE+8 + disc*16):(0x1BE+12 + disc*16)])
    print "Start partition: " + repr(x)

1 answer

  • answered 2017-11-12 20:02 alexisdevarennes

    Why not just use psutil ?

    import psutil
    psutil.disk_partitions()