How to check used space for each partitions in Linux?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to check used space for each partitions in Linux?
# 1  
Old 09-13-2017
How to check used space for each partitions in Linux?

we are using Disk utilization and filesystem utilization seperately. In AIX using
Code:
$lsvg
 rootvg 
datavg

Code:
$lspv hdisk1 
PHYSICAL VOLUME:    hdisk1                   VOLUME GROUP:     datavg 
PV IDENTIFIER:      00f65eab7acabb17 VG IDENTIFIER     00f65eab00004c00000001567b60a848
 PV STATE:           active 
STALE PARTITIONS:   0          ALLOCATABLE:      yes 
PP SIZE:            512 megabyte(s)          LOGICAL VOLUMES:  4 
TOTAL PPs:          899 (460288 megabytes)   VG DESCRIPTORS:   2
FREE PPs:           470 (240640 megabytes)   HOT SPARE:        no 
USED PPs:           429 (219648 megabytes)   MAX REQUEST:      256 kilobytes

I am able to get Total PPs,Free PPs and used PPs for hdisk0,hdisk1 using lspv and able to calculate disk utilization.
But in linux i tried like this,

Code:
$pvdisplay /dev/sda2  
--- Physical volume ---   
PV Name               /dev/sda2   
VG Name               VolGroup   
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

Using this not able to understand Disk size,used space, Free space.
using "df" we are already calculating filesystem utilization. now i need to calculate disk utilization.
->currently using "cat /proc/partitions" able to get size of each disk but not able to get used space for each disk.

Last edited by freeaac; 09-13-2017 at 04:26 AM.. Reason: code not intended correctly
# 2  
Old 09-13-2017
Trying a (mayhap too) simple approach:
Mount all partitions found in /proc/partitions, and then use df to find the respective usage, awk to sum them all up.
# 3  
Old 09-13-2017
So, a quick lesson in disk allocations. Apologies if this is already know to you.
  • Originally you would have to allocate s physical volume for each filesystem. Very difficult to use on servers with few disks or lots of small disks. You might end up having far more filesystems that you want and have to mount them in some hodge-podge to get enough space in the right locations. Yes, I am that old! Smilie It was still better than having data on tape and stream-reading it in. I just about remember punched card and paper tape too, but lets not go there! Smilie
  • Then you could slice the disk and allocate a slice for a filesystem. This was better, but very rigid.
  • More recently we got volume managers. You allocate disk slices to them, and they give much more functionality.
Fortunately, (so far as I know) AIX has always been with a volume manager built in and nearly (if not all) other unix flavours have them too. Some were purchasable extras like Veritas but most are built in.

With a volume manager, you can allocate it whole physical disks (real local disk, SAN provided etc.) or slices of physical disks. They build them into Volume Groups and you can then allocate a portion of the volume group as a logical volume to build your filesystems on. They also allow you to mirror data (protecting against a disk failure) and other useful features such as the ability to grow/shrink logical volumes and filesystems without having to save and restore your data.

There are therefore two things you are trying to measure here:-
  • How much space have I allocated
  • How much space have I used
Allocated space
This is what LVM has blended and configured as logical volumes for formatting as filesystems, allocating as swap/paging space or giving to software such as a database which can use the raw disk space. On AIX, you can do lsvg rootvg to get a summary of the root volume group (or other volume group you choose. On most Linux systems it will be vgdisplay -v <<vgname>>
You can also do this on AIX for a single physical volume with lspv hdisk0 or whatever (and pvdisplay for Linux etc.) but the lsvg/vgdisplay will probably be what you want. This should give you the total/allocated/free physical partitions (PPs) or physical extents (PEs) in the volume group. Hopefully you have some free space here so you can manoeuvre.

Used space
This is space in filesystems used by files. This is what most people will want to know most of the time. df -k or df -h will probably give you what you need here, that is total filesystem size, used space, frespace and a percentage used. It also may include information about i-nodes, the space allocated to keep information about all the files in the filesystem (block lists etc.)

Adjusting space with a volume manager
AIX is easy. Something like chfs -a size=+1 my_lv will grow the logical volume & filesystem by one 512-byte block, but because the volume group has a definition of the PP size, you will actually get the whole next PP allocated. You can, of course allocated a specific bigger number rather than adding 1 PP at a time.
Linux servers are quite easy too. Something but you work on the logical volume instead. Something like lvextend -r -L +1G /dev/mapper/my_lv will add 1Gb to the logical filesystem and the -r flag will extend the filesystem, indeed you can also reduce a filesystem on Linux with lvreduce and if you use the -r flag it will move your blocks that have data in them to within the remaining part of the logical volume. Depending on your OS version, it may unmount the filesystem to do the work and fail if it is busy.


Do you have enough information to work with or is there something you are stuck with? What sort of report do you need to produce?


I hope that this input helps,
Robin
This User Gave Thanks to rbatte1 For This Post:
# 4  
Old 09-13-2017
On Linux, instead of the hard-to-read pvdisplay use pvs.
(Analogue: vgdisplay and vgs, lvdisplay and lvs.)
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Linux

Linux partitions and limitations

In recently reading an article on linux basics before I embark and my personal installation project I came across this passage - IDE drives have three types of partition: primary, logical, and extended. The partition table is located in the master boot record (MBR) of a disk. The MBR is the... (12 Replies)
Discussion started by: Synchlavier
12 Replies

2. Shell Programming and Scripting

Check disk space

I am trying a script which will alert if disk space crosses some threshold, i googled it and got some scripts already, but they are not working with my server. The problem is, my filesystem names are big, so the sizes are moving to the second line. just like below any ideas? thanks in advance... (8 Replies)
Discussion started by: karthikeayan
8 Replies

3. SCO

check partitions size in MB

hi Howto check partitions size in MB on SCO 5.0.6? Using df command I can see just in blocks. (4 Replies)
Discussion started by: ccc
4 Replies

4. UNIX for Dummies Questions & Answers

Help needed to understand partitions in linux

Hi guys, It has been more than 2 month i switched to linux but i m still very much confused how linux handles and names the partitions. I have gone through couple of beginners material and found linux doesnt treat partitions as c: and d: instead it uses /dev/hda1 /dev/hda2 hda3 .But now i... (7 Replies)
Discussion started by: pinga123
7 Replies

5. Linux

What is the minimum number of partitions you need to install Linux?

I think its 3. Just to know if I am correct. / /boot swap :confused: (2 Replies)
Discussion started by: nitin09
2 Replies

6. Shell Programming and Scripting

Shell script partitions space monitor

Hello friends, I'm newbie in shell scripting... Until now i have this script: #!/bin/sh emailok = email1@domain.com emailissue = email2@domain.com limit="50" df -h | grep -vE '^Filesystem' | awk '{print $1 " " $4 " " $5}'|while read val do partition=$(echo $val | awk '{print... (9 Replies)
Discussion started by: john_doe
9 Replies

7. Linux

grub error 22,after removing linux partitions only windows is threre.Pc not booting.i

hi, in my pc linux and windows was there with 2 hdd in raid.i removed linux partititons.Now my ps is not booting giving grub error 22.Nothing works.I hace my data in windows.Hard disks are RAID.when tried to go to recovery mode from windoes boot cd,it says hard disk not detected.when tried with... (2 Replies)
Discussion started by: pankajd
2 Replies

8. Shell Programming and Scripting

check space !!!

The have written the below script :- ============================ SPACE=`bdf /DATA_TRANSFER|awk '{print $4}' |grep "%"` TEST="96%" if then echo "Continue ....." sleep 2 else echo " Current space for DATA_TRANSFER is less than 02 %" echo " Pls clear space and than continue ....."... (2 Replies)
Discussion started by: kamlesh_p
2 Replies

9. Linux

File Sharing among NTFS Partition & RH Linux 9 Partitions

Well Guys, will anybody solve my problem? I have installed Win XP and RH Linux 9 (Dual Boot) on an Intel x86 Machine. Everything is going fine except that I cannot share files among the two operating systems. For example, if I download a PDF file from internet and save it in my Win XP partition... (1 Reply)
Discussion started by: Jawwad
1 Replies
Login or Register to Ask a Question