How to display used devices/free space when using LVM?

I have following situation:

=$ LC_ALL=C df -hP | column -t
Filesystem              Size  Used  Avail  Use%  Mounted  on
/dev/mapper/vg0-rootlv  19G   854M  17G    5%    /
/dev/mapper/vg0-homelv  19G   343M  18G    2%    /home
/dev/mapper/vg0-optlv   19G   192M  18G    2%    /opt
/dev/mapper/vg0-varlv   19G   357M  18G    2%    /var

I'd like to know what physical disks are used by these volumes, and how much free disk space (unallocated) I have, so that I will know how much I can grow these.


Solution 1:

This is relatively easy. Use lvdisplay to show logical volumes, vgdisplay to show volume groups (including free space available) and pvdisplay to show physical volumes.

You should get all the data you need from those three commands, albeit with some work to figure out what all the various bits of data mean.

Solution 2:

pvs, vgs and lvs are convenient easy-to-read alternatives to pvdisplay, vgdisplay and lvdisplay if you only need a summary. E.g. :

# pvs
  PV         VG     Fmt  Attr PSize   PFree 
  /dev/sda2  fedora lvm2 a--  232,59g 20,87g

Solution 3:

The "maps" option is what you are after. This works at the lv level as well as pv.

So if you want to see what room an LV is taking up on a volume, do

lvdisplay -m <volumegroupname>

If you want to see the usage of PVs, do

pvdisplay -m

Solution 4:

I like to use lsblk

lsblk -ao NAME,FSTYPE,FSSIZE,FSUSED,FSUSE%

Output enter image description here

Solution 5:

pvs -o+devices gives a concise output showing you all the PVs, what devices they're on, and at the end any free space and the device it is on.

But even more useful, to map physical extents to logical extents use: pvs --segments -o+lv_name,seg_start_pe,segtype

The output will look something like this:

  # pvs --segments -o+lv_name,seg_start_pe,segtype
  PV         VG   Fmt  Attr PSize    PFree    Start SSize LV      Start Type
  /dev/sda2  vg01 lvm2 a--   <71.02g       0      0   500 lvswap      0 linear
  /dev/sda2  vg01 lvm2 a--   <71.02g       0    500  2500 lvaudit     0 linear
[...]
  /dev/sdc1  vg01 lvm2 a--  <256.00g <185.63g     0  7518 lvdata  41890 linear
  /dev/sdc1  vg01 lvm2 a--  <256.00g <185.63g  7518   256 lvvar    2500 linear
  /dev/sdc1  vg01 lvm2 a--  <256.00g <185.63g  7774 10240 lvdata  49408 linear
  /dev/sdc1  vg01 lvm2 a--  <256.00g <185.63g 18014 47521             0 free

I can't take any credit for this. It's in the manpage for lvdisplay.