Logical Volume Management (LVM) is a disk management technology aimed at providing a more advanced and flexible method for managing disk space. Unlike traditional partitioning, LVM allows for volumes to be resized and moved around easily, even while the system is in use. It abstracts the physical hardware (hard disks, SSDs, etc.) to create a pool of logical volumes, providing a layer of versatility and control not available with conventional partitioning methods.
LVM operates by grouping physical volumes (PVs) into volume groups (VGs). Each VG can then be divided into logical volumes (LVs), which are seen by the operating system as regular partitions but with the added benefits of LVM's flexibility. These logical volumes can span across multiple physical volumes, making it easy to expand storage by simply adding more physical volumes to a volume group. LVM supports various types of logical volumes, such as linear volumes, mirrored volumes, and striped volumes, each serving different performance and redundancy needs.
pvcreate /dev/disk1 /dev/disk2 /dev/disk3
Initializes /dev/disk1
, /dev/disk2
, and /dev/disk3
as physical volumes (PVs) to be used in an LVM volume group.
vgcreate VG /dev/disk1 /dev/disk2 /dev/disk3
Creates a volume group (VG) named VG
, combining the previously initialized physical volumes. This group acts as a storage pool from which logical volumes can be allocated.
lvcreate -l +100%FREE VG -n LVName
Allocates all available space in the volume group VG
to a new logical volume named LVName
.
pvcreate /dev/cache
Initializes /dev/cache
as a physical volume to be used specifically for caching purposes within the LVM framework.
vgextend VG /dev/cache
Adds the cache physical volume to the existing volume group VG
, allowing it to be utilized for caching.
lvcreate --type cache --cachemode writethrough -l 100%FREE -n VG/LV /dev/cache
Creates a cache logical volume from the available space on /dev/cache
and attaches it to the logical volume LV
within the volume group VG
, using a write-through caching policy.
lvconvert --uncache /dev/VG/LV
Detaches the cache from the logical volume LV
within the volume group VG
, effectively removing the caching layer.
# Remove any stacked volumes like cache first.
pvcreate /dev/disk1 /dev/disk2 /dev/disk3
vgextend VG /dev/disk1 /dev/disk2 /dev/disk3
lvconvert --type raid6 --stripes 4 VG/LV
Converts a RAID5 logical volume to RAID6 within the volume group VG
, adjusting the number of stripes according to the total disks minus two.
lvconvert --type linear VG/LV
Converts a RAID-configured logical volume to a linear layout, removing any RAID functionality.
lvs -a -o name,copy_percent,devices
Displays the conversion progress and status of logical volumes within a volume group.
lvconvert --repair VG/LV
Repairs or replaces failed devices within a mirror or RAID logical volume.
lvchange --syncaction check VG/LV
lvchange --syncaction repair VG/LV
Initiates a background synchronization operation on the logical volume, with options to check or repair the array.
lvs -o +raid_sync_action,raid_mismatch_count VG/LV
Displays detailed information about the ongoing scrubbing operation, including sync actions and mismatch counts.