LVM: an introductory guide to logical volumes

hard disks
Image courtesy of William Warby.

Logical Volume Management is easily one of the most important and useful tools in storage administration. With LVM you can easily move “partitions” (volumes) around your physical disk, have snapshots, even mirroring or live migrations across disks become possible.

Disclaimer: I take absolutely no responsibility for what you do following this tutorial, thus it is made only as a reference and for learning purpose.

LVM at a glance

Before we fire up the terminal, let’s take a look at the LVM structure. LVM is an abstraction layer, a way to provide higher-level functions using lower-level ones. This enables you to have much more flexibility and in the end a higher level of control over your disks. Let’s now define three important concept: PV, VG and LV.

  • Physical Volume: A physical volume is a device or a partition that will be used to support LVM.
  • Volume Group: A volume group is a group of one or more PV. VG can span across multiple PV.
  • Logical Volume: A logical volume is the final step of this chain, it acts as a partition to the file system. It belongs to a VG, and is physically stored on one of the PV of its VG.

We didn’t cover PE and LE, since they’re not fundamental to understand the basics of LVM. Feel free to learn about them after you’ve done some practice with it.

LVM-ization

Creating your very first LVM volume is really easy. The first step is to create a PV: a partition or an entire device. Remember: that space (and its data) will be lost upon creating a PV, so be warned to back up whatever you’re using. Done? In case of a whole disk:

In case of a partition use:

Of course replace X with the letter of the device you want to use and Y with the number of the partition. Once done it is time to create a VG do so by:

Replace NAME with the desired name of the volume group and use the device/partition you used in the precedent step. Once done, you’re practically done, you can now start creating and manipulating your LVs. To create one you just need to issue:

Replace SIZE with the desired size with a suffix e.g. 10G or 250M. Replace NAME with the desired volume name. Replace VOLUME_GROUP with the volume group you created before. That’s it, you’ve just create a LV that acts exactly like a partition, but is way more flexible. First, to access it you should seek /dev/VG_NAME/LV_NAME . Now let’s take a look at the most used commands associated with LVM.

Image courtesy of Docklandsboy.

Image courtesy of mark | marksei

The following two tabs change content below.
The IT guy with a little boredom look in his eyes, fond of computers since forever he now works as a freelancer in the IT and shares his experiences through this blog.

You may also like...