LVM – Logical Volume Manager

by Mike on December 6, 2008

in Hardware

The LVM (Logical Volume Manager) is an abstract layer that envelops all of the hard drives and allows the kernel to access the filesystem as if it is a normal filesystem structure.  Normally, the kernel see s drive partitions and then the data structure that represents the filesystem on those partitions.  So for example, the kernel might see /dev/sda3 mounted as the /home partition.  Using LVM the partitions are used to create the physical volumes which in turn are added to the abstraction layer, the volume group.  From the group, the “partitions” are created.  They function as partitions but are really not partitions at all.  The administrator can then  manipulate the volumes, they act like partitions,  that are created.  This manipulation includes resizing the volumes when needed.  The LVM recognizes and manages volumes spanning several drives.    In addition physical devices can be added to the LVM.

Advantages of LVM
1. Multiple Drive Capability
You have the ability to create a LVM from multiple drives.  Or you can add a drive and then expand the LVM to include the newly added drive.  In the illustration you see that partitions from three separate drives; sda,sdb and sdc are used to create the volume group.

2. Re-sizable Volumes
Logical volumes can be extended or contracted to fit the needs of the user.

3. Disk Striping
Data can be striped across a number of drives to increase throughput.

4. Volume Mirroring
Volumes can be mirrored to provide redundancy much like a RAID 1.

5. Data Relocation
Data can be relocated on a new drive while the system is running.

6. Volume Snapshots
Volume snapshots provides a way to capture an image of the logical volume.

The LVM2 is the new version of LVM in the CentOS/RHEL 5 version.  The LVM2 provides more efficient use of metadata storage and redundancy, stronger recovery formatting, and atomic changes to the metadata.

Physical Volumes
The foundation for the LVM are the physical storage units in the terms of partitions or whole drives.  These are block devices that are initialized into physical volumes or PV.  When a PV is created a label is placed in the first 512-byte sector.  The label signifies the device as a LVM physical volume and contains a unique identifier (UUID) for the PV.  The other purpose of the label is to provide the information for ordering for bootup, store the size of the block device in bytes and it records where the LVM metadata will be stored.  The metadata for the LVM is stored by default in two locations, the beginning of the drive and at the end of the drive in case the metadata at the beginning of the drive is overwritten.

Extents

The physical volumes are divided into blocks of data known as physical extents.  When making the decision about the size of the physical extent be sure to take into account two things.  First, the extent size must be the same on the logical extents as the volume group.  In other words, you will not be able to alter the extent size, the size of an individual block of data, once it is set at the physical volume.  Second, in considering extent size is the size of the data you will be saving.  If you are saving large blocks of data, a larger extent size may be faster as fewer blocks will need to be accessed to access your data.  However, if you data is smaller, you may want to use smaller extents as the larger extents may waste space.

Volume Groups

The physical volumes are combined to create volume groups.  This pool of disk space then will provide the resources for logical volumes.  The disk space is divided into fixed-size units called extents.  These extents or chunks of disk space are the same size in both the volume group and the logical volumes.

Logical Volumes
The volume group is taken and then divided into the logical volumes that you want to create.  There are three types of logical volumes; linear, striped and mirrored.

Linear Volumes
The linear volume adds up the total of the physical volumes to create one larger unit.    In the example with a linear logical volume the total disk space is added together to create the one logical volume.

Linear logical volumes can also be divided up into a number of volumes of different sizes.  In the example, two volumes have been created instead of one, but it is still a linear logical volume.

Previous post:

Next post: