How to Check Physical Disks and Free Space in LVM for Storage Expansion


2 views

When working with Logical Volume Manager (LVM), it's crucial to know which physical disks are backing your logical volumes and how much unallocated space remains available for expansion. The standard df command only shows mounted filesystems, not the underlying physical storage.

To see what physical disks are used by your volume group:

# pvdisplay -m
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg0
  PV Size               100.00 GiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              25599
  Free PE               20479
  Allocated PE          5120
  PV UUID               abc123-xzy-789

  --- Physical Segments ---
  Physical extent 0 to 5119:
    Logical volume      /dev/vg0/rootlv
    Logical extents    0 to 5119

To see available space in your volume group that can be allocated to logical volumes:

# vgdisplay vg0
  --- Volume group ---
  VG Name               vg0
  System ID             
  Format                lvm2
  VG Size               100.00 GiB
  PE Size               4.00 MiB
  Total PE              25599
  Alloc PE / Size       5120 / 20.00 GiB
  Free  PE / Size       20479 / 80.00 GiB
  VG UUID               def456-uvw-012

If you want to expand /dev/vg0/rootlv by 10GB:

# lvextend -L +10G /dev/vg0/rootlv
# resize2fs /dev/vg0/rootlv

For a complete overview of your LVM setup:

# lvmdiskscan
# lvs -a -o +devices

For a graphical representation of your LVM setup:

# lvm vgs --reportformat json
# lvm pvs --reportformat json | jq '.report[].pv[].vg_name'

When working with Logical Volume Manager (LVM), it's crucial to understand both the physical disk allocation and available free space to effectively manage storage expansion. The standard df command only shows logical volume usage, not the underlying physical disks.

To see which physical volumes (PVs) compose your volume group (VG), use:

sudo pvdisplay

For a more concise view of physical disks in your volume group:

sudo pvs

Example output showing PV-VG mapping:

PV         VG   Fmt  Attr PSize  PFree
/dev/sda2  vg0  lvm2 a--  100.00g 20.00g
/dev/sdb1  vg0  lvm2 a--  200.00g 50.00g

To see available space in your volume group that can be allocated to logical volumes:

sudo vgdisplay vg0 | grep "Free"

Or for all VGs with free space:

sudo vgs --units g -o vg_name,vg_size,vg_free

Before expanding a logical volume (like /home from your example), first verify:

# Check current LV usage
sudo lvdisplay /dev/vg0/homelv

# Check available space in VG
sudo vgdisplay vg0 | grep "Free"

# Check which PVs have space
sudo pvs -o+pv_used,pv_available

For comprehensive LVM space monitoring, create this custom view:

sudo lvs -o +devices,lv_size,lv_metadata_size,seg_size

This shows the exact physical disk allocation for each logical volume segment.

Create a script to monitor LVM storage health:

#!/bin/bash
echo "Physical Volumes:"
sudo pvs

echo -e "\nVolume Groups:"
sudo vgs

echo -e "\nLogical Volumes:"
sudo lvs --units g -o lv_name,vg_name,lv_size,lv_attr