Logical Volume Manager (Linux)

From TBP Wiki
Revision as of 16:30, 20 March 2024 by Goldbolt (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

In Linux, Logical Volume Manager (LVM) is a device mapper framework that provides logical volume management for the Linux kernel. Most modern Linux distributions are LVM-aware to the point of being able to have their root file systems on a logical volume.

Heinz Mauelshagen wrote the original LVM code in 1998, when he was working at Sistina Software, taking its primary design guidelines from the HP-UX's volume manager.

Uses

LVM is used for the following purposes:

  • Creating single logical volumes of multiple physical volumes or entire hard disks (somewhat similar to RAID 0, but more similar to JBOD), allowing for dynamic volume resizing.
  • Managing large hard disk farms by allowing disks to be added and replaced without downtime or service disruption, in combination with hot swapping.
  • On small systems (like a desktop), instead of having to estimate at installation time how big a partition might need to be, LVM allows filesystems to be easily resized as needed.
  • Performing consistent backups by taking snapshots of the logical volumes.
  • Encrypting multiple physical partitions with one password.

LVM can be considered as a thin software layer on top of the hard disks and partitions, which creates an abstraction of continuity and ease-of-use for managing hard drive replacement, repartitioning and backup.

Creating an LVM Logical Volume on Three Disks

This command destroys all data on /dev/sda1, /dev/sdb1, and /dev/sdc1. This assumes these disks exist and are attached.

   pvcreate /dev/sda1 /dev/sdb1 /dev/sdc1

Create the a volume group that consists of the LVM physical volumes you have created. The following command creates the volume group vol_group_1.

   vgcreate vol_group_1 /dev/sda1 /dev/sdb1 /dev/sdc1

The command vgs can be used to view currently existing volume groups.

This creates the logical volume from the volume group which has been created. This next command creates the logical volume logical_volume_1 from the volume group vol_group_1. This will create a logical volume of 2gb from the volume group.

   lvcreate -L 2G -n logical_volume_1 vol_group_1

Now you can mkfs format the /dev/vol_group_1/logical_volume_1 and mount it.


Extend preexisting logical volume

To increase the overall size of a logical volume, identify the volume group with vgs. The following will resize vol_group_1 to X amount of gb. Replace X with the size required.

   lvextend -r -L XG /dev/vol_group_1/logical_volume_1