how to get partition information of a hard disk with python

Discussion in 'Python' started by Hellmut Weber, Sep 21, 2010.

  1. Hi list,
    I'm looking for a possibility to access the partiton inforamtion of a
    hard disk of my computer from within a python program.

    Googling I found the module 'parted' but didn't see any possibility to
    get the desired information.
    Is there any reasonable documentation for the parted module?

    Any idea is appreciated ;-)

    TIA

    Hellmut

    --
    Dr. Hellmut Weber
    Degenfeldstraße 2 tel +49-89-3081172
    D-80803 München-Schwabing mobil +49-172-8450321
    please: No DOCs, no PPTs. why: tinyurl.com/cbgq
     
    Hellmut Weber, Sep 21, 2010
    #1
    1. Advertising

  2. Hellmut Weber

    Nobody Guest

    On Wed, 22 Sep 2010 00:31:04 +0200, Hellmut Weber 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?
     
    Nobody, Sep 22, 2010
    #2
    1. Advertising

  3. Hellmut Weber

    Anssi Saari Guest

    Nobody <> writes:

    > On Wed, 22 Sep 2010 00:31:04 +0200, Hellmut Weber 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...
     
    Anssi Saari, Sep 30, 2010
    #3
  4. Hellmut Weber

    Nobody Guest

    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.
     
    Nobody, Sep 30, 2010
    #4
  5. In message <>, Anssi Saari wrote:

    > Nobody <> writes:
    >
    >> Have you considered parsing /proc/partitions?

    >
    > One could also just read the partition table directly, it's on the
    > first sector usually.


    The Linux kernel includes built-in support for something close to two dozen
    different partition formats, from the common ones like MS-DOS, Solaris, SGI,
    Ultrix, EFI and BSD on down. Why reinvent parts of that when you can get it
    all for free?
     
    Lawrence D'Oliveiro, Oct 3, 2010
    #5
  6. Hellmut Weber

    Anssi Saari Guest

    Lawrence D'Oliveiro <_zealand> writes:

    > The Linux kernel includes built-in support for something close to two dozen
    > different partition formats, from the common ones like MS-DOS, Solaris, SGI,
    > Ultrix, EFI and BSD on down. Why reinvent parts of that when you can get it
    > all for free?


    Because for the common case it's simple and easy and one might learn
    something interesting?

    But can you really get all that for free, in python? in other words,
    is there a python API for all that? The stuff in /proc/partitions
    seems rather limited to me, although I have only vanilla partitions on
    my computers.
     
    Anssi Saari, Oct 4, 2010
    #6
  7. Hellmut Weber

    Tim Chase Guest

    On 10/04/10 09:33, Anssi Saari wrote:
    > But can you really get all that for free, in python? in other words,
    > is there a python API for all that? The stuff in /proc/partitions
    > seems rather limited to me, although I have only vanilla partitions on
    > my computers.


    A similar question regarding reading partition-tables came up a
    while back, so you (or the OP) might be interested in the thread:

    http://www.mail-archive.com//msg267375.html

    where I threw together a little partition-reading code that
    should be fairly easy to modify.

    -tkc
     
    Tim Chase, Oct 4, 2010
    #7
  8. In message <>, Anssi Saari wrote:

    > Lawrence D'Oliveiro <_zealand> writes:
    >
    >> The Linux kernel includes built-in support for something close to two
    >> dozen different partition formats, from the common ones like MS-DOS,
    >> Solaris, SGI, Ultrix, EFI and BSD on down. Why reinvent parts of that
    >> when you can get it all for free?

    >
    > Because for the common case it's simple and easy and one might learn
    > something interesting?


    You consider it “interesting†to reinvent stuff that others have already
    done?

    > But can you really get all that for free, in python? in other words,
    > is there a python API for all that? The stuff in /proc/partitions
    > seems rather limited to me, although I have only vanilla partitions on
    > my computers.


    What more do you want?
     
    Lawrence D'Oliveiro, Oct 5, 2010
    #8
  9. Hellmut Weber

    Seebs Guest

    On 2010-10-05, Lawrence D'Oliveiro <_zealand> wrote:
    > In message <>, Anssi Saari wrote:
    >> Because for the common case it's simple and easy and one might learn
    >> something interesting?


    > You consider it ???interesting??? to reinvent stuff that others have already
    > done?


    That isn't what the other poster said. The claim was that you might learn
    something interesting.

    When I reinvent stuff others have already done, I usually do indeed learn
    something interesting. It may not be a good use of my time, but...

    Here's the thing. As a learning exercise, "reinvent something others have
    already done" is excellent. It means you have working code to study and
    think about. Once you already know everything, of course, it stops being
    useful, and then there's no reason to ever duplicate existing code.

    But I learned more from writing a roguelike game which was pretty much in
    no way superior to existing roguelikes than I would have from trying to
    invent a new kind of game when I didn't understand how to program in the
    first place, I suspect.

    -s
    --
    Copyright 2010, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
     
    Seebs, Oct 5, 2010
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    422
  2. Praveen
    Replies:
    1
    Views:
    984
    Rob Williscroft
    Nov 5, 2006
  3. snaporaz

    Inaccessible hard disk partition

    snaporaz, Nov 24, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    584
    snaporaz
    Nov 24, 2007
  4. MRAB
    Replies:
    0
    Views:
    444
  5. bolega
    Replies:
    1
    Views:
    685
    Stan Bischof
    Mar 28, 2011
Loading...

Share This Page