Skip to main content

Command documentation sourced from the linux-command project This comprehensive command reference is part of the linux-command documentation project.

lvremove - Remove logical volume

The lvremove command is a powerful LVM (Logical Volume Manager) utility used to remove logical volumes from a volume group. This command permanently deletes logical volumes and frees up the allocated space within the volume group for reuse. It's an essential tool for storage administrators managing flexible storage environments, allowing for dynamic resizing and cleanup of logical volumes as storage needs change. The command includes safety features like confirmation prompts and force options for automated scripts.

Basic Syntax

lvremove [OPTIONS] LogicalVolume[Path] [LogicalVolume[Path]...]
lvremove [OPTIONS] VGName/LVName [VGName/LVName...]

Common Options

Removal Options

  • -f, --force - Remove logical volumes without confirmation prompts
  • --noudevsync - Disable udev synchronization
  • -y, --yes - Answer yes to all prompts automatically

Display Options

  • -v, --verbose - Provide verbose output showing removal progress
  • -h, --help - Display help information
  • --version - Show version information

Advanced Options

  • --noudevrules - Skip udev rule generation
  • -t, --test - Run in test mode (dry run)
  • -A, --autobackup - Automatic metadata backup

Selection Options

  • -S, --select SelectionString - Select volumes based on criteria
  • --commandprofile ProfileName - Use specific command profile
  • --profile ProfileName - Use specific profile

Usage Examples

Basic Logical Volume Removal

Removing Single Logical Volumes

# Remove a specific logical volume with confirmation
lvremove /dev/vg_data/lv_backup

# Remove using VG/LV notation
lvremove vg_data/lv_backup

# Remove multiple logical volumes
lvremove /dev/vg_data/lv_temp1 /dev/vg_data/lv_temp2

# Remove without confirmation prompts
lvremove -f /dev/vg_data/lv_old_data

Removing with Different Path Formats

# Remove using full device path
lvremove /dev/mapper/vg_system-lv_home

# Remove using VG/LV format
lvremove vg_system/lv_home

# Remove multiple volumes in same volume group
lvremove vg_system/lv_test1 vg_system/lv_test2

Force Removal Operations

Automated Removal

# Force removal without prompts (for scripts)
lvremove -f vg_data/lv_temporary

# Auto-confirm all prompts
lvremove -y vg_data/lv_cleanup

# Force removal with verbose output
lvremove -f -v vg_data/lv_old_backup

# Remove multiple volumes without prompts
lvremove -f vg_temp/lv_test1 vg_temp/lv_test2 vg_temp/lv_test3

Safe Force Removal

# Test run before actual removal
lvremove --test vg_data/lv_candidate

# Remove with backup of metadata
lvremove -f -A vg_data/lv_archive

Volume Selection and Filtering

Selective Removal Based on Properties

# Remove volumes based on size criteria
lvremove --select 'lv_size > 10g' vg_storage

# Remove volumes with specific names
lvremove --select 'lv_name =~ temp_.*' vg_workspace

# Remove inactive volumes
lvremove --select 'lv_attr =~ ^....i' vg_data

# Remove volumes smaller than 1GB
lvremove --select 'lv_size < 1g' vg_test

Advanced Selection Patterns

# Remove volumes matching multiple criteria
lvremove --select 'lv_name =~ backup_.* && lv_size < 5g' vg_archive

# Remove volumes with specific attributes
lvremove --select 'lv_attr =~ ^...-m' vg_workspace

# Remove volumes older than certain date (using tags)
lvremove --select 'lv_tags =~ old_.*' vg_maintenance

Batch Operations and Automation

Scripted Volume Cleanup

# Remove all temporary volumes in a group
for lv in $(lvs --noheadings -o lv_name vg_temp | grep temp_); do
lvremove -f vg_temp/$lv
done

# Remove volumes based on mount status
for mount in $(findmnt -l -n -o SOURCE | grep '/dev/mapper/'); do
# Skip mounted volumes, remove unmounted ones
if ! findmnt -l -n $mount >/dev/null 2>&1; then
lvremove -f $mount
fi
done

Conditional Removal

# Remove only if volume exists
if lvs vg_data/lv_test >/dev/null 2>&1; then
lvremove -f vg_data/lv_test
fi

# Remove volumes with confirmation check
echo "This will remove all volumes in vg_temp. Continue? (y/n)"
read confirm
if [ "$confirm" = "y" ]; then
lvremove -f vg_temp
fi

Practical Examples

System Administration

Storage Cleanup

# Clean up old backup volumes
lvremove -f vg_backup/backup_$(date -d '30 days ago' +%Y%m%d)

# Remove temporary workspace volumes
lvremove -y vg_workspace/temp_*

# Remove volumes marked for deletion
lvremove --select 'lv_tags =~ delete_me' vg_data

# Clean up test environment volumes
lvremove -f -v vg_test/lv_app_test vg_test/lv_db_test

Environment Management

# Remove development environment volumes
lvremove -f vg_dev/lv_dev_db vg_dev/lv_dev_app vg_dev/lv_dev_cache

# Remove staging volumes after deployment
lvremove -y vg_staging/stg_app vg_staging/stg_config

# Remove snapshot volumes after backup completion
lvremove --select 'segtype =~ snapshot && lv_name =~ snap_.*' vg_data

Storage Migration and Reorganization

Volume Group Restructuring

# Remove volumes to free space for new layout
lvremove -f vg_old/legacy_app vg_old/legacy_data

# Remove intermediate migration volumes
lvremove -y vg_migration/temp_source vg_migration/temp_target

# Clean up after volume group merger
lvremove --select 'lv_name =~ old_vg_.*' vg_merged

Space Reclamation

# Remove unused volumes to reclaim space
lvremove -f vg_data/lv_unused_archive vg_data/lv_old_temp

# Remove overprovisioned volumes
lvremove --select 'lv_size > 50g && lv_tags =~ overprovisioned' vg_storage

# Clean up duplicate test volumes
for i in {1..5}; do
lvremove -f vg_test/lv_duplicate_test_$i
done

Disaster Recovery and Maintenance

Failed Volume Cleanup

# Remove corrupted volumes
lvremove -f vg_data/lv_corrupted

# Remove volumes with I/O errors
lvremove --select 'lv_attr =~ .*p.*' vg_problematic

# Clean up after failed operations
lvremove -y vg_temp/lv_incomplete_operation

Maintenance Operations

# Remove volumes before maintenance window
lvremove -f vg_maintenance/lv_pre_maintenance_backup

# Remove maintenance snapshots
lvremove -y vg_data/snap_pre_maintenance vg_data/snap_during_maintenance

# Remove temporary volumes created for maintenance
lvremove -f vg_temp/lv_maintenance_temp_*

Advanced Usage

Complex Removal Scenarios

Conditional Removal Based on Status

# Remove only volumes that are not active
for lv in $(lvs --noheadings -o lv_path --select 'lv_attr =~ .....-'); do
lvremove -f $lv
done

# Remove volumes with specific permissions
lvremove --select 'lv_permissions =~ rw' vg_workspace

# Remove volumes not mounted in /etc/fstab
for lv in $(lvs --noheadings -o lv_path vg_data); do
if ! grep -q "$lv" /etc/fstab; then
lvremove -f $lv
fi
done

Safe Removal Procedures

# Check dependencies before removal
check_dependencies() {
local lv=$1
if mount | grep -q "$lv"; then
echo "ERROR: Volume $lv is mounted"
return 1
fi
if lvs --noheadings -o origin --select 'lv_attr =~ s.*' | grep -q "$lv"; then
echo "ERROR: Volume $lv has snapshots"
return 1
fi
return 0
}

# Safe removal with dependency checking
safe_lvremove() {
local lv=$1
if check_dependencies "$lv"; then
lvremove -f "$lv"
else
echo "Skipping removal of $lv due to dependencies"
fi
}

Integration with System Tools

Automated Cleanup Scripts

#!/bin/bash
# Automated old backup removal script

BACKUP_VG="vg_backups"
RETENTION_DAYS=30

# Find and remove old backup volumes
find_old_backups() {
local cutoff_date=$(date -d "$RETENTION_DAYS days ago" +%Y%m%d)
lvs --noheadings -o lv_name --select "lv_name =~ backup_.* && lv_date < $cutoff_date" $BACKUP_VG
}

# Remove old backups
for backup in $(find_old_backups); do
echo "Removing old backup: $backup"
lvremove -f "$BACKUP_VG/$backup"
done

echo "Cleanup completed"

Monitoring and Alerting Integration

# Monitor for volumes marked for deletion
monitor_deletions() {
local deletions=$(lvs --noheadings -o lv_name --select 'lv_tags =~ delete_pending')
if [ -n "$deletions" ]; then
echo "Alert: Found volumes pending deletion:"
echo "$deletions"
# Send alert to monitoring system
curl -X POST -d "message=Volumes pending deletion: $deletions" \
http://monitoring-system.example.com/alerts
fi
}

# Remove volumes with deletion tag
process_deletions() {
lvremove --select 'lv_tags =~ delete_pending' -f
}

Troubleshooting

Common Issues

Volume in Use Errors

# Error: Logical volume is in use
# Solution: Check for mounts and processes
mount | grep /dev/vg_data/lv_test
lsof /dev/vg_data/lv_test

# Unmount and remove processes
umount /dev/vg_data/lv_test
fuser -km /dev/vg_data/lv_test

# Then remove the volume
lvremove -f vg_data/lv_test

Snapshot Dependencies

# Error: Cannot remove volume with snapshots
# Solution: Remove snapshots first
lvs --noheadings -o lv_name --select 'origin=vg_data/lv_source'

# Remove snapshots before the source
lvremove -f vg_data/lv_snapshot1 vg_data/lv_snapshot2
lvremove -f vg_data/lv_source

Permission Issues

# Error: Permission denied
# Solution: Run with appropriate privileges
sudo lvremove -f vg_data/lv_test

# Check LVM permissions
groups $USER | grep lvm
sudo usermod -a -G lvm $USER

Volume Group Issues

# Error: Volume group not found
# Solution: Check volume group status
vgs vg_data
vgdisplay vg_data

# Import missing volume group
vgimport vg_data
vgchange -a y vg_data

# Then remove volumes
lvremove -f vg_data/lv_test

Recovery and Verification

Verification After Removal

# Verify volume is removed
lvs vg_data | grep lv_test
ls -la /dev/vg_data/lv_test

# Check space is reclaimed
vgs --noheadings -o vg_free --select 'vg_name=vg_data'

# Verify no dependencies remain
dmsetup ls | grep lv_test

Emergency Recovery

# If wrong volume was removed, check backups
vgcfgrestore --list vg_data

# Restore from backup if available
vgcfgrestore -f /etc/lvm/backup/vg_data vg_data

# Verify restored volumes
lvs vg_data

Best Practices

  1. Always verify volume contents before removal to prevent data loss
  2. Use test mode (--test) first to preview what will be removed
  3. Check for dependencies like mounts, snapshots, and active processes
  4. Create metadata backups (-A) before bulk operations
  5. Use selection criteria for automated cleanup to avoid manual errors
  6. Verify removal by checking volume listings and freed space
  7. Document removal reasons in change management systems
  8. Test scripts in non-production environments before deployment
  9. Monitor system impact during large volume removal operations
  10. Maintain proper backups of critical data before any removal operations

Performance Tips

  1. Batch removal of multiple volumes is more efficient than individual removals
  2. Use --noudevsync in automation scripts for faster removal
  3. Avoid verbose output (-v) in production scripts for better performance
  4. Consider system load when removing large volumes (>100GB)
  5. Schedule removals during maintenance windows for production systems
  6. Monitor I/O load during removal operations on active systems
  7. Use selection criteria rather than shell loops for better performance
  8. Plan space reclamation to account for metadata overhead changes
  9. Test removal performance with similar-sized test volumes first
  10. Consider parallel operations when removing volumes from different volume groups

The lvremove command is a critical component of LVM storage management, providing safe and flexible removal of logical volumes while maintaining data integrity and system stability through its comprehensive set of safety features and operational controls.