LVM Commands - Manage Logical Volume Management

Learn essential LVM commands for creating, managing, and extending physical volumes, volume groups, and logical volumes. Master LVM for flexible storage management.

LVM Commands

LVM Command Reference

Logical Volume Management (LVM) provides a flexible way to manage storage devices in Linux. This section outlines essential LVM commands for creating, displaying, extending, reducing, and removing physical volumes (PVs), volume groups (VGs), and logical volumes (LVs).

Physical Volume (PV) Management

Physical volumes are the underlying storage devices that LVM uses. Commands here focus on their creation and inspection.

# PV - physical volume (disc); eg. /dev/sda

# Create PV
pvcreate /dev/sda

# Display info about PV
pvdisplay /dev/sda

Volume Group (VG) Management

Volume groups are pools of storage created from one or more physical volumes. These commands cover VG creation, extension, and management.

# VG - volume group; eg. vg0

# Create VG
vgcreate vg0 /dev/sda

# Display info about VG
vgdisplay vg0

# Add PV to VG, PV must be created before
vgextend vg0 /dev/sdb

# Remove PV from VG
pvmove /dev/sdb         # Move data from PV
vgreduce data /dev/sdb

# Deactivate VG, do this when you want to physically remove device
vgchange --activate n vg0

Logical Volume (LV) Management

Logical volumes are the usable storage partitions carved out from volume groups. This section details LV creation, resizing, and removal.

# LV - logical volume; eg. root

# Create LV
lvcreate --name root --size 8G vg0

# Extend LV size
lvextend --size 16G vg0/root

# Reduce LV size, FS must be resized first!
lvreduce --size 8G vg0/root

# Remove LV
lvremove vg0/root

Advanced LVM Features (Mirroring and Striping)

Explore commands for creating mirrored (RAID1) and striped (RAID0) logical volumes for data redundancy and performance.

# Create mirrored LV (RAID1)
lvcreate --name root --size 8G --mirrors 1 data vg0
# Mirror logs are stored on third device by default - if you don't have 3 or
# more devices in VG add '--mirrorlog core' to store logs in memory

# Enable mirroring on existing LV
lvconvert --mirrors 1 vg0/root

# Create stripped LV (RAID0)
lvcreate --name root --size 8G --stripes 2 --stripesize 4 vg0

Exclusive Activation in Clusters

Learn how to manage exclusive activation of Volume Groups in a cluster environment for high availability.

# Exclusive Activation of a Volume Group in a Cluster
# Link --> https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/High_Availability_Add-On_Administration/s1-exclusiveactive-HAAA.html
1> vgs --noheadings -o vg_name
2> volume_list = [ "rhel_root", "rhel_home" ]
3> dracut -H -f /boot/initramfs-$(uname -r).img $(uname -r)
4> Reboot the node
5> uname -r to verify the correct initrd image

For more in-depth information on LVM, refer to the official Red Hat Enterprise Linux Storage Administration Guide and the LVM man pages.