LVM Commands - Manage Logical Volume Manager

Master LVM commands for managing logical volumes. Learn to create, resize, activate, deactivate, and remove LVM volumes and volume groups efficiently.

LVM Commands

The Logical Volume Manager (LVM) provides a flexible way to manage disk storage in Linux. It allows you to create logical volumes that can span across multiple physical disks, resize them on the fly, and manage them more efficiently than traditional partitioning. Below is a collection of essential LVM commands to help you manage your storage effectively.

LVM Volume Group Management

Volume groups (VGs) are pools of storage made up of one or more physical volumes (PVs). Managing VGs is crucial for organizing your storage.

  • Create a new volume group: Use vgcreate to combine physical volumes into a new volume group.
  • Extend a volume group: Use vgextend to add more physical volumes to an existing volume group.
  • Reduce a volume group: Use vgreduce to remove physical volumes from a volume group.
  • Remove a volume group: Use vgremove to delete an entire volume group.
  • List volume groups: Use vgs to display information about existing volume groups.

LVM Logical Volume Management

Logical volumes (LVs) are the usable storage units created from volume groups. They behave like partitions but offer more flexibility.

  • Create a new logical volume: Use lvcreate to create a new logical volume with a specified size within a volume group.
  • Resize an existing logical volume: Use lvresize to increase or decrease the size of a logical volume.
  • Activate a logical volume: Use lvchange -ay to make a logical volume available for use.
  • Deactivate a logical volume: Use lvchange -an to make a logical volume unavailable.
  • Remove a logical volume: Use lvremove to delete a logical volume.
  • List logical volumes: Use lvs to display detailed information about logical volumes.

LVM Physical Volume Management

Physical volumes (PVs) are the underlying storage devices (like hard drives or partitions) that LVM uses.

  • Display physical volumes: Use pvs to show information about physical volumes.

For more in-depth information on LVM, refer to the Red Hat Enterprise Linux LVM documentation or the LVM man pages.

# lvm
# Activate the LVM2 command-line interface.

# List all existing volume groups
lvm vgs

# Display detailed information about all physical volumes
lvm pvs -v

# Activate a specific logical volume
lvm lvchange -ay /dev/VolumeGroupName/LogicalVolumeName

# Deactivate a specific logical volume
lvm lvchange -an /dev/VolumeGroupName/LogicalVolumeName

# Create a new logical volume with a specified size
lvm lvcreate -L 10G -n LogicalVolumeName VolumeGroupName

# Resize an existing logical volume
lvm lvresize -L +5G /dev/VolumeGroupName/LogicalVolumeName

# Remove a logical volume
lvm lvremove /dev/VolumeGroupName/LogicalVolumeName

# Display detailed information about logical volumes
lvm lvs -v

# Extend a volume group by adding a physical volume
lvm vgextend VolumeGroupName /dev/sdX

# Create a new volume group
lvm vgcreate VolumeGroupName /dev/sdX

# Reduce a volume group by removing a physical volume
lvm vgreduce VolumeGroupName /dev/sdX

# Remove a volume group
lvm vgremove VolumeGroupName