In this lesson, you will learn about the Logical Volume Manager.
In this video, I'll tell you about the different components that you are using in LVM.
In the heart of LVM is a volume group.
And this volume group is an abstraction of all the storage that you want to put in your
LVM configuration.
You do that by using the so-called PV, the physical volumes.
And these physical volumes can be hard disks, it can be partitions, it can be any valid
block device.
And that is allowing you for flexibility.
If you run out of disk space on your volume group, you can easily add more storage by
adding PVs.
Now from the volume group, you are going to create your logical volumes.
And these are the storage devices on which you are going to use your file systems.
So your MKFS is happening here.
And a nice thing is that these logical volumes get their disk space from the volume group,
but they are not aware and there is no strict relation.
And that means that if your logical volume runs out of disk space, you just go get more
disk space from the volume group.
And if in the volume group, there is no additional disk space available, well, you are just going
to add another storage device right here as a PV.
And that is what implements the flexibility in an LVM environment.
So let's summarize the procedure for creating LVM.
First, you need to create a partition.
And this partition needs to be set to the appropriate type, which is 8E on MBR, 8E00
on GPT.
Or when you use modern utilities, you can use LVM, which is an alias to the correct
partition type.
Then you use pvcreate on your device to mark the partition as a physical volume.
And next, vgcreate, you give the volume group a name and you add a physical volume into
it.
DevNNN, that corresponds to the partition that you have just created as an LVM type
partition.
Oh, and by the way, if you are wondering, do we need to create a partition?
No, you can also put an entire disk in LVM, but it's nicer for administration purposes
to do partitions, because they are clearly marked as an LVM partition type.
Once you have your volume group, you can create logical volumes from it.
So lvcreate minus uppercase L1G will create a one gigabyte volume.
Minus N, LVName will use the name LVName, and vgname will put it in the volume group
that you have created.
And that will create a one gigabyte volume in that group.
And then you can use pvs, vgs, lvs, or pvdisplay, vgdisplay, lvdisplay to verify.
The display commands are giving a little bit more information, the pvs and so on commands
are giving a short list.
And once you are done, you can mount it using dev vgname LVName, or using the device mapper
name that is used behind it, which is slash dev slash mapper slash vgname dash LVName.
Let me show you how to set up a simple LVM environment.
So I'm going to start with lsblk, because in order to set up LVM, we need a block device.
And I need to analyze and determine what I've got.
Well, I'm going to use dev nvme0n2, on which we have sufficient space available.
So I'm going for my favorite utility, and that is fdisk on dev nvme0n2.
And there, you can ignore the message that you see here.
This is just to scare people away that don't know what they're doing.
But you know what you're doing, right?
So I'm going to use n for a new partition.
The new partition will be partition number four.
And first sector, well, I'm not even going to think about it.
I'm just accepting the default.
And last sector, let's make this a four gigabyte partition, plus 4g.
There, we can see that the new partition is created of the type Linux file system.
Well, that is what I need to change.
So I'm using T to change the partition type.
And for partition number four, I'm setting the partition type to LVM.
And now I'm using P to verify that partition four was correctly set as LVM.
It is, so I can use W to write and exit.
As always, it's a good idea to verify your storage using lsblk.
And there, we can see that we have an NVMe 0n2p4 partition.
That's the one that I just created.
So I'm going to use pvcreate on dev NVMe 0n2p4, which will mark it as a physical volume.
That will make it usable by LVM.
Next, I can use vgcreate.
I'm calling it vgdata.
And I'm putting in my device NVMe 0n2p4.
And that is telling me that the volume group was successfully created.
Well, that was easy.
Now, lvcreate minus l1g.
I want a 1 gigabyte logical volume minus n lvdata.
And I need to do that in vgdata.
And as you can see, the logical volume lvdata was created.
Good.
Now, I can use lvs.
And there, we can see that lvdata is indeed correctly created with a size of 1 gigabyte.
Now, the fun fact is that the logical volume has two different names.
When I use ls minus l on dev vgdata lvdata, I can see that that is one name pointing to a device DM2.
That's a symbolic link to the device mapper device.
Device mapper is a system that is used behind LVM.
And here, we can see the name of that device.
And when I use ls minus l on dev mapper, you can see that right in there, we have vgdata lvdata pointing to the same device.
And it doesn't matter at all which one of these names you are using.
Now, let's verify.
LVS is showing all my logical volumes.
VGS is showing all my volume groups.
We should be good here.
We just created the LVM logical volume.