- Home
-
Linux LVM
Linux Logical Volume Manager (LVM) Cheatsheet
Comprehensive LVM reference covering physical volume management, volume group operations, logical volume commands, snapshots, resizing, and common storage management workflows for Linux system administrators. Perfect for managing storage on VPS servers and cloud environments.
Free account required
LVM Architecture Hierarchy
Table of Contents
LVM Overview
Logical Volume Manager (LVM) provides flexible disk management by abstracting physical storage into logical volumes that can be easily resized, moved, and managed.
Benefits
- • Resize volumes on-the-fly
- • Span multiple disks
- • Create snapshots
- • Easy migration
Use Cases
- • Server storage management
- • Database volumes
- • Virtual machine storage
- • Backup solutions
Key Components
- • Physical Volumes (PV)
- • Volume Groups (VG)
- • Logical Volumes (LV)
- • Physical Extents (PE)
Want to see which providers offer the best storage performance? Check our comprehensive VPS benchmark results to compare disk I/O across different providers.
Physical Volume Commands
pvcreate - Create Physical Volume
Initialize a disk or partition for use with LVM.
# Create PV on a partition
sudo pvcreate /dev/sdb1
# Create PV on entire disk
sudo pvcreate /dev/sdc
# Create multiple PVs at once
sudo pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd1
pvdisplay - Display Physical Volume Details
Show detailed information about physical volumes.
# Display all PVs with details
sudo pvdisplay
# Display specific PV
sudo pvdisplay /dev/sdb1
# Display in columns format
sudo pvdisplay -C
pvs - Physical Volume Summary
Quick summary of all physical volumes.
# List all PVs (concise)
sudo pvs
# Show with additional fields
sudo pvs -o +pv_used,pv_free
# Show all available fields
sudo pvs -o +all
pvscan - Scan for Physical Volumes
Scan all disks for physical volumes.
# Scan for all PVs
sudo pvscan
# Scan and cache results
sudo pvscan --cache
pvremove - Remove Physical Volume
Remove LVM labels from a physical volume.
# Remove PV (must not be in use)
sudo pvremove /dev/sdb1
# Force removal
sudo pvremove -ff /dev/sdb1
⚠️ Warning: Ensure the PV is not part of any VG before removing.
Volume Group Commands
vgcreate - Create Volume Group
Create a new volume group from one or more physical volumes.
# Create VG from single PV
sudo vgcreate vg_data /dev/sdb1
# Create VG from multiple PVs
sudo vgcreate vg_data /dev/sdb1 /dev/sdc1
# Create VG with specific PE size (default 4MB)
sudo vgcreate -s 8M vg_data /dev/sdb1
vgdisplay - Display Volume Group Details
Show detailed information about volume groups.
# Display all VGs
sudo vgdisplay
# Display specific VG
sudo vgdisplay vg_data
# Short format
sudo vgdisplay -s
vgs - Volume Group Summary
Quick summary of all volume groups.
# List all VGs
sudo vgs
# Show additional information
sudo vgs -o +vg_free,vg_size
# Show all fields
sudo vgs -o +all
vgextend - Extend Volume Group
Add physical volumes to an existing volume group.
# Add single PV to VG
sudo vgextend vg_data /dev/sdd1
# Add multiple PVs
sudo vgextend vg_data /dev/sdd1 /dev/sde1
vgreduce - Reduce Volume Group
Remove physical volumes from a volume group.
# Remove specific PV from VG
sudo vgreduce vg_data /dev/sdd1
# Remove all empty PVs
sudo vgreduce --all vg_data
💡 Note: Move data off the PV using pvmove before reducing.
vgremove - Remove Volume Group
Delete a volume group.
# Remove VG (must have no LVs)
sudo vgremove vg_data
# Force removal
sudo vgremove -f vg_data
vgscan - Scan for Volume Groups
Scan all disks for volume groups and rebuild cache.
# Scan for VGs
sudo vgscan
# Scan and rebuild cache
sudo vgscan --mknodes
Logical Volume Commands
lvcreate - Create Logical Volume
Create a new logical volume in a volume group.
# Create LV with specific size
sudo lvcreate -L 10G -n lv_home vg_data
# Create LV using percentage of VG
sudo lvcreate -l 100%FREE -n lv_data vg_data
# Create LV with percentage of VG
sudo lvcreate -l 50%VG -n lv_apps vg_data
# Create LV with number of extents
sudo lvcreate -l 2560 -n lv_web vg_data
lvdisplay - Display Logical Volume Details
Show detailed information about logical volumes.
# Display all LVs
sudo lvdisplay
# Display specific LV
sudo lvdisplay /dev/vg_data/lv_home
# Display by VG
sudo lvdisplay vg_data
lvs - Logical Volume Summary
Quick summary of all logical volumes.
# List all LVs
sudo lvs
# Show with additional fields
sudo lvs -o +lv_size,lv_path
# Show all fields
sudo lvs -o +all
lvextend - Extend Logical Volume
Increase the size of a logical volume.
# Extend by specific size
sudo lvextend -L +5G /dev/vg_data/lv_home
# Extend to specific total size
sudo lvextend -L 20G /dev/vg_data/lv_home
# Extend using all free space
sudo lvextend -l +100%FREE /dev/vg_data/lv_home
# Extend and resize filesystem automatically
sudo lvextend -L +5G -r /dev/vg_data/lv_home
💡 Tip: Use -r flag to automatically resize the filesystem after extending.
lvreduce - Reduce Logical Volume
Decrease the size of a logical volume.
# Reduce by specific size
sudo lvreduce -L -2G /dev/vg_data/lv_home
# Reduce to specific size
sudo lvreduce -L 10G /dev/vg_data/lv_home
# Reduce with filesystem resize
sudo lvreduce -L 10G -r /dev/vg_data/lv_home
⚠️ Warning: Always shrink the filesystem BEFORE reducing LV size to avoid data loss!
lvresize - Resize Logical Volume
Change the size of a logical volume (extend or reduce).
# Resize to specific size
sudo lvresize -L 15G /dev/vg_data/lv_home
# Resize with filesystem adjustment
sudo lvresize -L 15G -r /dev/vg_data/lv_home
lvremove - Remove Logical Volume
Delete a logical volume.
# Remove LV
sudo lvremove /dev/vg_data/lv_home
# Force removal without confirmation
sudo lvremove -f /dev/vg_data/lv_home
lvscan - Scan for Logical Volumes
Scan all disks for logical volumes.
# Scan for all LVs
sudo lvscan
# Verbose output
sudo lvscan -v
Filesystem Operations
After creating logical volumes, you need to format them with a filesystem and mount them. For a deeper understanding of Linux filesystems, see our Linux Filesystem cheatsheet.
Create Filesystem
# Create ext4 filesystem
sudo mkfs.ext4 /dev/vg_data/lv_home
# Create XFS filesystem
sudo mkfs.xfs /dev/vg_data/lv_data
# Create ext4 with label
sudo mkfs.ext4 -L "Home" /dev/vg_data/lv_home
Mount Logical Volume
# Create mount point
sudo mkdir -p /mnt/home
# Mount LV
sudo mount /dev/vg_data/lv_home /mnt/home
# Verify mount
df -h /mnt/home
Permanent Mount (fstab)
# Add to /etc/fstab for automatic mounting
sudo nano /etc/fstab
# Add this line:
/dev/vg_data/lv_home /mnt/home ext4 defaults 0 2
# Or use UUID (recommended)
# Find UUID
sudo blkid /dev/vg_data/lv_home
# Add to fstab:
UUID=xxxx-xxxx-xxxx /mnt/home ext4 defaults 0 2
# Test fstab
sudo mount -a
Resize Filesystem
# Resize ext4 filesystem (after extending LV)
sudo resize2fs /dev/vg_data/lv_home
# Resize XFS filesystem (must be mounted)
sudo xfs_growfs /mnt/home
# Shrink ext4 filesystem (unmount first)
sudo umount /mnt/home
sudo e2fsck -f /dev/vg_data/lv_home
sudo resize2fs /dev/vg_data/lv_home 10G
sudo mount /dev/vg_data/lv_home /mnt/home
💡 Note: XFS filesystems cannot be shrunk, only extended.
LVM Snapshots
LVM snapshots provide point-in-time copies of logical volumes, useful for backups and testing. Combine with tar archives for complete backup solutions.
Create Snapshot
# Create snapshot (allocate space for changes)
sudo lvcreate -L 5G -s -n lv_home_snap /dev/vg_data/lv_home
# Create snapshot using percentage
sudo lvcreate -l 20%ORIGIN -s -n lv_home_snap /dev/vg_data/lv_home
💡 Tip: Snapshot size should be 20-30% of the original volume for most use cases.
Mount Snapshot
# Create mount point
sudo mkdir -p /mnt/snap
# Mount snapshot (read-only recommended)
sudo mount -o ro /dev/vg_data/lv_home_snap /mnt/snap
# Mount read-write (for testing)
sudo mount /dev/vg_data/lv_home_snap /mnt/snap
Check Snapshot Usage
# View snapshot status
sudo lvs -a -o +lv_size,data_percent,snap_percent
# Display detailed snapshot info
sudo lvdisplay /dev/vg_data/lv_home_snap
Restore from Snapshot
# Unmount the original volume
sudo umount /mnt/home
# Merge snapshot (restore)
sudo lvconvert --merge /dev/vg_data/lv_home_snap
# If volume is active, merge happens on next activation
# Reboot or deactivate/reactivate the LV
sudo lvchange -an /dev/vg_data/lv_home
sudo lvchange -ay /dev/vg_data/lv_home
# Remount
sudo mount /dev/vg_data/lv_home /mnt/home
Remove Snapshot
# Unmount snapshot
sudo umount /mnt/snap
# Remove snapshot
sudo lvremove /dev/vg_data/lv_home_snap
Extend Snapshot
# If snapshot is filling up, extend it
sudo lvextend -L +2G /dev/vg_data/lv_home_snap
⚠️ Warning: If a snapshot fills up completely, it becomes invalid and unusable!
Common LVM Workflows
1. Complete LVM Setup (New Disk)
# Step 1: Create partition (optional, can use entire disk)
sudo fdisk /dev/sdb
# Create new partition, type 8e (Linux LVM)
# Step 2: Create Physical Volume
sudo pvcreate /dev/sdb1
# Step 3: Create Volume Group
sudo vgcreate vg_data /dev/sdb1
# Step 4: Create Logical Volume
sudo lvcreate -L 50G -n lv_home vg_data
# Step 5: Create filesystem
sudo mkfs.ext4 /dev/vg_data/lv_home
# Step 6: Mount
sudo mkdir -p /mnt/home
sudo mount /dev/vg_data/lv_home /mnt/home
# Step 7: Add to fstab for permanent mount
echo "/dev/vg_data/lv_home /mnt/home ext4 defaults 0 2" | sudo tee -a /etc/fstab
2. Extend Logical Volume (Add Space)
# Check available space in VG
sudo vgs
# Extend LV
sudo lvextend -L +20G /dev/vg_data/lv_home
# Resize filesystem (ext4)
sudo resize2fs /dev/vg_data/lv_home
# OR do both in one command
sudo lvextend -L +20G -r /dev/vg_data/lv_home
# For XFS (must be mounted)
sudo xfs_growfs /mnt/home
3. Add New Disk to Existing Volume Group
# Create PV on new disk
sudo pvcreate /dev/sdc1
# Add to existing VG
sudo vgextend vg_data /dev/sdc1
# Verify
sudo pvs
sudo vgs
# Now you have more space to create/extend LVs
sudo lvextend -L +50G /dev/vg_data/lv_home
sudo resize2fs /dev/vg_data/lv_home
4. Move Data Between Physical Volumes
# Move all data from one PV to others in the same VG
sudo pvmove /dev/sdb1
# Move to specific PV
sudo pvmove /dev/sdb1 /dev/sdc1
# Check progress
sudo pvmove --abort # To cancel if needed
# After move, remove PV from VG
sudo vgreduce vg_data /dev/sdb1
# Remove PV label
sudo pvremove /dev/sdb1
5. Backup with Snapshot
# Create snapshot
sudo lvcreate -L 5G -s -n lv_home_backup /dev/vg_data/lv_home
# Mount snapshot
sudo mkdir -p /mnt/backup
sudo mount -o ro /dev/vg_data/lv_home_backup /mnt/backup
# Perform backup
sudo rsync -avz /mnt/backup/ /backup/home/
# OR create tar backup
sudo tar czf /backup/home-$(date +%Y%m%d).tar.gz -C /mnt/backup .
# Cleanup
sudo umount /mnt/backup
sudo lvremove /dev/vg_data/lv_home_backup
6. Complete LVM Removal
# Unmount all LVs
sudo umount /mnt/home
# Remove from fstab
sudo nano /etc/fstab # Remove the line
# Remove Logical Volumes
sudo lvremove /dev/vg_data/lv_home
# Remove Volume Group
sudo vgremove vg_data
# Remove Physical Volumes
sudo pvremove /dev/sdb1
# Optional: Zero out partition
sudo dd if=/dev/zero of=/dev/sdb1 bs=1M count=100
Troubleshooting
LVM Not Detecting Volumes
# Scan for all volumes
sudo pvscan
sudo vgscan
sudo lvscan
# Rebuild cache
sudo pvscan --cache
sudo vgscan --mknodes
# Activate all volume groups
sudo vgchange -ay
Volume Group Not Found
# Check if VG is inactive
sudo vgs -a
# Activate VG
sudo vgchange -ay vg_data
# Check for missing PVs
sudo vgdisplay vg_data | grep -i missing
Cannot Remove Physical Volume
# Check if PV is in use
sudo pvs -o pv_name,vg_name,pv_used
# Move data off the PV first
sudo pvmove /dev/sdb1
# Then reduce from VG
sudo vgreduce vg_data /dev/sdb1
# Now remove
sudo pvremove /dev/sdb1
Snapshot Filled Up
# Check snapshot usage
sudo lvs -a -o +snap_percent
# If under 100%, extend it
sudo lvextend -L +2G /dev/vg_data/lv_home_snap
# If at 100%, snapshot is invalid
# Remove and recreate
sudo lvremove /dev/vg_data/lv_home_snap
sudo lvcreate -L 10G -s -n lv_home_snap /dev/vg_data/lv_home
Filesystem Won't Resize
# For ext4, check filesystem first
sudo umount /mnt/home
sudo e2fsck -f /dev/vg_data/lv_home
sudo resize2fs /dev/vg_data/lv_home
sudo mount /dev/vg_data/lv_home /mnt/home
# For XFS, must be mounted
sudo mount /dev/vg_data/lv_home /mnt/home
sudo xfs_growfs /mnt/home
View LVM Logs
# Check system logs for LVM issues
sudo journalctl -u lvm2* -n 100
# Check dmesg for disk/LVM errors
sudo dmesg | grep -i lvm
# Verbose LVM commands
sudo pvs -vvv
sudo vgs -vvv
sudo lvs -vvv
Need more diagnostic capabilities? Explore our server management tools for advanced troubleshooting.
Best Practices
- • Always backup important data before LVM operations
- • Use descriptive names for VGs and LVs (e.g., vg_data, lv_home)
- • Monitor snapshot usage to prevent them from filling up
- • Leave 10-20% free space in VGs for flexibility
- • Document your LVM structure and naming conventions
- • Test restore procedures regularly
- • Use
-r
flag with lvextend to auto-resize filesystem - • Always check available space before extending:
vgs
Related Cheatsheets
Linux Filesystem
Storage fundamentals and filesystem types
Linux Commands
Essential command-line operations
Linux Admin Tips
System management best practices
Docker
Container volumes and storage management
Tar Archives
Backup and compression workflows
Linux Hardening
Security best practices for storage
Optimize Your VPS Storage Management
LVM provides flexible storage management for VPS deployments. Compare VPS providers with reliable storage performance and features that support advanced disk management.