How can I find out the free space on an LVM PV in human readable format?
The tool pvs
shows the output in whatever units you like.
$ pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 MMB lvm2 a-- 29.69G 6.91G
I noticed this mention in the man page:
--units hHbBsSkKmMgGtTpPeE
All sizes are output in these units: (h)uman-readable, (b)ytes,
(s)ectors, (k)ilobytes, (m)egabytes, (g)igabytes,(t)erabytes,
(p)etabytes, (e)xabytes. Capitalise to use multiples of 1000 (S.I.)
instead of 1024. Can also specify custom units e.g. --units 3M
Example
You can override the units like so:
$ pvs --units m
PV VG Fmt Attr PSize PFree
/dev/sda2 vg_switchboard lvm2 a-- 37664.00m 0m
Well, I said I'd give you a one liner so here it is but it really is not very good. @slm's answer is obviously the way to go. Anyway, the one-liner below assumes that the PV size is expressed in KBytes (which is not always the case) and prints GiB by default.
$ pvdisplay | perl -plne '$f=$1 if /Free PE\s*(\d+)/;
$s=$1 if /PE Size.*?(\d+)/;
print " Free Space\t\t",($s*$f)/1048576," GiB" if /UUID/'
/dev/cdrom: open failed: No medium found
--- Physical volume ---
PV Name /dev/sda2
VG Name MMB
PV Size 29.71 GB / not usable 19.77 MB
Allocatable yes
PE Size (KByte) 32768
Total PE 950
Free PE 221
Allocated PE 729
Free Space 6.90625 GiB
PV UUID QfZGfn-a3VV-IRkw-bV9g-6iqm-zXjN-y5e6gr
i know i'm a bit late to answer but i think the easiest way is just : (Same options work for vgs also),
$ pvs -o name,free --units g --noheadings
/dev/sda2 0g
/dev/sdb 18.40g
/dev/sdc 5.00g
/dev/sdd 14.00g