LVM - Logical Volume Management

If you've ever wondered how you could rebuild the filesystem and disk parts of your computer without having to redo everything, LVM is the answer.

Explained most simply, LVM is what is used to allow your Linux operating system to access the hard drive partitions through a layer that is flexible enough to be changed without requiring changes to the structures actually stored on the disk.

You can do the following things with LVM:

This topic deserves more discussion which I will be adding shortly -BMC

Logical Volume Management is one way of virtualizing resources. See the discussion on Virtualization for more general information.

How LVM works

LVM consists of three manageable sections:

It is possible to combine drives and partitions in pretty much any way imaginable and treat them as a single drive or split them into virtual drives. The Physical Extents create managed sections that can be managed at the most basic layer. Think of it as virtual drive blocks. The Volume Groups create what are best thought of as virtual hard drives and at the last layer, the Logical Volumes are virtual partitions.

These separations give administrators the ability with Physical Volumes to move data between sets of blocks and to optimize those blocks without requiring modifications to the systems using them. Further with Volume Groups, the system can combine, do basic RAID, or split the physical extents into virtual drives. Finally, the Logical Volumes can be used as virtual partitions, but expanded or contracted to match the changing layer below.

Carving off some free space

Evaluating available space

# pvdisplay

 "/dev/sda7" is a new physical volume of "52.51 GiB"

 --- NEW Physical volume ---

 PV Name               /dev/sda7

 VG Name              

 PV Size               52.51 GiB

 Allocatable           NO

 PE Size               0  

 Total PE              0

 Free PE               0

 Allocated PE          0

 PV UUID               zTMnIW-1hq1-x9ly-NxFX-xof6-Mr4C-iP3Mrn

Note the PE Size. This is the size of the "Physical Extents" or physical sections assigned to this volume group. The Free PE are the physical extents that are available to be assigned to something new and by multiplying the space per extent by the numbers of extents, you can determine how much space is available to be assigned.

In this example, there are 52GB of unassigned space. 

To make that space available for use, it has to be assigned to a volume group.

 # vgcreate 52GLVM

Now you will see that the Volume Group name has it assigned:

# pvdisplay

  --- Physical volume ---

  PV Name               /dev/sda7

  VG Name               52GLVM

  PV Size               52.51 GiB / not usable 3.00 MiB

  Allocatable           yes

  PE Size               4.00 MiB

  Total PE              13441

  Free PE               13441

  Allocated PE          0

  PV UUID               zTMnIW-1hq1-x9ly-NxFX-xof6-Mr4C-iP3Mrn

To create a logical volume of 10GB carved out of volume group 52GLVM with a name of mylv:

lvcreate -L 10G -n mylv 52GLVM

Don't forget to activate the LVM:

# lvchange -a y /dev/52GLVM/mylv

Really short cut