Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to know the following information, before using the harddisk to create logical volumes or database.. Any perl modules or snippet would be of great help.

  1. how many hard disks are presented to my system?
  2. Find out their sizes ( total, used, available )
share|improve this question
You should add to your question the fact that you are using a VM. Specify the platform as well for better answers. – Tim Jun 1 '12 at 13:55
cant you just use: parted U B print – Behrooz Jun 1 '12 at 15:09

This can easily be found: cat /proc/partitions. Pretty easy to interpret and to script with:

major minor  #blocks  name

  11        0     182466 sr0
   8        0  156290904 sda
   8        1  156039313 sda1
   8        2          1 sda2
   8        5     248976 sda5
 252        0   52428800 dm-0
 252        1    9764864 dm-1
 252        2    9764864 dm-2
  • The sdx (where x is a character) devices are your disks
  • sdxn (where n is a number) are partitions
  • dm-n are Logical Volumes
  • mdn are Linux Software RAID
  • sr0 is the CD drive
share|improve this answer

In Debian (and probably most Linux) fdisk -l tells the total size of all disks. If you also want to know the size of partitions then you can write a script to parse the output and calculate based on start and end cylinders and block sizes.

To know the used and available space on disks, in general you have to mount them. A tool might exist for some file systems to get that information without mounting, but there is no general purpose tool that will work with all file systems.

share|improve this answer

If your "VMware" instance is an ESX/ESXi server, you can use the Web Services SDK to obtain this info.

I personally like Steve Jin's vijava library for querying the WS. http://vijava.sourceforge.net/

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.