How to check used space for each partitions in Linux?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to check used space for each partitions in Linux?
I want to check used space for each and every partitions in Linux. I am using this command to get size of each partition but not able to get used space or free space.
I am able to get used space using "df" command, but "df" commands will show entire filesystem and not able to get used space for all partitions like /dev/sda2.
$ df -Tl
Filesystem Type 1K-blocks Used Available Use% Mounted on
The utility df gives the information you describe. What else is needed?
With the -T option as you have used it also tells you the type, but maybe you mean to have it in a more readable format? If so, the -h option will do that.
Either way, df will show you Filesystem name, file system Type, file system Size, amount Used, amount still Available, the percent in use and its mount point.
In addition, /dev/mapper/VolGroup-lv_root would indicate this is a logical volume which means that /dev/sda2 maybe a LVM partition.
Depends on what distribution/version and how it was installed but many automatically create a LVM with a /root and swap logical volumes. You can confirm this by looking at the output of the lsblk command.
As stated the df command will show used space for mounted filesystems but not the size of swap. You can use LVM commands like pvdisplay to see how lvm partition is allocated.
@michaelk
$lsblk -l
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 16G 0 disk
sda1 8:1 0 500M 0 part /boot
sda2 8:2 0 15.5G 0 part
VolGroup-lv_root (dm-0) 253:0 0 13.9G 0 lvm /
VolGroup-lv_swap (dm-1) 253:1 0 1.6G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom
yes michaelk sda2 is under lvm partition.
so how can i take used space for /dev/sda2? currently i am taking total space as sda and used space as sda1+sda2 with this command(cat /proc/partitions). so disk utilization as (sda1+sda2/sda)*100 and i am getting 99.9% which is wrong.
so how to calculate Disk utilization if volgroup is available for sda's?. Actually i am new to this.
LVM abstracts your disk partitions, you need to stop thinking of free space on individual partitions when using LVM. As you've seen with df your / partition is 29% used, so ~71% free.
How the disk is partitioned is unrelated to used space inside the file sytem.
For all practicable purposes your drive is 100% allocated. i.e 16 = .5 (sda1) + 15.5 (sda2)
On all of my systems with all drive space allocated using the number of blocks from /proc/partitions are 99.9...%
I assume your disk is using legacy MBR. In a nutshell the first sector of the disk contains the MBR which contains some of the bootloader code plus the partition table. Partitioning tools will align partitions on cylinder boundaries which might mean there is some unused space.
@TenTenths
thanks for reply.
i understand that if volume group is there for one partition, then we need to take that volume group used space and total space to calculate disk utilization?
no need to consider /dev/sda1 used and total space? if yes, please let me explain.
@michaelk
i did not understand this "Partitioning tools will align partitions on cylinder boundaries which might mean there is some unused space"
but df -Tl is showing free space, then what is the difference between df and cat /proc/partitions
In a nutshell a partition is a container for a filesystem. /proc/partitions displays the size of the container in blocks but because of overhead the size of the container does not equal the size of the filesystem. Formatting creates file system metadata which uses a percentage of the available container space.
In addition there is a small amount of LVM physical volume overhead so that will decrease the available container space for Volume groups/logical volumes.
Last edited by michaelk; 09-04-2017 at 07:22 AM.
Reason: add LVM
@michaelk
thank you and i just did this
$ df -P --total
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/mapper/VolGroup-lv_root 14225776 3792036 9704448 29% /
tmpfs 961596 72 961524 1% /dev/shm
/dev/sda1 487652 40187 421865 9% /boot
total 15675024 3832295 11087837 26%
so here total is showing 26% when i calculate((3832295/15675024)*100) i am getting 24%, so i need to remove "tmpfs" total size and used space to calculate disk usage?
Last edited by freeac; 09-05-2017 at 12:19 AM.
Reason: added calc
@freeac, you are over-complicating things.
there's still things like reserved blocks, MiB vs. MB, etc.
24% - 26% - close enough. you get an estimation. and your disk shouldn't ever be 99% full anyhow.
also you MUST use code tags when posting code (command output) here.
example:
Code:
[code]df -h .
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 40G 32G 5.3G 86% /
[/code]
[ edit: oops, it's getting full. off to do sth about it... ]
Thank you all
i noted all the points and get the filesystem utilization but i need disk Utilization for physical volumes.
Can i open one more thread for detailed explanation or i can discuss here?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.