LOGICAL VOLUME MANAGER (LVM)

Logical Volume Management


Logical Volume Management is carried out by LVM the "Logical Volume Manager". LVM allows you to easily manage your disk space. LVM gives you the ability to add additional disk space to filesystems and move data from one partition to another.

Basically, LVM is split into 3 distinct layers. These are Physical Volumes (PV), Volume Groups (VG) and Logical Volumes (LV).

Physical Volumes (PV)

Physical Volumes are literally storage space. Generally these are partitions on either a local disk or a SAN attached device or even a loop back file. The storage space on a Physical Volume is divided into small units called Physical Extents (PE).

Volume Groups (VG)

Logical Volumes and Physical Volumes are grouped together into a Volume Group (VG)

Logical Volumes (LV)

Volume Groups are divided into Logical Volumes (LV).

LVM Basic Process

Each of the above three sections have specialized commands for managing/manipulating your storage requirements.

The basic order for creating a LVM managed system is to:

Assign Disk
Create a partition or partitions on this disk.

Create a Volume Group.
The Volume Group will contain your Physical Volumes (storage)

Create a Logical Volume(s).

Create a filesystem on your Logical Volume.

Create a mount point
The mount point is used for mounting your filesystem.

LVM Command Overview

Below are a list of the most commonly used command for working with Linux's LVM (Logical Volume Manager.

Physical Volume Commands

pvchange: Change attributes of a Physical Volume (PV)
pvcreate: Initialize a disk or partition for use with LVM
pvmove: Move Physical Extents
pvresize: Resize a disk partition utilised by LVM
pvscan: Scan all disks for Physical Partitions
pvck: Check Physical Volume metadata
pvdisplay: Display Physical Volume Information
pvremove: Remove a Physical Volume
pvs: Report Physical Volume Information

Volume Group Commands

vgcfgbackup: Backup a volume group descriptor area
vgconvert: Convert Volume Group metadata
vgextend: Add Physical Volumes to a Volume Group
vgmknodes: Recreate volume group directory and logical volume special files
vgs: Report information about volume groups
vgcfgrestore: Restore volume group descriptor area
vgcreate: Create a Volume Group
vgimport: Make exported volume groups known to the system
vgreduce: Reduce a volume group by removing one or more physical volumes
vgscan: Scan all disks for volume groups and rebuild cache
vgchange: Change attributes of a volume group
vgdisplay: Display Volume Group Information
vgimportclone: Import and rename duplicated volume group
vgremove: Remove a Volume Group
vgsplit: Split a volume group into two, moving any logical volumes from one volume group to another by moving entire physical volumes
vgck: Check volume Group metadata
vgexport: Make volume groups unknown to the system
vgmerge: Merge two Volume Groups
vgrename: Rename an existing Volume Group

Logical Volume Commands

lvchange: Change attributes of a logical volume
lvconvert: Convert a Logical Volume from linear to mirror or snapshot
lvcreate: Create a logical volume in an existing volume group
lvdisplay: Display attributes of a logical volume
lvextend: Extend the size of a logical volume
lvmchange: Change attributes of the logical volume manager
lvmdiskscan: Scan for all devices visible to LVM2
lvmdump: Create lvm2 information dumps for diagnostic purposes
lvreduce: Reduce the size of a logical volume
lvremove: Remove a logical volume
lvrename: Rename a logical volume
lvresize: Resize a logical volume
lvs: Report information about logical volumes
lvscan: Scan (all disks) for logical volumes

Make filesystem commands

mkfs: Make a filesystem of specified type
mkfs.ext2: Make an ext2 type filesystem
mkfs.ext3: Make an ext3 type filesystem
mkfs.ext4: Make an ext4 type filesystem
mkfs.xfs: Make an xfs type filesystem

LVM Examples

The easiest way to get an understanding of LVM is to create some basic examples using some of the commands from the lists above. In the following examples I have used VirtualBox, fdisk and a CentOS Linux Operating System. I also have provided an example of LVM using loop back devices.

LVM Example 01: In this example we will create a simple 2 disk scenario whereby we have a single volume group that spans two physical disks. Each disk will be 1GB in size.

LVM Example 02: In this example we will create a multi disk scenario. We will use commands to add and reduce space. Instead of using VirtualBox, we will create loopback devices. This will enable you to try out your LVM commands.

LVM Example 03 In this example, we will initially add a single disk to our LVM environment. Later we then add a second larger disk. We will then use the "pvmove" commands to migrate data from the smaller disk to the larger disk.

LVM Command Examples: In this section we will cover some of the frequently used LVM commands.

LVM Snapshots: LVM snapshots are used to take a point in time snapshot of a Logical Volume. These snapshots can then be used to roll-back your Logical Volume to its point in time state. Snapshots are a very powerful feature of LVM. In this example we take a snapshot copy of a Logical Volume and then make some changes to the original copy. We then revert the changes back with the "lvconvert --merge" command.