Now again, we're still working on our AlmaLinux 8.5 system,
but we're going to take a look at LVM.
So we're going to be taking a look at our block device files,
which we're going to be using.
We'll be looking at creating our LVM structures,
and then extending those structures.
So come on, let's find that command line.
And here we are then.
Running lsblk block,
we can go through and see we've got loop0 and loop0p1 and loop0p2.
We know when we created those partitions,
they were flagged as in use by our LVM system,
so we can make use of them now with lvm.
We can begin by taking a look at our pvs.
Now here we can see that pvs is not found, so we don't have LVM installed.
This is a vagrant VirtualBox, and obviously,
they're not using logical volume management within their VirtualBox,
so let's go through then and add it.
So I'm running as root, I can run yum install,
and then lvm2 is the package that I want,
and we can go through and accept to install all of
the packages that are required.
Now this is obviously going to give me then my pvs command,
so if I go through now and relist my physical volumes,
well, obviously, we don't have any because we haven't created any.
It doesn't look at the partitions and the flags
we've used within our partitions,
we have to mark them as being in use by our logical volume system.
And we do that with the pvcreate command.
All it's really doing is adding a header through to the disk or the partition.
And if I go through and add it through to loop0p1,
we can see then that we now have a physical volume,
and that's going to show when we look in our PVS.
We should be able to then list it as an available physical volume.
However, this really is an optional step, as we'll see.
When I create a volume group,
I can specify to create our physical volume as we go through.
So yes, with PVS at the moment, I only have the one physical volume.
Now, obviously, we don't have any volume groups.
We haven't created any.
VGS will then show me my volume groups.
We can go through and create a volume group.
But in creating the volume group, I'm going to use my second partition.
I just want to demonstrate that if I use that second partition,
we will automatically enlist it as a physical volume.
So I'm using loop0p2, and I'm going to put on the ‑v switch for verbose,
so we'll actually see the physical volume being created.
So it wasn't marked as a physical volume.
The header now has been added, and our physical volume has been created,
along with the volume group.
So if I now run pvs, we can see then I've got two physical volumes.
Partition 2 is part of volume group 1,
but partition 1 is not part of any volume group at the moment.
VGS will show that I've got 1 physical volume enlisted,
and we've got 508 MB of free space.
Vgdisplay, and then the volume group will give me a little bit more information.
The physical extent size, the PE size,
can be used when I'm looking at creating logical
volumes if I use that lowercase l.
So we're just about ready for that, so let me clear the screen with CTRL+L,
and obviously if I do an lvs for scanning my logical volumes,
I don't have any.
So I'm going to go ahead and create myself a logical volume.
‑N is the name, so I'm just going to call it data.
We can go through and specify with minus and lowercase l,
we can specify the number of extents.
Now, I don't particularly know how many extents that we have available,
but if I go 100%FREE, I can use all of the free extents from volume group 1.
So now my logical volume is created, and I can use lvs,
and I can show then the logical volumes that I've got created.
If I use the lvs from vg1, if I had multiple volume groups,
I would display just those logical volumes in vg1,
so it's something worth knowing.
Now the logical volume becomes a block device,
so I can use mkfs.xfs to create an XFS file system.
I'm going to add it on dev/vg1/data.
When I take a look at this,
this is going to be a symbolic link through to a dev‑mapper device,
but it gives an easy way of having access through to the device.
When I do a long listing on Escape and dot to bring up my last argument,
we can see that it's a symbolic link through to the parent directory and dm‑0,
a dev‑mapper device.
I generally access them, though,
through the volume group directory because that's easy.
We can create ourselves a directory and then mount our
device through to that directory.
And with all of this done,
I'm going to copy across a few files just to show
that our file system can be live, and we're not going to lose any of our data.
So I'm going to look in the usr/share/doc where the name is,
then, let's say, html.
So we should have at least a couple of html documents.
And we can then go through and then ‑exec and cp the found
file through to our data directory and then Escape the
semicolon for our line ending.
If I then go through and list the data directory,
look at that, a glorious two web pages.
That will do for me.
We can see now our file system is live and in use.
Now, there are a few ways that we can go through and see its size.
We can use lvs, and we can see then it's size of 508 MB.
We can also go through and see that same information when I look at lvdisplay,
but with lvdisplay, we can then go through and see vg1/data,
and we can again go through and see it's 508 MB.
When we go through and take a look, though,
at the file system, so df ‑h /data, then again,
we can go through and see that we've got,
well, available 474 MB.
Now if we decided that we were getting low on disk space,
we can go through and extend our logical volume.
That space, though, has to come from our volume group.
If we look inside our volume group, we don't have any volume group free space.
So we can go through and extend by adding in another disk or partition.
So we can extend vg1 by adding in /dev/loopp0p1.
I'm not going to add in the ‑v switch.
We'd already created this as a physical volume.
But we can see with VGS now that we've got 2 physical volumes
and 1 logical volume and 508 MB free space.
We can now go through and extend our logical volumes, so vg1/data.
‑R will allow us to resize the file system if it's XFS or Ext4.
Using uppercase L, we're able to specify a target size,
so + to extend it by 500 MB, and then hit the big Enter key.
We can see the file system data showing,
so we have extended it,
and we're going to be able to then go through and take
a look back at our disk free space, and we can see then that whilst mounted,
whilst online, we're able then to extend the disk space.
So by using our logical volume management,
we can see how easy it is to add extra disk space when we require it, and that's why it is and has been so popular.