LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 09-04-2017, 03:01 AM   #1
freeac
LQ Newbie
 
Registered: Sep 2017
Posts: 8

Rep: Reputation: Disabled
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.

$ 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 "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

/dev/mapper/VolGroup-lv_root 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 partitions?
 
Old 09-04-2017, 03:40 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
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.
 
Old 09-04-2017, 03:52 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,735

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
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.

Last edited by michaelk; 09-04-2017 at 03:54 AM.
 
Old 09-04-2017, 04:15 AM   #4
freeac
LQ Newbie
 
Registered: Sep 2017
Posts: 8

Original Poster
Rep: Reputation: Disabled
@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.
 
Old 09-04-2017, 05:40 AM   #5
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,476

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
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.
 
Old 09-04-2017, 06:32 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,735

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
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.
 
Old 09-04-2017, 06:34 AM   #7
freeac
LQ Newbie
 
Registered: Sep 2017
Posts: 8

Original Poster
Rep: Reputation: Disabled
@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.
 
Old 09-04-2017, 06:48 AM   #8
freeac
LQ Newbie
 
Registered: Sep 2017
Posts: 8

Original Poster
Rep: Reputation: Disabled
@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
 
Old 09-04-2017, 07:08 AM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,735

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
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
 
1 members found this post helpful.
Old 09-04-2017, 12:22 PM   #10
freeac
LQ Newbie
 
Registered: Sep 2017
Posts: 8

Original Poster
Rep: Reputation: Disabled
@michaelk
i got it michael thank you.
could you please help me to how to calculate disk usage for this scenarios
 
Old 09-04-2017, 04:36 PM   #11
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,735

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
The output of the df command shows disk usage per filesytem.

https://www.tecmint.com/how-to-check...pace-in-linux/
 
Old 09-04-2017, 05:48 PM   #12
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,361

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
If you are going to process the o/p of 'df' automatically, you'll probably want the -P switch which forces the columns to align instead of wrapping.
 
Old 09-05-2017, 12:18 AM   #13
freeac
LQ Newbie
 
Registered: Sep 2017
Posts: 8

Original Poster
Rep: Reputation: Disabled
@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
 
Old 09-05-2017, 12:43 AM   #14
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
@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... ]

Last edited by ondoho; 09-05-2017 at 12:44 AM.
 
Old 09-06-2017, 12:38 AM   #15
freeac
LQ Newbie
 
Registered: Sep 2017
Posts: 8

Original Poster
Rep: Reputation: Disabled
Unhappy

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?

Last edited by freeac; 09-06-2017 at 12:43 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check and use unpartitioned space of Hard disk in linux. nhsarvaiya Linux - Hardware 11 03-13-2024 06:39 AM
LXer: Quick guide for Linux check disk space LXer Syndicated Linux News 0 04-25-2017 01:01 PM
[SOLVED] what is a logical partitions and group partitions and how to check disk space on a partition ITareliteralyMyInitials Linux - Newbie 10 02-08-2016 11:19 AM
How to check disk space in linux of remote server ? rockstar05 Linux - Server 10 08-28-2013 08:33 AM
[SOLVED] No space to create more partitions, but there is free space anon091 Linux - Newbie 35 10-31-2012 10:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration