In recent months, I have been boasting about how much Linux has grown in its recent versions. Well, it's true. We now have journaling, we have clusters, and we have very nice SMP scaling. It's all in there. One more feature that should convince even die-hard anti-Linux folks is the Linux Logical Volume Manager, or LVM in short.
This article is going to describe the features and possibilities of LVM and show how to use it in general terms. For an in-depth coverage of LVM along with file systems and everything file I/O related, wait for my upcoming book Linux File Systems by McGraw-Hill, to be published in October this year.
The LVM set of drivers/programs and documentation was written by a team of developers with a website at http://linux.msede.com/lvm/. As usual hundreds of people all over the Internet contributed. Among the best known developers were people like Andrea Arcangeli from SuSE (see my March 6, 2000 interview with him here at Byte), Michael Marxmeier, Andy Bakun, Steve Brueggeman, and others.
The goal of the LVM project was to implement a flexible, virtual-disk subsystem to handle disk storage and online allocation and extension/shrinking of said storage.
Historically, a partition size is static. This requires a system installer to have to consider not the question of "how much data will I store on this partition," but rather "how much data will I ever store on this partition." When a user runs out of space on a partition, they either have to re-partition (which may involve an entire operating system reload) or use symbolic links.
The notion that a partition was a sequential series of blocks on a physical disc has since evolved. Most Unix-like systems now have the ability to break up physical discs into some number of units. Storage units from multiple drives can be pooled into a "logical volume," where they can be allocated to partitions. Additionally, units can be added or removed from partitions as space requirements change. This is what an LVM is good for.
Why is that necessary?
Because now, in a Linux server you typically find between 3 and 10, or even 50 or 60 disks. From a hardware perspective, with SCSI channels and separate disk cabinets it's certainly possible. I know of one installation in Israel doing genetic research that has Linux servers with as many as 90 disks online.
Managing that many disks and their partitions is not easy. Also, you as a Linux sysadmin surely have encountered situations where one of the file systems was approaching 100 percent space occupation and you wished you could just magically extend the partition. Well, with LVM it's not only possible, it is quite easy to do so.
What LVM does is add an additional layer between the physical peripherals and the I/O interface in the kernel to get a logical view of disks. This lets the concatenation of several disks (physical volumes or PVs) form a storage pool (volume group or VG, also known as volg) with allocation units called physical extents (called PE).
Parts out of these volume groups then can be allocated in the form of logical volumes or lvols in units called logical extents or LEs. Each logical extent is mapped to a corresponding physical extent of equal size. These physical extents are mapped to offsets and blocks on the disk(s).
The logical volumes can then be used through device special files similar to /dev/sd[a-z]* or /dev/hd[a-z]* named /dev/VolumeGroupName/LogicalVolumeName.
Because the disks and partitions (volume groups/logical volumes) are a virtual representation of the hardware, you can easily extend or shrink the logical volume, even at run-time.
How does LVM work internally to achieve this functionality?