I want to check used space for each and every partition in Linux. I am using this command to get size of each partition but not able to get used space or free space.

$ cat /proc/partitions
major minor   #blocks  name

   8      0   16777216  sda
   8      1     512000 sda1
   8      2   16264192 sda2
 253      0   14585856 dm-0     
 253      1    1675264 dm-1

I am able to get used space using df command, but it shows filesystems and it's not able to get used space for all the partitions like /dev/sda2.

$ df -Tl
Filesystem           Type  1K-blocks    Used Available Use% Mounted on
                     ext4   14225776 3791704   9704780  29% /
tmpfs                tmpfs    961596      72    961524   1% /dev/shm
/dev/sda1            ext4     487652   40187    421865   9% /boot

I want to calculate disk utilization. Is there any way to get used space and total space for each and every partition?

  • What's wrong with df exactly? Do you want to see the results for filesystems that are not mounted? Or do you have a filesystem that spawns over multiple devices and you want to check used space for each of them separately (whatever it means)? Or what? – Kamil Maciorowski Sep 4 '17 at 7:00
  • actually i want to calculate disk utilization using used space and available space for each partition in linux. using cat /proc/partitions it is showing all partitions with size but when i use df -h it is not showing /dev/sda2 partition with used space. – Free Aac Sep 4 '17 at 7:07
  • Is it mounted? Is there a filesystem there in the first place? In general it may be a swap partition, unsupported filesystem or whatever. I guess there's no tool that covers all the "whatevers". – Kamil Maciorowski Sep 4 '17 at 7:13
  • 1
    There is no notion of "used space" in a partition, because the partition concept doesn't know the files that are put in it (or you can consider that the partition is 100% full since all of it is allocated to a file system). The used space is only pertinent for a file system, because it can compare the size allocated to it (the partition size) and the space used by the files currently on it. – xenoid Sep 4 '17 at 8:04
  • 1
    I think your /dev/sda2 is used by LVM to host dm-0 etc. In this context it's 0% free, i.e. you cannot write to it without messing LVM. However you can write to /dev/mapper/VolGroup-lv_root mounted under / and this data will be stored on /dev/sda2 somehow. That's my guess. – Kamil Maciorowski Sep 4 '17 at 8:09

Since df -Tl shows a volumegroup it means you are using LVM on top of normal partitioning. This means that for the operating system the partition is always fully utilized and will show no free space. With df you can see the free space in the logical volume root. If you want to see more info from lvm you can run for example pvdisplay to see how the physical volumes are configured, and then lvdisplay to see how the logical volumes are configured.

  • if LVM is configured then how to calculate this disk usage?. – Free Aac Sep 5 '17 at 7:49
  • If you really just want to know how much space is left, just use df -h . The lvm volume shows just as a normal disk, you just manage it differently as you can grow the volume by adding disks or partitions to it. – Elias Sep 5 '17 at 10:17
  • In Aix by doing lspv hdisk0 able to get total PPs, Used PPs.. and able to calculate disk utilization, but in linux not able to understand pvdisplay, I tried pvdisplay /dev/sda2 i am getting [code]PV Size 15.51 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 3970 Free PE 0 Allocated PE 3970[/code] How to calculate Disk utilization by using this in linux? – Free Aac Sep 5 '17 at 12:03
  • pvdisplay would show free PE only if you have not allocated the space from a pv to an lv. So a logical volume is the layer on top of the physical volumes. And a logical volume shows directly as a mount point. So if you need to know how much of each partition is allocated to a pv, pvdisplay shows that, but normally that is 100%. df then shows the total available space in the whole logical volume and doesn't care about the partitions since they are not directly mounted to the OS. – Elias Sep 6 '17 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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