In this lesson, you will learn about 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
or 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 the 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 volume 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 the LSB OK, 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 NVMe
0N2, on which we have sufficient space available. So I'm going for my favorite utility, and that is
fdisk on dev NVMe 0N2. 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 0N2 P4 partition. That's the one that I just
created. So I'm going to use PV create on dev, NVMe 0N2 P4, which will mark it as a physical
volume. That will make it usable by LVM. Next, I can use VG create. I'm calling it VG data.
And I'm putting in my device, NVMe 0N2 P4. And that is telling me that the volume group
was successfully created. Well, that was easy. Now, LV create minus L1G. I want a one gigabyte
logical volume minus NLV data. And I need to do that in VG data. And as you can see, the logical
volume LV data was created. Good. Now, I can use LVS. And there, we can see that LV data is indeed
correctly created with a size of one gigabyte. Now, the fun fact is that the logical volume has
two different names. When I use LS minus L on dev VG data LV data, 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 VG data LV data 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.