How to list PVs/VGs/LVs → pvs; vgs; lvs
How to List PVs/VGs/LVs → pvs; vgs; lvs
Table of Contents
1. [Introduction](#introduction)
2. [Prerequisites](#prerequisites)
3. [Understanding LVM Components](#understanding-lvm-components)
4. [Listing Physical Volumes (PVs)](#listing-physical-volumes-pvs)
5. [Listing Volume Groups (VGs)](#listing-volume-groups-vgs)
6. [Listing Logical Volumes (LVs)](#listing-logical-volumes-lvs)
7. [Advanced Options and Formatting](#advanced-options-and-formatting)
8. [Practical Examples and Use Cases](#practical-examples-and-use-cases)
9. [Common Issues and Troubleshooting](#common-issues-and-troubleshooting)
10. [Best Practices and Tips](#best-practices-and-tips)
11. [Conclusion](#conclusion)
Introduction
Logical Volume Management (LVM) is a powerful storage management system in Linux that provides flexibility in disk space allocation and management. Understanding how to effectively list and monitor Physical Volumes (PVs), Volume Groups (VGs), and Logical Volumes (LVs) is essential for system administrators and anyone working with Linux storage systems.
This comprehensive guide will teach you how to use the `pvs`, `vgs`, and `lvs` commands to display detailed information about your LVM configuration. You'll learn not only the basic commands but also advanced options, formatting techniques, and troubleshooting methods that will help you efficiently manage your storage infrastructure.
By the end of this article, you'll have a thorough understanding of how to inspect your LVM setup, interpret the output, and use this information for effective storage management and troubleshooting.
Prerequisites
Before diving into the commands, ensure you have:
- Linux System Access: Root or sudo privileges on a Linux system
- LVM Installed: Most modern Linux distributions include LVM by default
- Basic Command Line Knowledge: Familiarity with terminal operations
- Storage Understanding: Basic knowledge of disks, partitions, and file systems
- LVM Components: Understanding of the relationship between PVs, VGs, and LVs
Required Packages
On most distributions, LVM tools are pre-installed. If not, install them using:
```bash
Ubuntu/Debian
sudo apt-get install lvm2
RHEL/CentOS/Fedora
sudo yum install lvm2
or for newer versions
sudo dnf install lvm2
Arch Linux
sudo pacman -S lvm2
```
Understanding LVM Components
Before exploring the listing commands, it's crucial to understand the three main components of LVM:
Physical Volumes (PVs)
Physical Volumes are the foundation of LVM. They can be:
- Entire hard drives
- Disk partitions
- RAID arrays
- Network storage devices
Volume Groups (VGs)
Volume Groups combine one or more Physical Volumes into a single storage pool. They act as a container for Logical Volumes and provide the abstraction layer that makes LVM flexible.
Logical Volumes (LVs)
Logical Volumes are created from Volume Groups and function like traditional partitions. They can be dynamically resized and moved between Physical Volumes.
Listing Physical Volumes (PVs)
The `pvs` command provides a concise overview of all Physical Volumes in your system.
Basic pvs Command
```bash
sudo pvs
```
Example Output:
```
PV VG Fmt Attr PSize PFree
/dev/sda2 ubuntu lvm2 a-- <19.00g 0
/dev/sdb1 data lvm2 a-- <10.00g 2.00g
/dev/sdc1 lvm2 --- <5.00g 5.00g
```
Understanding pvs Output Columns
| Column | Description |
|--------|-------------|
| PV | Physical Volume device path |
| VG | Volume Group name (empty if not assigned) |
| Fmt | Format type (usually lvm2) |
| Attr | Attributes (a=allocatable, -=not allocatable) |
| PSize | Physical size of the volume |
| PFree | Free space available |
Detailed Physical Volume Information
For more comprehensive information, use the `pvdisplay` command:
```bash
sudo pvdisplay
```
Example Output:
```
--- Physical volume ---
PV Name /dev/sda2
VG Name ubuntu
PV Size <19.00 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 4863
Free PE 0
Allocated PE 4863
PV UUID abc123-def4-5678-90gh-ijklmnopqrst
```
Customizing pvs Output
You can customize the output using various options:
```bash
Show specific columns
sudo pvs -o pv_name,vg_name,pv_size,pv_free
Show all available information
sudo pvs -v
Display in different units
sudo pvs --units m # Megabytes
sudo pvs --units g # Gigabytes
sudo pvs --units t # Terabytes
```
Listing Volume Groups (VGs)
The `vgs` command displays information about Volume Groups in your system.
Basic vgs Command
```bash
sudo vgs
```
Example Output:
```
VG #PV #LV #SN Attr VSize VFree
data 1 2 0 wz--n- <10.00g 2.00g
ubuntu 1 2 0 wz--n- <19.00g 0
```
Understanding vgs Output Columns
| Column | Description |
|--------|-------------|
| VG | Volume Group name |
| #PV | Number of Physical Volumes |
| #LV | Number of Logical Volumes |
| #SN | Number of snapshots |
| Attr | Attributes (w=writeable, z=resizable, n=normal) |
| VSize | Total size of Volume Group |
| VFree | Free space in Volume Group |
Detailed Volume Group Information
Use `vgdisplay` for comprehensive Volume Group details:
```bash
sudo vgdisplay
```
Example Output:
```
--- Volume group ---
VG Name ubuntu
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <19.00 GiB
PE Size 4.00 MiB
Total PE 4863
Alloc PE / Size 4863 / <19.00 GiB
Free PE / Size 0 / 0
VG UUID xyz789-abc1-2345-67de-fghijklmnopq
```
Customizing vgs Output
```bash
Show specific information
sudo vgs -o vg_name,pv_count,lv_count,vg_size,vg_free
Show all Volume Groups with extended information
sudo vgs -v
Display specific Volume Group
sudo vgs ubuntu
Show in different formats
sudo vgs --units m
sudo vgs --separator ":"
```
Listing Logical Volumes (LVs)
The `lvs` command displays information about Logical Volumes in your system.
Basic lvs Command
```bash
sudo lvs
```
Example Output:
```
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home data -wi-ao---- 5.00g
projects data -wi-ao---- 3.00g
root ubuntu -wi-ao---- <17.04g
swap_1 ubuntu -wi-ao---- 1.96g
```
Understanding lvs Output Columns
| Column | Description |
|--------|-------------|
| LV | Logical Volume name |
| VG | Volume Group containing the LV |
| Attr | Attributes (various flags) |
| LSize | Size of Logical Volume |
| Pool | Thin pool name (if applicable) |
| Origin | Origin volume for snapshots |
| Data% | Data usage percentage |
| Meta% | Metadata usage percentage |
Logical Volume Attributes Explained
The Attr column contains important flags:
- 1st character: Volume type (- = linear, m = mirrored, s = snapshot)
- 2nd character: Permissions (w = writeable, r = read-only)
- 3rd character: Allocation policy (i = inherited, c = contiguous)
- 4th character: Fixed minor number (- = no, m = yes)
- 5th character: State (a = active, s = suspended, I = invalid)
- 6th character: Device state (o = open, X = unknown)
Detailed Logical Volume Information
Use `lvdisplay` for comprehensive Logical Volume details:
```bash
sudo lvdisplay
```
Example Output:
```
--- Logical volume ---
LV Path /dev/ubuntu/root
LV Name root
VG Name ubuntu
LV UUID uvw456-xyz7-8901-23ab-cdefghijklmn
LV Write Access read/write
LV Creation host, time ubuntu-server, 2023-01-15 10:30:25 +0000
LV Status available
# open 1
LV Size <17.04 GiB
Current LE 4362
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
```
Customizing lvs Output
```bash
Show specific columns
sudo lvs -o lv_name,vg_name,lv_size,lv_attr
Show all Logical Volumes with paths
sudo lvs -a
Display specific Volume Group's LVs
sudo lvs ubuntu
Show detailed information in custom format
sudo lvs --units g -o +lv_path,lv_kernel_major,lv_kernel_minor
```
Advanced Options and Formatting
Using Sorting and Filtering
```bash
Sort by size
sudo lvs --sort lv_size
Sort by Volume Group
sudo vgs --sort vg_name
Filter by specific criteria
sudo pvs -S 'pv_free > 1g'
sudo vgs -S 'vg_name =~ data'
sudo lvs -S 'lv_size > 5g'
```
Output Formatting Options
```bash
JSON output (LVM 2.03+)
sudo pvs --reportformat json
CSV format
sudo vgs --separator="," --noheadings
Custom formatting
sudo lvs --units g --nosuffix --separator="|" -o lv_name,vg_name,lv_size
```
Combining Commands
```bash
Show complete LVM overview
echo "=== Physical Volumes ==="
sudo pvs
echo -e "\n=== Volume Groups ==="
sudo vgs
echo -e "\n=== Logical Volumes ==="
sudo lvs
```
Practical Examples and Use Cases
Example 1: Storage Capacity Planning
```bash
#!/bin/bash
Storage overview script
echo "LVM Storage Overview"
echo "==================="
echo -e "\nPhysical Volumes:"
sudo pvs --units g -o pv_name,vg_name,pv_size,pv_free --sort pv_name
echo -e "\nVolume Groups:"
sudo vgs --units g -o vg_name,pv_count,lv_count,vg_size,vg_free --sort vg_name
echo -e "\nLogical Volumes:"
sudo lvs --units g -o lv_name,vg_name,lv_size,lv_attr --sort vg_name,lv_name
echo -e "\nStorage Summary:"
echo "Total PV Space: $(sudo pvs --noheadings --units g -o pv_size | awk '{sum+=$1} END {print sum"G"}')"
echo "Total VG Space: $(sudo vgs --noheadings --units g -o vg_size | awk '{sum+=$1} END {print sum"G"}')"
echo "Total LV Space: $(sudo lvs --noheadings --units g -o lv_size | awk '{sum+=$1} END {print sum"G"}')"
```
Example 2: Monitoring Script
```bash
#!/bin/bash
LVM monitoring script
THRESHOLD=90
echo "LVM Space Monitoring"
echo "==================="
Check Volume Group usage
while read vg size free; do
if [ "$free" != "VFree" ] && [ "$free" != "" ]; then
used_percent=$(echo "scale=2; (1 - $free / $size) * 100" | bc -l 2>/dev/null || echo "0")
if (( $(echo "$used_percent > $THRESHOLD" | bc -l 2>/dev/null || echo "0") )); then
echo "WARNING: Volume Group $vg is ${used_percent}% full"
fi
fi
done < <(sudo vgs --noheadings --units g --nosuffix -o vg_name,vg_size,vg_free)
```
Example 3: Backup Information Collection
```bash
#!/bin/bash
Collect LVM configuration for backup
OUTPUT_FILE="/tmp/lvm_config_$(date +%Y%m%d_%H%M%S).txt"
{
echo "LVM Configuration Backup"
echo "Generated on: $(date)"
echo "Hostname: $(hostname)"
echo "========================="
echo -e "\nPhysical Volumes:"
sudo pvdisplay
echo -e "\nVolume Groups:"
sudo vgdisplay
echo -e "\nLogical Volumes:"
sudo lvdisplay
echo -e "\nLVM Configuration:"
sudo cat /etc/lvm/lvm.conf
} > "$OUTPUT_FILE"
echo "LVM configuration saved to: $OUTPUT_FILE"
```
Common Issues and Troubleshooting
Issue 1: Command Not Found
Problem: `pvs`, `vgs`, or `lvs` commands return "command not found"
Solution:
```bash
Check if LVM is installed
which pvs vgs lvs
Install LVM if missing
sudo apt-get install lvm2 # Ubuntu/Debian
sudo yum install lvm2 # RHEL/CentOS
```
Issue 2: Permission Denied
Problem: Commands fail with permission errors
Solution:
```bash
Use sudo for all LVM commands
sudo pvs
sudo vgs
sudo lvs
Or switch to root user
sudo su -
```
Issue 3: No Output or Empty Results
Problem: Commands run but show no results
Diagnosis:
```bash
Check if LVM is active
sudo systemctl status lvm2-lvmetad
sudo systemctl status lvm2-monitor
Scan for Physical Volumes
sudo pvscan
Scan for Volume Groups
sudo vgscan
Scan for Logical Volumes
sudo lvscan
```
Solution:
```bash
Activate Volume Groups
sudo vgchange -ay
Refresh LVM cache
sudo pvscan --cache
sudo vgscan --mknodes
```
Issue 4: Inconsistent Information
Problem: Different commands show conflicting information
Solution:
```bash
Update LVM metadata
sudo vgcfgrestore --list [VG_NAME]
Backup and restore metadata
sudo vgcfgbackup
sudo vgcfgrestore [VG_NAME]
Force metadata update
sudo vgscan --mknodes
```
Issue 5: Missing Physical Volumes
Problem: Physical Volumes appear as missing or unknown
Diagnosis:
```bash
Check system logs
sudo journalctl -u lvm2-monitor
dmesg | grep -i lvm
Verify disk status
sudo fdisk -l
lsblk
```
Solution:
```bash
Re-scan devices
sudo pvscan
If disk is present but PV is missing
sudo pvcreate --restorefile /etc/lvm/backup/[VG_NAME] --uuid [PV_UUID] /dev/[DEVICE]
Restore Volume Group
sudo vgcfgrestore [VG_NAME]
```
Best Practices and Tips
Regular Monitoring
1. Create Monitoring Scripts: Implement automated scripts to check LVM status regularly
2. Set Up Alerts: Configure system alerts for low space conditions
3. Document Configuration: Maintain up-to-date documentation of your LVM setup
Performance Optimization
```bash
Use appropriate options for better performance
sudo pvs --aligned # Better formatted output
sudo vgs --units h # Human-readable units
sudo lvs -a # Show all logical volumes including hidden ones
```
Security Considerations
1. Limit Access: Ensure only authorized users can execute LVM commands
2. Backup Metadata: Regularly backup LVM metadata
3. Monitor Changes: Keep track of LVM configuration changes
Automation Tips
```bash
Create aliases for common commands
alias lvm-overview='sudo pvs && echo && sudo vgs && echo && sudo lvs'
alias lvm-space='sudo vgs -o vg_name,vg_size,vg_free'
Use watch for real-time monitoring
watch -n 5 'sudo vgs -o vg_name,vg_size,vg_free'
```
Troubleshooting Checklist
1. Verify Permissions: Ensure you have appropriate privileges
2. Check System Status: Verify LVM services are running
3. Examine Logs: Review system logs for error messages
4. Validate Hardware: Confirm underlying storage devices are healthy
5. Test Connectivity: For network storage, verify network connectivity
Advanced Usage Patterns
```bash
Combine with other tools
sudo pvs | grep -v "PFree.*0" # Show only PVs with free space
sudo lvs | awk '$4 ~ /G/ && $4+0 > 5' # Show LVs larger than 5GB
Use in scripts
VG_FREE=$(sudo vgs --noheadings --units g --nosuffix -o vg_free ubuntu)
if (( $(echo "$VG_FREE < 1" | bc -l) )); then
echo "Warning: Less than 1GB free in ubuntu VG"
fi
```
Conclusion
Understanding how to effectively use `pvs`, `vgs`, and `lvs` commands is fundamental for successful LVM management in Linux environments. These tools provide essential insights into your storage infrastructure, enabling informed decisions about capacity planning, troubleshooting, and optimization.
Key takeaways from this guide:
1. Basic Commands: `pvs`, `vgs`, and `lvs` provide quick overviews of your LVM components
2. Detailed Information: Use `pvdisplay`, `vgdisplay`, and `lvdisplay` for comprehensive details
3. Customization: Leverage various options to format output according to your needs
4. Monitoring: Implement regular monitoring to prevent storage issues
5. Troubleshooting: Follow systematic approaches to diagnose and resolve problems
Next Steps
After mastering these listing commands, consider exploring:
- LVM Creation: Learn to create PVs, VGs, and LVs
- Resizing Operations: Understand how to expand and shrink volumes
- Snapshot Management: Implement backup strategies using LVM snapshots
- Advanced Features: Explore thin provisioning, RAID configurations, and caching
- Automation: Develop scripts for automated LVM management tasks
Regular practice with these commands in a test environment will build confidence and expertise in managing Linux storage systems effectively. Remember to always backup critical data before making changes to production LVM configurations.
The flexibility and power of LVM make it an invaluable tool for Linux system administrators, and mastering these fundamental listing commands is your first step toward becoming proficient in advanced storage management techniques.