Linux Logical Volume Management (LVM)

This article was first written in December 2003 for
the BeezNest technical website (http://glasnost.beeznest.org/articles/99)
LVM [1] is a great system to resize filesystems and partitions online [2], do online snapshots of the filesystems, span filesystems and partitions on multiple drives. It is the ultimate solution to the disk space allocation nightmare. Linux's LVM is closely inspired by HP-UX, which provided the technology to AIX also. They share almost the same schemes, functionalities and names for tools and everything else.

Terminology

You will need some knowledge of the terminology of an LVM before using it; all Volume Managers use a same basic principles but use sometimes different names. Volume Group is a "container" that holds physical disks and logical volumes. It's wise to only have two volume groups, a VGROOT and a VGDATA. AIX calls it a diskgroup, since it holds physical disks as well as logical volumes. Example: /dev/datavg/var Physical Volume is in fact a slice or partition. These devices are the building blocks for a volume group. Example: /dev/hdb1 Logical Volume is a part of a volume group. The logical volume will be supplied with a file system and then can be mounted. You can also keep logical volumes 'RAW' and assign them to an Oracle system for example. Physical Extend (PE) A logical volume can be extended or shrunk with a certain amount of PE's. In AIX this is known as PP. Always be careful with shrinking volumes! Do not shrink a volume thoo much that it lands into your filesystem; your filesystem will be immediately an irreversibly useless. Also notice that most filesystems can grow but not all of them can shrink.

HOWTO

The reference document in this respect is the LVM HOWTO. Here is how to use LVM on a Debian Woody, for non-root filesystems (it is not hard to adapt, though): Install the needed packages
$ sudo apt-get install lvm10
Prepare the system
# vgscan
Create the LVM partition container
# cfdisk /dev/hda
Use 8E(LVM) as partition type code. Create the Physical Volume
# pvcreate /dev/hda4
Create and activate the Volume Group(s)
# vgcreate my_volume_group_name /dev/hda4
# vgchange -a y my_volume_group_name

Create the Logical Volumes

to be continued…
[1] Kernel 2.6 calls it Device-Mapper instead of LVM [2] read: while programs are running on it