Logical Volume Manager (Linux)
From Wikipedia, the free encyclopedia
LVM is an implementation of a logical volume manager for the Linux kernel. It was originally written in 1998 by Heinz Mauelshagen, who based its design on that of the LVM in HP-UX.
The installers for the Fedora, SuSE and Debian distributions are LVM-aware and can install a bootable system with a root filesystem on an logical volume.
The LVM can:
- Resize volume groups online by absorbing new physical volumes (PV) or ejecting existing ones.
- Resize logical volumes online by concatenating extents onto them or truncating extents from them.
- Create read-only snapshots of logical volumes (LVM1).
- Create read-write snapshots of logical volumes (LVM2).
- Stripe whole or parts of logical volumes across multiple PVs, in a fashion similar to RAID0.
- Move online logical volumes between PVs.
- Split or merge volume groups in situ (as long as no logical volumes span the split). This can be useful when migrating whole logical volumes to or from offline storage.
It cannot:
- Mirror whole or parts of logical volumes, in a fashion similar to RAID1 or RAID5 mirroring of logical volumes. For this, it is recommended that one use the Linux software RAID driver to mirror the underlying PVs to achieve redundancy.
[edit] Implementation
LVM keeps a metadata header at the start of every PV, each of which is uniquely identified by a UUID. Each PV's header is a complete copy of the entire volume group's layout, including the UUIDs of all other PV, the UUIDs of all logical volumes and an allocation map of PEs to LEs.
In the 2.6-series Linux kernels, the LVM is implemented in terms of the device mapper, a block-level scheme for creating virtual block devices and mapping their contents onto other block devices. This minimizes the amount of the relatively hard-to-debug kernel code needed to implement the LVM and also allows its I/O redirection services to be shared with other volume managers (such as EVMS).
Any LVM-specific code is pushed out into its user-space tools. To bring a volume group online, for example, the "vgchange" tool:
- Searches for PVs in all available block devices.
- Parses the metadata header in each PV found.
- Computes the layouts of all visible volume groups.
- Loops over each logical volume in the volume group to be brought online and:
- Checks if the logical volume to be brought online has all its PVs visible.
- Creates a new, empty device mapping.
- Maps it (with the "linear" target) onto the data areas of the PVs the logical volume belongs to.
To move an online logical volume between PVs, the "pvmove" tool:
- Creates a new, empty device mapping for the destination.
- Applies the "mirror" target to the original and destination maps. The kernel will start the mirror in "degraded" mode and begin copying data from the original to the destination to bring it into sync.
- Replaces the original mapping with the destination when the mirror comes into sync, then destroys the original.
These device mapper operations take place transparently, without applications or filesystems being aware that their underlying storage is moving.