In this lesson, we're going to walk through
how to manage logical volumes.
So, up to this point,
we'll work directly with the physical devices.
However, there's a way to further abstract these items
and use them in a more efficient way.
Linux uses a process called device mapping
to help us accomplish this.
In Linux, device mapper creates the virtual devices
and passes data from that virtual device
to one or more physical devices.
One major application of the device mapper
is the Logical Volume Manager.
If you recall when we configured our virtual machines,
the storage option was defaulted for us to use LVM.
LVM maps whole physical devices and partitions
into one or more virtual containers
called volume groups.
Within these volume groups are one or more logical volumes.
Ultimately, the logical volumes become the storage devices
that the system, user, and the applications
will end up working with.
So, first thing we want to do, let's identify
the current logical volumes that's on the system now.
We'll do /dev/mapper.
Again, from when we created the virtual machine,
we see that the system created centos-root and centos-swap.
Those are the logical volumes
that we currently have on the system.
Now, what we're going to do is we're going to scan the system
for the current physical volumes,
volume groups, and logical volumes.
There's commands for those.
Scan here.
See we have one from the creation with CentOS?
We're going to use the pvdisplay command.
That's going to also show us
a little bit more detailed information
about the physical volumes that are currently on the system.
Remember, the physical volumes are ones
that has been identified and associated
with the device mapper.
You want to do the same thing, vgscan.
See the volume groups that's currently created,
only the CentOS.
Then, I'm going to do the display.
Again, showing us more information about the volume groups
that are currently on the system.
Last one will be the logical volume scan.
Once more, logical volume display.
Give us, again, more detailed information
about the current logical volumes
that are associated with the system.
Now, we're going to hop right into creating
the physical volumes.
'Cause remember, we're going to layer this.
So we're going to start with the physical volumes,
then we're going to move to the volume groups,
and then last the logical volumes.
So let's start creating the physical volumes.
So we want to do pvcreate.
We want to use the hard disk that we used earlier
that were partitioned.
Sdb2.
I partitioned these earlier.
All right, looks like it's successfully created.
Now, let's just verify that, pvdisplay.
And now, we see we have the new physical volumes.
Next, we're going to create a volume group
from the physical volumes that we just created.
New volume group create, going to need the backup.
Going to use ones we just created,
sdb1,
/dev/sdb2.
All right, so we have the volume group successfully created,
so let's display that here.
Do the quick one, the scan,
and then we can also do the display command.
All right, we see that it's created.
The last thing we want to do is create three logical volumes
to associate it with the new volume group.
lvcreate.
Create the name here.
Going to do a system backup.
Size,
just going to give 'em all
two gigabytes for now.
And we're going to associate it with the backup volume group.
Yep, going to accept this warning.
All right, looks like that was successfully created.
Going to do one more.
Going to change the name to the data backup
Created one more for the log.
Wipe it.
Okay.
Now let's do a scan,
and now we can see they we're all successfully created.
Sometimes it will be necessary to extend
or reduce the volume size
and to do this you want to simply use
the lvextend
and the -l option,
this is what the new size is going to be.
So we're going to extend the data backup to three gigabytes.
Okay?
Dev,
data backup.
All right, looks like that went through.
Next, we want to reduce the log backup file.
So we'll do
reduce again.
Want to reduce it to one gig.
Device backup.
Log back.
All right, we'll accept the warning here,
and we'll see it successfully changed from two to one.
So let's just verify this really quick.
Do
display,
and now we can see that the log backup is one gigabyte
and the data backup is three gigabytes now.
The last thing we want to do is
to create a file system on these volumes
that we just created.
So we'll do make file system, use .xfs for the first one.
Dev,
for the /systemback
Okay, that went through successfully.
Going to make a file system using .ext4.
Going to use that for the data backup.
Data backup.
Okay, that's went through successfully.
We'll do the same thing for the log system.
So we're going to scroll up, change this to log.
And looks like that went through as well.
So to summarize, we went through creating fiscal volumes,
volume groups, and logical volumes.
We also created file systems on those volumes
and now we can use them just
like they were a regular hard disc.
And I'll see you in the next lesson.