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
vgcreateto combine physical volumes into a new volume group. - Extend a volume group: Use
vgextendto add more physical volumes to an existing volume group. - Reduce a volume group: Use
vgreduceto remove physical volumes from a volume group. - Remove a volume group: Use
vgremoveto delete an entire volume group. - List volume groups: Use
vgsto 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
lvcreateto create a new logical volume with a specified size within a volume group. - Resize an existing logical volume: Use
lvresizeto increase or decrease the size of a logical volume. - Activate a logical volume: Use
lvchange -ayto make a logical volume available for use. - Deactivate a logical volume: Use
lvchange -anto make a logical volume unavailable. - Remove a logical volume: Use
lvremoveto delete a logical volume. - List logical volumes: Use
lvsto 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
pvsto 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