In Linux Logical Volume Management (LVM), logical volumes (LVs) can span across multiple physical volumes (PVs) within the same volume group (VG). This flexibility is great for storage management, but sometimes you need to know exactly which PVs contain the extents for a particular LV.
Here are the key commands to identify PV allocation for LVs:
# Display PV allocation for all LVs in a VG
sudo pvdisplay -m
# Show detailed LV segment information
sudo lvdisplay -m /dev/vg_name/lv_name
Let's walk through a real-world scenario with a VG named 'datavg' containing two PVs:
$ sudo vgdisplay datavg
--- Volume group ---
VG Name datavg
System ID
Format lvm2
VG Size 1.99 TiB
PE Size 4.00 MiB
Total PE 522237
Alloc PE / Size 522237 / 1.99 TiB
Free PE / Size 0 / 0
VG UUID abc123-xzy-789
Now let's examine the PV allocation:
$ sudo pvdisplay -m
--- Physical volume ---
PV Name /dev/sdb1
VG Name datavg
PV Size 1.00 TiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 262144
Free PE 0
Allocated PE 262144
PV UUID def456-uvw-012
--- Physical Segments ---
Physical extent 0 to 262143:
Logical volume /dev/datavg/lv_data
Logical extents 0 to 262143
--- Physical volume ---
PV Name /dev/sdc1
VG Name datavg
PV Size 1023.99 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 262143
Free PE 0
Allocated PE 262143
PV UUID ghi789-rst-345
--- Physical Segments ---
Physical extent 0 to 262142:
Logical volume /dev/datavg/lv_data
Logical extents 262144 to 524287
The output shows that our 'lv_data' LV spans both PVs:
- /dev/sdb1 contains logical extents 0-262143
- /dev/sdc1 contains logical extents 262144-524287
For scripting purposes, you can extract specific information:
# List which PVs an LV uses
sudo lvs -o +devices /dev/vg_name/lv_name
# Get PV allocation percentages
sudo pvs -o +pv_used,pv_used_percent
If you encounter issues:
- Ensure you have root privileges (or sudo access)
- Verify the LV is not inactive (use lvchange -a y to activate)
- Check for LVM filter restrictions in /etc/lvm/lvm.conf
When working with Logical Volume Manager (LVM), a common administrative task is determining which physical volumes (PVs) actually store the data for a given logical volume (LV). This becomes particularly important when:
- Planning storage migrations
- Troubleshooting performance issues
- Preparing for hardware maintenance
- Optimizing storage allocation
The most straightforward method uses the lvs
command with specific parameters:
# lvs -o +devices
LV VG Attr LSize Devices
lv_root vg_sys -wi-ao---- 50.00g /dev/sda2(0)
lv_home vg_sys -wi-ao---- 200.00g /dev/sda2(12288),/dev/sdb1(0)
For a more comprehensive view, combine multiple LVM commands:
# pvdisplay -m
--- Physical volume ---
PV Name /dev/sda2
VG Name vg_system
PV Size 465.76 GiB
Allocatable yes
PE Size 4.00 MiB
Total PE 119234
Free PE 5324
Allocated PE 113910
PV UUID abc123-xzy-789
--- Physical Segments ---
Physical extent 0 to 12287:
Logical volume /dev/vg_system/lv_root
Logical extents 0 to 12287
Physical extent 12288 to 119233:
Logical volume /dev/vg_system/lv_home
Logical extents 0 to 106945
For automated environments, here's a bash script that generates a PV-LV mapping report:
#!/bin/bash
for vg in $(vgs --noheadings -o vg_name); do
echo "Volume Group: $vg"
lvs --noheadings -o lv_name,devices $vg | while read lv devices; do
echo " LV: $lv"
echo "$devices" | tr ',' '\n' | sed 's/^/ /'
done
echo
done
When LVs span multiple PVs, you can check segment distribution:
# lvdisplay --maps vg_name/lv_name
--- Logical volume ---
LV Path /dev/vg_data/lv_archive
LV Name lv_archive
VG Name vg_data
LV UUID xyz789-123-abc
LV Write Access read/write
LV Creation host server1
--- Segments ---
Logical extents 0 to 51199:
Type linear
Physical volume /dev/sdc1
Physical extents 0 to 51199
Logical extents 51200 to 102399:
Type linear
Physical volume /dev/sdd1
Physical extents 0 to 51199
For RHEL/CentOS systems, the lvseg
command provides concise output:
# lvseg -v vg_application
LV LE PE PV PE Ranges
lv_app_data 1024 1024 /dev/sde1 0-1023
lv_app_logs 512 512 /dev/sdf1 0-511
lv_app_cache 256 256 /dev/sde1 1024-1279
lv_app_cache 256 256 /dev/sdf1 512-767