In this video, I will tell you how to create a logical volume.
So here is the procedure.
To start it, you need to create a partition and set the partition type to LVM.
Even if it's possible to add a complete disk for RHCSA, you should prepare starting with
a partition and using that partition in your LVM setup.
Then you use pvcreate on the partition that you just created to mark it as a physical
volume.
Next, you can use vgcreate followed by the name of the volume group that you want to
create and followed by the name of the storage device that you want to put in there.
You can put in one storage device, also multiple.
Once you have your volume group, you can use lvcreate followed by the name of the logical
volume and followed by the size that you want to add as well as the name of the volume group.
And that will create a logical volume for you.
And then you are ready to put a file system on it.
So use MKFS to create any file system that you want on your logical volume that is addressed
in the naming structure, slash depth, slash name of the VG, slash name of the LV.
And finally, obviously, you need to put it in etcfs step to mount it persistently.
While creating logical volumes, you might want to consider extents.
Extents are the elementary blocks of LVM allocations.
And you set the extent size while you are defining the volume group.
So it's a volume group property and not a logical volume property.
And all the logical volumes in the volume group will share the same extent size.
In order to set a non-standard extent size, you use the minus s parameter, like minus
s 8m, which will use extents with the size of 8 megabytes.
And all of the LVM logical volumes built from the volume group will use this exact
same extent size.
To check the extent size, as well as other properties on the volume group, you can use
VG display.
Now, let me show you how to set up a logical volume.
So to start the setup, we need to use LSBLK for list block devices, because we need to
start with the partition.
And I am going to continue on my NVMe disk 1, where we have five partitions.
I'm using fdisk on that exact disk, NVMe 0 and 1, to create a sixth partition.
As you know, the message in red can be ignored, because we know what we are doing.
So I'm just going to use n to create a new partition.
And the new partition number will be partition number 6.
Using the first sector, specifying the last sector, let's make it 2 gigabytes.
And then I've created the new partition.
And now that I'm here, I'm also creating another new partition, because we are going to need
this partition later.
So we better do it all at once.
So the partition number is 7.
And first sector and last sector, another 2-gig partition, so plus 2g.
And a quick P to print the current partitioning scheme.
And there we can see partition 6 and 7, which have the type Linux file system.
That needs to be changed.
So I'm using T to change it, first on partition number 6.
And I'm setting it to LVM.
And next, I need to use T again to change partition number 7 as well, sending it to
LVM.
And then P to print.
And here we can see all the different partitions and their properties, where you can see that
6 and 7 are set as Linux LVM.
Well, that's good.
So I can use W to write it.
And now I can use pvcreate on dev nvme0n1p6 to mark it as a physical volume.
So the physical volume has been successfully created.
I can verify that using pvs.
pvs is showing a list of all physical volumes.
And here we go.
We can see the pv, which is not a part of a vg.
Whereas the other pv that is a part of the default volume group that was used while setting
up, my new pv is not yet a part of a vg.
And that makes sense, because I still need to use vgcreate.
Let's call it vgdata, and let me put in dev nvme0n1p6.
And now pvs is showing that my pv is a part of the vg vgdata.
And vgs is showing more or less the same thing from a different perspective, this time from
the vg perspective.
As you can see, there's two gigs available in the volume group.
And that is amazing, because that's exactly what I need to create my logical volume.
So lvcreate, minus n, lvdata.
I like using minus n to give it a name, because otherwise it will get an automatically assigned
names.
And these automatically assigned names don't make sense.
Next I'm using minus l, 2g, and vgdata, because I want to create it in the vgdata volume group.
And oh boy, what do we get?
Well, we get volume group as insufficient free space.
That is for a simple reason, that when you create a volume group, one extent is used
for metadata.
So instead of making it 2g, I need to make it 2044m.
Or I can use minus lowercase, 511, to directly refer to the number of extents I want to use
in my logical volume.
Lvs is now showing that I have an lvdata that exists in the vgdata vg, with a size a little
bit smaller than two gigs.
And that's exactly what I wanted.
So it's time to use mkfs.
So let's do ext4 this time on dev vgdata lvdata.
And now I've created my file system, and it means that I can mount it.
So to complete the procedure, I'm going to put it in etcfs step.
Now where before we have always used UUIDs, if you are using logical volumes, you can
also use the logical volume name.
So that would be dev vgdata slash lvdata.
That is because the logical volume name is written to the device and doesn't change automatically.
Going to mount it on slash lvdata, file system type is ext4, and using defaults and 0 and
0.
And then that should do it.
So mount minus a is a quick test.
And oh no, mount minus a is complaining that lvdata does not exist.
That's because I'm trying to bypass systemd here.
If I would just reboot, then during the reboot, systemd is converting this logical volume,
and it will create the lvdata mount point automatically for me.
To facilitate that process, it's wise to use systemctl daemon reload, and that should take
care of it.
So does mount minus a work at this point?
No, it does not.
But if you reboot, then it should work.
So let me use lsblk.
As always, the best way to figure out what is going on.
And here you can see that during the reboot, systemd has automatically created the mount
point for me.
So the logical volume is now mounted.