LVM: Overview

Tech Articles
LVM Commands
This article describes LVM and is intended for experienced LINUX users.
LVM

Introduction
LVM is used for managing disks on Linux computers. LVM creates volumes that are used by the operating system as if they were disks. The volumes themselves are built on physical storage such as disks. LVM allows the systems administrator to increase the size of a volume beyond the size of a disk and to reduce the size of a volume. LVM also allows for easier management of disk failures.

Physical volumes

Physical volumes are made up of the most intuitive components to storage: disks. Physical volumes can be:
  • Whole disks
  • Disk partitions
  • LUNs (Logical Unit Numbers) of an external storage device that is addressed by:
    • the SCSI protocol
    • one of the SAN (Storage Area Network) protocols which encapsulates SCSI (Fibre Channel or iSCSI)

LVM Physical Volumes have 4 sections:
  • First sector (not touched by LVM)
  • LVM Label (second sector by default, but can be any of first 4 sectors)
  • Metadata
  • Usable space

The LVM label:
  • contains the UUID (a random unique identifier) for the physical volume
  • stores the size of the block device in bytes
  • records where the LVM metadata will be stored on the device.

The LVM metadata
  • contains LVM configuration information
    •  specifically, LVM metadata is the details of the LVM volume groups on your system
  •  an identical copy of the metadata is maintained in every metadata area in every physical volume within the volume group
  • LVM metadata is small and stored as ASCII
  • LVM allows you to store identical copies of its metadata on each physical volume to help recover from accidental overwrites of the metadata
  • The first copy is stored at the start of the device, shortly after the label
  • If there is a second copy, it is placed at the end of the device

It is possible to use one or more disk partitions as a physical volume. However, this should be done as an exception.

The SA usually creates a single partition that covers the entire disk and labels that as an LVM physical volume.

It is easier to treat a disk as a single physical volume because:
  • Easier to replace a failed disk
  • LVM cannot tell that two physical volumes are on the same physical disk
  • This may lead to stripes could be on different partitions on the same disk
  • a striped logical volume when two physical volumes are on the same physical disk can result in a decrease in performance rather than an increase (striped logical volume are used to increase performance of large sequential reads and writes by reading/writing across multiple disks).


Volume Groups

Volume Groups are pools of disk space.
  • Volumes are created from Volume Groups
  • Volumes are logical devices. They are also referred to as abstractions because the operating system writes to the volume without knowing which disk the data is ultimately being written to.

Extent: the smallest unit of space that can be allocated
  • Extents are fixed sized
  • In RedHat’s documentation, the extents in the examples are 4 MB
  • Logical extents are the same size as the Physical extents they are mapped to
  • The volume group maps the logical extents to physical extents.


Logical Volumes

There are three types of LVM logical volumes:
  • Linear volumes
  • striped volumes
  • mirrored  volumes.

Linear Logical Volumes
A linear volume is made up of one or more physical volumes
  • For example, a 160 GB linear logical volume can be created from two 80 GB physical volumes
  • The physical volumes do not have to be the same size
  • We say: “The physical storage is concatenated”

Striped Logical Volumes

A striped logical volume writes the data across multiple underlying physical volumes.

When you write data to an LVM logical volume, the file system lays the data out across the underlying physical volumes. You can control the way the data is written to the physical volumes by creating a
striped logical volume. For large sequential reads and writes, this can improve the efficiency of the data I/O.

Striping enhances performance by writing data to a predetermined number of physical volumes in round-robin fashion. With striping, I/O can be done in parallel. In some situations, this can result in near-linear performance gain for each additional physical volume in the stripe.

Striped logical volumes can be extended by concatenating another set of devices onto the end of the first set. In order to extend a striped logical volume, however, there must be enough free space on the
underlying physical volumes that make up the volume group to support the stripe. For example, if you have a two-way stripe that uses up an entire volume group, adding a single physical volume to the volume group will not enable you to extend the stripe. Instead, you must add at least two physical volumes to the volume group. For more information on extending a striped volume,

Mirrored Logical Volumes

When you create a mirrored logical volume, LVM ensures that data written to an underlying physical volume is also written onto a separate physical volume. This is called mirroring. With LVM, you can create mirrored logical volumes with multiple mirrors. This provides protection for device failures.

When the disk used by one leg of a mirror fails, the data can still be accessed and the damaged disk can be replaced without losing data.

Suggestions for Future Learning
See the next page for examples of LVM commands.

RedHat has a nice document on LVM:



Tech Articles
LVM Commands