So friends, let's talk about another story solution, this one known as LVM, Log
ical Volume
Management. This happens to be one of my favourite technologies in all of Linux
, so let's just dive
in. So, you know the problem with storage, everyone wants more storage no
matter how much you buy,
eventually you always seem to run out. So the question is, is that when we
happen to run out,
how do we address that particular problem? Well, very often what you might do
is just go and,
you know, buy more storage that might be an external hard drive, maybe it's a WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
you know, buy more storage that might be an external hard drive, maybe it's a
USB pin,
whatever it may be. Who knows, maybe you need a ton of storage and you go and
buy a massive server.
Now all of these are certainly viable options, they definitely do work, they
will solve your problem,
but is it the most efficient way to go about solving that particular problem?
Let me give you a
simple example, let's maybe say in your home you happen to have a spare drive
that happens to have
50 gigabytes on it. Now for whatever reason, you maybe need an additional 100 WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
50 gigabytes on it. Now for whatever reason, you maybe need an additional 100
gig of storage,
so as it stands right now, this particular storage device is not going to be
good enough
to handle the request or the requirement should I say of the 100 gig. So the
temptation might be to
think that the 50 gigabyte one is useless and what you might have to do is to
go and buy a brand
new fresh 100 gig bit of storage via an external hard drive via a USB whatever
it may be. Now what
if I told you that even though the 50 gig by itself is not sufficient to cover WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
if I told you that even though the 50 gig by itself is not sufficient to cover
all your storage
needs, but it can be used in conjunction to support that particular solution
that you're looking for?
Well, I'm actually hinting at the use of LVM because that is going to allow us
to make use of
disparate physical storage devices and effectively aggregate them and it is
this type of aggregation
that is going to allow us to make use of in the example we just saw the 50 gig
abyte storage device
that would ultimately be rather useless. So you're now here that you can make WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
that would ultimately be rather useless. So you're now here that you can make
use of these old
storage devices. You go rummaging through your house and you find even more old
storage devices.
So like I say you have your 50 gig storage device, maybe you find three more 10
gigabyte
ones. So in reality what we actually have here is a total of 80 gig of storage
space that is not
being used. So as opposed to having to go out and buy one contiguous block of
100 gig storage space,
what if we just jump out and buy a fairly cheap 20 gig storage device? WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
what if we just jump out and buy a fairly cheap 20 gig storage device?
Certainly more
but cheaper than the 100 gig and all we will do is we will use this new
purchase in conjunction
with remaining 80 gig storage that we just found laying about the house. So
like I have hinted
that this is all going to be enabled via logical volume management but we have
to understand the
constituent concepts that make up the LVM architecture. Now the first concept
we have to
understand is something known as a PV otherwise known as a physical volume. Now WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
understand is something known as a PV otherwise known as a physical volume. Now
the PV's are the
actual physical discs that we're going to use for storage. So in my case here
my 50 gig storage
device would become an LVM physical volume. Same with the 310 gig and the newly
purchased 20 gig
storage device they would all be my physical volumes. That's the first concept
in the architecture.
The next concept is the VG. This is known as the volume group. Now the volume
group is quite
simply the aggregation of those physical volumes. So realistically the volume WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
simply the aggregation of those physical volumes. So realistically the volume
group is going to be
the combined result of the physical volumes grouped together. It's going to
give us one big logical
blob of storage. So imagine it like this. Here is our 50 gig storage device,
here is our 20 gig
storage device and then we have our 310 gig storage devices. Individually they
are all physical volumes
but via the technology of LVM logically what they become is this big contiguous
chunk of storage WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
chunk of storage
at 100 gig. That would be the volume group. Now that is just two components of
the architecture.
We have one more component we have to understand and that is how we are going
to effectively subdivide
this volume group because just because we have aggregated these physical discs.
And to one big blob doesn't mean we have to use it as one big blob we can
logically subdivide
this into many smaller chunks. We could effectively chop it up into equal sizes
if we so wish.
Let's say we wanted to quarter it. Then we could have four equally sized WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
Let's say we wanted to quarter it. Then we could have four equally sized
partitions made up of all
of these asymmetric physical volumes. A 50 and a 20 and a 10 10 10 suddenly
been able to be subdivided
into 425 gig partitions. These particular partitions carved out of the volume
group would be the
logical volumes. Now one thing to note is that we don't actually have to subdiv
ide these in a
symmetric manner. What we could do is I could maybe create one partition space
of 75 gig and then WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
of 75 gig and then
for the remaining 25 gig I could create another partition which is only 10 in
size and another
which is 15 in size. Now we effectively have three partitions of varying size
of carved out from
the 100 gigabyte volume group. This is the type of flexibility that we get with
LVM.
So with that primer out the way let's dive in and begin it seeing how we can
automate this
particular process. So if you search for the Ansible LVM module if we click
this link right here once WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
this link right here once
again this is going to be part of the Ansible Community General module
collection. And notice
here what this particular module does it allows you to create remove or resize
volume groups that
has our VGs. So once again you can go through all of the particular parameters
to see how we can
actually use this particular option. Notice we have this PVS option here. And
this allows us to
specify which physical volumes i.e. which actual disks should be combined to
make the volume group.
And this is going to be accepted in the form of a list comprising of strings. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
And this is going to be accepted in the form of a list comprising of strings.
Notice the very
important option here specifying VG. This is a require parameter and this is
going to be the name
of the volume group. So here is what I'm going to do. I'm first going to shut
down my blue box
right now. I'm going to add in some new devices once again. So I'll go to my
options here. Click
settings. I'm going to go to hard disk and then I will choose add a device and
I'll choose a new
hard disk and then select add. I'm going to give this one a size of let's maybe WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
hard disk and then select add. I'm going to give this one a size of let's maybe
say 3GB and I will
choose apply. If I go back to show all I can choose hard disk again. Select add
a device. Choose
another new hard disk. Add it. And let's just maybe make this one 4GB so it's a
little bit different
okay. So let's apply this to kill. So if I parallel this back on again give it
a moment to boot up.
So now if I log into this device. So if I just say so though parted dash L and
type in the password
for the user. As we can see we have dev NVMe 0n3. We have the actual size right
here. And if I
just scroll on up a little bit further we can actually see NVMe 0n4 which has a WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
just scroll on up a little bit further we can actually see NVMe 0n4 which has a
different storage
capacity. These are the two physical disks that I'm going to combine to make a
volume group.
So let's go back to my control machine here. So let's create a playbook called
play3.yml.
Going to insert mode have a three hyphens at the top give the playbook in name
as per usual.
I should call this play3lvmstuff. And all I'm going to do is I'll target the
blue box in this case
here but not actually added the devices for the yellow box. And in the case WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
here but not actually added the devices for the yellow box. And in the case
here I will just say
gather facts as false to keep things nice and fast. And now I'll begin defining
my task of the first
task. It's going to be create a vg. Now what we're going to use we're going to
use the community.general.lvg
module. And we're going to have to specify a few things. The first thing is I'm
going to say that
the state should be present. We have to specify the volume group name. I'll
just call this nugget
storage. And now I'll specify my physical volumes that are going to comprise of
the script. Now
remember it's going to be in the form of a list object. So here's my hyphen. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
remember it's going to be in the form of a list object. So here's my hyphen.
And the first disk
is going to be dev nvm3. And the second one is going to be dev nvm4. So with
that now done we
should be able to create a volume group. So I will say answerable play3.yml and
to enter.
Oh and I have a typo right here. Let me go in. That should be nvm3. But silly
there. Try that
entirely again. Switch these around. Write the changes. Arrow up and try again. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
entirely again. Switch these around. Write the changes. Arrow up and try again.
And this looks
a lot healthier. We have a change. So let's go here. Go back to the blue box.
If I just say
pseudo VGS, we can actually see the volume group that we have created. Check
this out. Nugget
storage. And we can see here the size is seven gig because we have one device
that comprises of
three gig storage. And another which comprises of four four and three gives us
that logical
grouping of seven gig storage space. Now right now we have a volume group. If
you want to subdivide WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
you want to subdivide
that into our logical volumes, we have another module to do so. So if you
search for answerable
elvall, this particular module here once again from the same collection, this
is going to allow
us to create remove or resize logical volumes. So once again, we can go through
all of the
particular options, we can specify the name of the logical volume. We have
options to resize
file systems, that type of thing. We can specify should the state be present or
absence. And notice
very crucially, we have this required parameter of VG, which is going to take a WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
very crucially, we have this required parameter of VG, which is going to take a
string. Pretty much
which volume group do we want to be carving up. Now one last thing, which is
obviously important
is the size of the logical volume. So we have our size parameter. And if we
scroll on down,
we can see some examples. So notice we can specify the size and units, i.e. we
can specify megabytes
in this case here, or the example below we can specify gigabytes. Or if we
switch, we can specify
the size as a percentage. One thing to note though, is if we happen to utilize
a percentage as the
size, the module is not going to act in an idempotent manner. So just be aware WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
size, the module is not going to act in an idempotent manner. So just be aware
of that if you choose
to use that particular option. So let's go and see how this actually looks then
. So what I will do
is I'll go into my play three dot yml. And I'm going to have another task here.
So let's give this a
name. And I'll just say create first logical volume, the module will be
community general, elvall,
I'll specify that the VG I'm going to be targeting is going to be the nugget
storage volume group.
And I'll specify the name of this logical volume is going to be, let's just
call it my first chunk. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
call it my first chunk.
Now specify the size of this logical volume. And let's say I want to create 512
meg. So if I just
happen to save this right here, and I run the playbook and to enter give it a
moment. As we can
see here, the volume group was already created, but we do have a change with
respect to the logical
volume. Let's go and inspect it. So we have our device, if I notice a pseudo V
GS type in my password.
Notice before the free space was pretty much seven gig. And now the free space
is now 6.5 gig. WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
is now 6.5 gig.
That's because if I now type the command pseudo LVS, we can actually see here I
have created a
logical volume called my first chunk carved out of the nugget storage volume
group of the size 512
meg. And if I wanted to create another chunk, what I could do is go back into
the playbook.
Let's give us a name. We'll just create second LV, use the same module specify
we want to carve
the next logical volume out of the same volume group. That is the nugget
storage. I specify this
logical volume here can be called, let's say my second bigger chunk. Okay. And WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
logical volume here can be called, let's say my second bigger chunk. Okay. And
this time the size
is going to be what do we have left? We've got 6.5 left. Let's maybe go for a
second volume of
4G. Okay. So let's save this and run the playbook. Notice we have item potency
on the first volume
that was just skipped. But the creation of the second volume that actually
invoked a change on
the device. So let's go back. Now if I say pseudo VGS, the free space is now
down to 2.5 gig. And if I WEBVTT X-TIMESTAMP-MAP=LOCAL:00:00:00.000,MPEGTS:900000
down to 2.5 gig. And if I
do pseudo LVS, notice we have a second logical volume once again carved out
from the same storage
chunk this time for gig and size.