LVM Commands and Device Mapper

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Time
21 hours 25 minutes
Difficulty
Intermediate
CEU/CPE
21
Video Transcription
00:00
>> Hello Cybrarians.
00:00
Welcome back to the Linux plus course here at Cybrary.
00:00
I'm your instructor Rob Gills
00:00
and in today's lesson we're going to
00:00
be discussing LVM commands and device mapper.
00:00
Upon completion of today's lesson,
00:00
you'll be able to use the LVM commands
00:00
that we talked about in the previous lesson,
00:00
we're also going to look at dev mapper content,
00:00
the device mapper content.
00:00
Let's get going with some demo time.
00:00
Here we are in our CentOS environment.
00:00
Full disclosure I did a little bit of
00:00
clean up since we were last over here.
00:00
If we do an ls on dev and
00:00
>> then we just look for sd star,
00:00
>> we use the [inaudible] the asterisk.
00:00
We can see that we no longer have
00:00
the sdb1 and sdb2 partitions.
00:00
We just have dev sdb,
00:00
and I've also added another disk device, dev sdc.
00:00
We're going to use the two devices in
00:00
order to create an lvm, a logical volume.
00:00
Let's get started with creating physical volumes.
00:00
We'll do this with sudo and in fact,
00:00
let's just become root using sudo.
00:00
We'll do sudo bash.
00:00
The reason for this is because we have to constantly
00:00
remember to type this command when
00:00
we're working with disks,
00:00
and for the purposes of expediency
00:00
and minimizing errors I'm just going to become root.
00:00
Normally I would recommend that you use sudo,
00:00
but in this case we're just going to become root.
00:00
The first thing we're going to do
00:00
>> is we're going to type
00:00
>> pv create and we're going to
00:00
specify that we want to use dev sdb and
00:00
dev sdc as the two devices
00:00
that we're going to add into our physical volume.
00:00
Once we've done that, we can see that these were
00:00
successfully created as physical volumes.
00:00
We can see this if we run the pv display command.
00:00
That will display what happened with these two devices.
00:00
We can see that dev sdb is a new physical volume
00:00
of eight gigs and the same thing is true of dev sdc.
00:00
We see right here dev sdc is
00:00
a physical volume of eight gigs and so is dev sdb.
00:00
Now what we need to do in order
00:00
to create our logical volume,
00:00
the next step we need to do is to
00:00
>> create a volume group,
00:00
>> and we do that using the vg create command.
00:00
Now we're going to give this a name vg1,
00:00
and we're going to add the two devices,
00:00
dev sdb and dev sdc,
00:00
which are actually physical volumes at this point.
00:00
We can add these in and
00:00
hit "Enter" and now we'll see that
00:00
the volume group BG1 is successfully created.
00:00
Now in order to display this,
00:00
we can run the vg display command.
00:00
Are you getting a sense of the rhythm here?
00:00
Pv create, pv display,
00:00
vg create, vg display,
00:00
and so on and so forth.
00:00
Now if we hit "Enter", we can see that we
00:00
have a volume group, vg1.
00:00
It's a format of lvm2, rewrite,
00:00
and it is 15.99 gigs in size.
00:00
It's just a hair under the two eight gigs,
00:00
so it would be 16 gigs total.
00:00
That's just because of formatting overhead
00:00
and creating it into a volume group.
00:00
Now what we can do that we have
00:00
our physical volume setup as number one and number two,
00:00
we have our volume group setup,
00:00
we can create the logical volume
00:00
using the lv create command.
00:00
The way that we do this is we type lv create and we
00:00
give it a name with the dash n option,
00:00
and we're going to call this lv1.
00:00
We're going to use the dash capital
00:00
L option to specify the size,
00:00
we'll make this a one gig partition,
00:00
and we're also going to need to specify
00:00
the volume group that we're creating
00:00
the logical volume from.
00:00
The very last thing we need to specify is
00:00
our volume group name, which is vg1.
00:00
Then if we hit "Enter", we can see that
00:00
the logical volume lv1 has been created.
00:00
Then just like we saw with pv display and vg display,
00:00
we can also run an lv display.
00:00
That will display the output about
00:00
the information related to what we
00:00
just created and we see that this is in dev vg lv1.
00:00
The lv name is lv1 is associated with
00:00
a volume group vg1 and so on and so forth.
00:00
Now, let's take a look at how this is
00:00
actually set up in device mapper.
00:00
Let's do an ls dash al on dev vg1,
00:00
lv1, which is what we see right up here, the lv path.
00:00
If we hit "Enter", we see that this is actually
00:00
a pointer to dm0,
00:00
and dm0 is the lvm entry for the first logical volume.
00:00
If we were to do an ls al on dev mapper,
00:00
we can also see that vglv1 points to dm0.
00:00
If we are actually to go up to that directory,
00:00
we can see the dm0 directory.
00:00
In dev dm star we'll see dm0.
00:00
Really all that these lvm devices set up in
00:00
dev mapper do is point to another device file,
00:00
the dm0 device file.
00:00
Guess what, if we were to go and run
00:00
an lv create command,
00:00
and let's just say we want to
00:00
create a second logical volume,
00:00
we'll call it lv2,
00:00
what do you think happens?
00:00
Well, what happens is we actually end up with
00:00
a second logical volume and its name will be dm1,
00:00
so dm0 and dm1.
00:00
That's how you work with logical volumes in
00:00
device mapper and how they all get linked together.
00:00
Now next we're going to move on to
00:00
creating ray devices using mdadm.
00:00
However, before we do this we need to
00:00
remove lvms we created.
00:00
Well, how do you think that we do this?
00:00
Well, just like we saw create and display,
00:00
we also have remove commands that are
00:00
used to remove logical volumes,
00:00
volume groups, and physical volumes.
00:00
We can run lv remove.
00:00
We're going to specify first the volume group,
00:00
volume group one,
00:00
>> and then we'll specify logical volume two.
00:00
>> That'll remove that regular active logical volume.
00:00
Now we can do the same thing.
00:00
I just hit the up arrow by
00:00
the way to get back my history.
00:00
I went back to the previous history,
00:00
I removed lv2 and I just put
00:00
in one and we can remove lv1 as well.
00:00
Now that we've removed those,
00:00
we need to remove our volume group.
00:00
Well, we do that with a vg remove command,
00:00
so vg remove vg one.
00:00
That is successfully removed as well.
00:00
Now the last thing we need to do is remove
00:00
the physical volumes because we're going to
00:00
reuse these devices to create our raid.
00:00
We're going to remove dev sdb and dev sdc.
00:00
Pv remove dev sdb and dev sdc and hit "Enter".
00:00
Now we can see that the labels on
00:00
the physical volumes have been successfully wiped,
00:00
they're ready and able to be used again.
00:00
Let's take a look at what we see though in dev mapper.
00:00
If we go back into dev mapper,
00:00
>> what do you think we see?
00:00
>> Well, we see basically absolutely nothing.
00:00
Our dm devices,
00:00
our device mapper devices,
00:00
dm0, dm1 are gone.
00:00
If we go up to our dev directory,
00:00
so you do an ls al on dev dm star,
00:00
>> we don't see anything.
00:00
>> There's no such file in
00:00
our directory, it's been removed.
00:00
That's how we know we're clear and
00:00
ready to move forward with our next lesson.
00:00
We've reached the end of today's lesson.
00:00
In this lesson, we covered creating,
00:00
displaying, and removing logical volumes.
00:00
We also looked at the resulting dev mapper files
00:00
that are created when you set up a logical volume.
00:00
But that's it for this lesson.
00:00
Thank you so much for being here and I
00:00
look forward to seeing you in the next lesson.
Up Next