Linux LVM: I’m Already Falling Asleep

I have been working on a P2V of some Red Hat nodes and have been doing some Logcial Volume Management updates post conversion. I started thinking about how I wish someone had taught me about LVM when I was first starting out. The abstractness of the idea is a lot to take in, but like most things, once you do it a few times you will develop your own style and ways to remember. We are going to walk through creating an LVM with little insights that I hope help you pick up the concepts faster. What could be more fun. 😉

Its All About Abstraction

The four main components of LVM are:

  1. The physical storage devices themselves
  2. The physical volumes
  3. The volume group
  4. The logical volumes

Image Source

The Physical Devices and the Physical Volumes

This idea was the hardest part initially for me. The physical volume is something you create from the physical device.Its the first logical abstraction. Think of these hard drives as unaltered in anyway. Its a device seen by the OS. That’s it. You could create a partition, format that partition with a file system, and mount it. Instead, with LVM, we partition it in preparation for it to become a physical volume. Technically, you don’t have to partition the disk. You can create a physical volume using the whole disk. But it is best practice to partition the disk, according to the Linux documentation project (of which I’m a fan).

I’ll be partitioning three disks and creating physical volumes from the disks. The disks are /dev/sdb /dev/sdc and /dev/sdd. The command we will be using for partitioning is fdisk. The commands we will be using for physical volume creation are pvs: physical volume show and pvcreate: physical volume create.

Partitioning with defaults:

Physical volume creation with defaults:

The fruits of our labor:

Looking back a the picture above we are now on the light blue line.

The Volume Group

The volume group can be thought of as a pool. It is one logical resource. The logical volumes we create on it later are not aware of the physical volumes we created in the previous section. So in that way, I always think about the volume group as the middle man in this setup. This is also the cool part of LVM. We can add more physical disk/ physical volumes later and expand the volume group. Its the thing that gives LVM the ability to expand and shrink compared to traditional storage. I’ll be creating one volume group called volume_group. The commands we will be using for volume group creation are vgs: volume group show, vgcreate: volume group creation and vgdisplay to see details of the volume group.

Volume group creation with defaults:

Volume group details. Notice the VG size. It is the sum of our three disks:

The fruits of our labor:

Looking again at the picture above, we are on the darker blue line.

The Logical Volume

Now we will be carving up the volume group into logical volumes. These volumes, like traditional disks, will need to be formatted and mounted. The commands we will be using for logical volume creation are lvs: logical volume show and lvcreate: logical volume creation. I’ll be creating two logical volumes and naming them Logical_volume_1 and logical_volume_2.  I highlighted the volume_group in an effort to show how the command is creating the logical_volume_1 and logical_volume_2 from the “pool.”

Logical volume creation with defaults:

The fruits of our labor, two logical volumes from one volume group:

Looking back at the picture we are now on the pink line.

The filesystem and mount:

Now if you look in /dev you will find a device called the name of your volume group. For example mine is /dev/volume_group. We have arrived. We now have something we can format, mount and save files to.

Looking back on the picture we are now on the yellow line.

Wrapping Up:

So to summarize: Physical device —-> Physical Volume —-> Volume Group —-> Logical Volume —-> Filesystem Mount

Check out this post for more detail than you ever thought possible on a subject:

Setup Flexible Disk Storage with Logical Volume Management (LVM) in Linux – PART 1



One thought on “Linux LVM: I’m Already Falling Asleep”

Leave a Reply

Your email address will not be published. Required fields are marked *