469,909 Members | 1,765 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,909 developers. It's quick & easy.

Easy way to detect hard drives and partitions in Linux

I need a way to detect hard drives and their partitions... labels would
be nice too... I did some googling but did not find anything all too
useful. This will strictly be on Linux / Unix so any help would be
greatly appreciated.

TIA

Jul 19 '05 #1
3 5206
RunLevelZero wrote:
I need a way to detect hard drives and their partitions... labels would
be nice too... I did some googling but did not find anything all too
useful. This will strictly be on Linux / Unix so any help would be
greatly appreciated.


os.popen('/sbin/sfdisk -l /dev/hda') etc... ?

Or reading from /proc/ide and friends?
Jul 19 '05 #2
You're not going to find a single portable "unix" way of doing this.
The format of /etc/fstab and /etc/mtab are pretty portable, but they
only list mountable/mounted partitions, not all partitions.

In addition to the linux possibilities mentioned in another reply, there
is also /proc/partitions. Finally, if you only want to recognize
FDISK.EXE-type partitions (used by many types of Linux, though that
seems to be changing in Fedora Core 4), it shouldn't be hard to write a
Python program to read the partition table directly from the disk. The
details will be readily available online.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFCn0rcJd01MZaTXX0RAhVLAJ90DC3XyxTcgnweHqvHbq fQlBKZIgCfSpdl
O8X4WWSLBjcr6tJxIJUAiz4=
=evN/
-----END PGP SIGNATURE-----

Jul 19 '05 #3


Jeff Epler wrote:
You're not going to find a single portable "unix" way of doing this.
The format of /etc/fstab and /etc/mtab are pretty portable, but they
only list mountable/mounted partitions, not all partitions.

In addition to the linux possibilities mentioned in another reply, there
is also /proc/partitions. Finally, if you only want to recognize
FDISK.EXE-type partitions (used by many types of Linux, though that
seems to be changing in Fedora Core 4), it shouldn't be hard to write a
Python program to read the partition table directly from the disk. The
details will be readily available online.

Jeff


Well thanks for the responses and so quickly. I'm very new to
programming and am not afraid to say it. I'll see what I can come up
with. at least this is a good start.

Thanks.

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Steve | last post: by
6 posts views Thread by cantabile | last post: by
3 posts views Thread by Flix | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.