1
00:00:00,000 --> 00:00:11,480
In this lesson, you will learn about Logical Volume Manager. In this video, I'll tell you

2
00:00:11,480 --> 00:00:18,040
about the different components that you are using in LVM. In the heart of LVM is a volume

3
00:00:18,040 --> 00:00:24,719
group. And this volume group is an abstraction of all the storage that you want to put in

4
00:00:24,719 --> 00:00:31,320
your LVM configuration. You do that by using the so-called PV, the physical volumes. And

5
00:00:31,320 --> 00:00:36,520
these physical volumes can be hard disks, it can be partitions, it can be any valid

6
00:00:36,520 --> 00:00:42,000
block device. And that is allowing you for flexibility. If you run out of disk space

7
00:00:42,000 --> 00:00:49,799
or your volume group, you can easily add more storage by adding PVs. Now from the volume

8
00:00:49,799 --> 00:00:56,680
group, you are going to create your logical volumes. And these are the storage devices

9
00:00:56,680 --> 00:01:04,599
on which you are going to use your file systems. So your MKFS is happening here. And the nice

10
00:01:04,599 --> 00:01:10,320
thing is that these logical volumes get their disk space from the volume group, but they

11
00:01:10,320 --> 00:01:14,480
are not aware and there is no strict relation. And that means that if your logical volume

12
00:01:14,480 --> 00:01:19,839
runs out of disk space, you just go get more disk space from the volume group. And if in

13
00:01:19,839 --> 00:01:24,239
the volume group, there is no additional disk space available, well, you are just going

14
00:01:24,239 --> 00:01:30,559
to add another storage device right here as a PV. And that is what implements the flexibility

15
00:01:30,559 --> 00:01:37,559
in an LVM environment. So let's summarize the procedure for creating LVM. First, you

16
00:01:37,559 --> 00:01:42,440
need to create a partition. And this partition needs to be set to the appropriate type, which

17
00:01:42,440 --> 00:01:50,639
is 8E on MBR, 8E00 on GPT. Or when you use modern utilities, you can use LVM, which is

18
00:01:50,639 --> 00:01:57,800
an alias to the correct partition type. Then you use PVCreate on your device to mark the

19
00:01:57,800 --> 00:02:04,440
partition as a physical volume. And next, VGCreate, you give the volume group a name

20
00:02:04,440 --> 00:02:09,880
and you add a physical volume into it, devNNN. That corresponds to the partition that you

21
00:02:09,960 --> 00:02:15,399
have just created as an LVM type partition. Oh, and by the way, if you are wondering,

22
00:02:15,399 --> 00:02:21,240
do we need to create a partition? No, you can also put an entire disk in LVM, but it's nicer

23
00:02:21,240 --> 00:02:26,600
for administration purposes to do partitions because they are clearly marked as an LVM

24
00:02:26,600 --> 00:02:33,479
partition type. Once you have your volume group, you can create logical volume from it. So LVCreate

25
00:02:33,479 --> 00:02:40,839
minus uppercase L1G will create a one gigabyte volume. Minus N, LVName will use the name

26
00:02:40,839 --> 00:02:46,199
LVName, and VGName will put it in the volume group that you have created. And that will create

27
00:02:46,199 --> 00:02:54,440
a one gigabyte volume in that group. And then you can use PVS, VGS, LVS, or PVDisplay, VGDisplay,

28
00:02:54,440 --> 00:02:59,880
LVDisplay to verify. The display commands are giving a little bit more information.

29
00:02:59,880 --> 00:03:06,039
The PVS and so on commands are giving a short list. And once you are done, you can mount it

30
00:03:06,039 --> 00:03:12,039
using dev VGName LVName, or using the device mapper name that is used behind it, which is

31
00:03:12,039 --> 00:03:19,080
slash dev slash mapper slash VGName dash LVName. Let me show you how to set up a simple LVM

32
00:03:19,080 --> 00:03:25,800
environment. So I'm going to start with the LSB OK, because in order to set up LVM, we need a

33
00:03:25,800 --> 00:03:33,080
block device. And I need to analyze and determine what I've got. Well, I'm going to use dev NVMe

34
00:03:33,080 --> 00:03:39,720
0N2, on which we have sufficient space available. So I'm going for my favorite utility, and that is

35
00:03:39,720 --> 00:03:48,119
fdisk on dev NVMe 0N2. And there, you can ignore the message that you see here. This is just to

36
00:03:48,119 --> 00:03:52,279
scare people away that don't know what they're doing. But you know what you're doing, right?

37
00:03:52,279 --> 00:03:58,039
So I'm going to use N for a new partition. The new partition will be partition number four.

38
00:03:58,039 --> 00:04:03,479
And first sector, well, I'm not even going to think about it. I'm just accepting the default.

39
00:04:03,479 --> 00:04:10,759
And last sector, let's make this a four gigabyte partition, plus 4G. There we can see that the new

40
00:04:10,759 --> 00:04:16,600
partition is created of the type Linux file system. Well, that is what I need to change. So I'm using

41
00:04:16,600 --> 00:04:23,640
T to change the partition type. And for partition number four, I'm setting the partition type to

42
00:04:23,640 --> 00:04:30,279
LVM. And now, I'm using P to verify that partition four was correctly set as LVM.

43
00:04:30,279 --> 00:04:37,720
It is, so I can use W to write and exit. As always, it's a good idea to verify your storage

44
00:04:37,720 --> 00:04:45,799
using LSBLK. And there, we can see that we have an NVMe 0N2 P4 partition. That's the one that I just

45
00:04:45,799 --> 00:04:55,959
created. So I'm going to use PV create on dev, NVMe 0N2 P4, which will mark it as a physical

46
00:04:55,959 --> 00:05:04,440
volume. That will make it usable by LVM. Next, I can use VG create. I'm calling it VG data.

47
00:05:04,440 --> 00:05:13,399
And I'm putting in my device, NVMe 0N2 P4. And that is telling me that the volume group

48
00:05:13,399 --> 00:05:22,279
was successfully created. Well, that was easy. Now, LV create minus L1G. I want a one gigabyte

49
00:05:22,279 --> 00:05:31,160
logical volume minus NLV data. And I need to do that in VG data. And as you can see, the logical

50
00:05:31,160 --> 00:05:39,320
volume LV data was created. Good. Now, I can use LVS. And there, we can see that LV data is indeed

51
00:05:39,320 --> 00:05:48,359
correctly created with a size of one gigabyte. Now, the fun fact is that the logical volume has

52
00:05:48,359 --> 00:05:58,200
two different names. When I use LS minus L on dev VG data LV data, I can see that that is one name

53
00:05:58,200 --> 00:06:04,200
pointing to a device DM2. That's a symbolic link to the device mapper device. Device mapper is

54
00:06:04,200 --> 00:06:09,799
a system that is used behind LVM. And here, we can see the name of that device. And when I use

55
00:06:09,799 --> 00:06:17,239
LS minus L on dev mapper, you can see that right in there, we have VG data LV data pointing to

56
00:06:17,239 --> 00:06:24,119
the same device. And it doesn't matter at all which one of these names you are using. Now, let's verify

57
00:06:24,119 --> 00:06:30,359
LVS is showing all my logical volumes. VGS is showing all my volume groups. We should be good

58
00:06:30,359 --> 00:06:33,720
here. We just created the LVM logical volume.

