1 00:00:00,000 --> 00:00:10,480 In this lesson, you will learn about the Logical Volume Manager. 2 00:00:10,480 --> 00:00:15,840 In this video, I'll tell you about the different components that you are using in LVM. 3 00:00:15,840 --> 00:00:21,000 In the heart of LVM is a volume group. 4 00:00:21,000 --> 00:00:24,959 And this volume group is an abstraction of all the storage that you want to put in your 5 00:00:24,959 --> 00:00:25,959 LVM configuration. 6 00:00:25,959 --> 00:00:31,280 You do that by using the so-called PV, the physical volumes. 7 00:00:31,280 --> 00:00:36,520 And these physical volumes can be hard disks, it can be partitions, it can be any valid 8 00:00:36,520 --> 00:00:38,439 block device. 9 00:00:38,439 --> 00:00:40,759 And that is allowing you for flexibility. 10 00:00:40,759 --> 00:00:46,279 If you run out of disk space on your volume group, you can easily add more storage by 11 00:00:46,279 --> 00:00:49,080 adding PVs. 12 00:00:49,080 --> 00:00:54,759 Now from the volume group, you are going to create your logical volumes. 13 00:00:54,759 --> 00:01:00,240 And these are the storage devices on which you are going to use your file systems. 14 00:01:00,240 --> 00:01:04,320 So your MKFS is happening here. 15 00:01:04,320 --> 00:01:10,239 And a nice thing is that these logical volumes get their disk space from the volume group, 16 00:01:10,239 --> 00:01:12,559 but they are not aware and there is no strict relation. 17 00:01:12,559 --> 00:01:17,360 And that means that if your logical volume runs out of disk space, you just go get more 18 00:01:17,360 --> 00:01:19,559 disk space from the volume group. 19 00:01:19,559 --> 00:01:24,199 And if in the volume group, there is no additional disk space available, well, you are just going 20 00:01:24,199 --> 00:01:28,440 to add another storage device right here as a PV. 21 00:01:28,440 --> 00:01:33,320 And that is what implements the flexibility in an LVM environment. 22 00:01:33,320 --> 00:01:36,720 So let's summarize the procedure for creating LVM. 23 00:01:36,720 --> 00:01:39,400 First, you need to create a partition. 24 00:01:39,400 --> 00:01:45,760 And this partition needs to be set to the appropriate type, which is 8E on MBR, 8E00 25 00:01:45,760 --> 00:01:46,959 on GPT. 26 00:01:46,959 --> 00:01:51,800 Or when you use modern utilities, you can use LVM, which is an alias to the correct 27 00:01:51,800 --> 00:01:53,879 partition type. 28 00:01:53,879 --> 00:02:00,400 Then you use pvcreate on your device to mark the partition as a physical volume. 29 00:02:00,400 --> 00:02:06,919 And next, vgcreate, you give the volume group a name and you add a physical volume into 30 00:02:06,919 --> 00:02:07,919 it. 31 00:02:07,919 --> 00:02:11,880 DevNNN, that corresponds to the partition that you have just created as an LVM type 32 00:02:11,880 --> 00:02:12,880 partition. 33 00:02:12,880 --> 00:02:17,160 Oh, and by the way, if you are wondering, do we need to create a partition? 34 00:02:17,160 --> 00:02:23,160 No, you can also put an entire disk in LVM, but it's nicer for administration purposes 35 00:02:23,199 --> 00:02:28,720 to do partitions, because they are clearly marked as an LVM partition type. 36 00:02:28,720 --> 00:02:32,559 Once you have your volume group, you can create logical volumes from it. 37 00:02:32,559 --> 00:02:38,240 So lvcreate minus uppercase L1G will create a one gigabyte volume. 38 00:02:38,240 --> 00:02:44,039 Minus N, LVName will use the name LVName, and vgname will put it in the volume group 39 00:02:44,039 --> 00:02:45,639 that you have created. 40 00:02:45,639 --> 00:02:49,479 And that will create a one gigabyte volume in that group. 41 00:02:49,479 --> 00:02:56,759 And then you can use pvs, vgs, lvs, or pvdisplay, vgdisplay, lvdisplay to verify. 42 00:02:56,759 --> 00:03:02,039 The display commands are giving a little bit more information, the pvs and so on commands 43 00:03:02,039 --> 00:03:04,440 are giving a short list. 44 00:03:04,440 --> 00:03:10,199 And once you are done, you can mount it using dev vgname LVName, or using the device mapper 45 00:03:10,199 --> 00:03:16,600 name that is used behind it, which is slash dev slash mapper slash vgname dash LVName. 46 00:03:16,600 --> 00:03:20,600 Let me show you how to set up a simple LVM environment. 47 00:03:20,600 --> 00:03:28,000 So I'm going to start with lsblk, because in order to set up LVM, we need a block device. 48 00:03:28,000 --> 00:03:30,839 And I need to analyze and determine what I've got. 49 00:03:30,839 --> 00:03:37,220 Well, I'm going to use dev nvme0n2, on which we have sufficient space available. 50 00:03:37,220 --> 00:03:44,199 So I'm going for my favorite utility, and that is fdisk on dev nvme0n2. 51 00:03:44,199 --> 00:03:47,639 And there, you can ignore the message that you see here. 52 00:03:47,639 --> 00:03:50,559 This is just to scare people away that don't know what they're doing. 53 00:03:50,559 --> 00:03:52,520 But you know what you're doing, right? 54 00:03:52,520 --> 00:03:55,380 So I'm going to use n for a new partition. 55 00:03:55,380 --> 00:03:58,440 The new partition will be partition number four. 56 00:03:58,440 --> 00:04:01,639 And first sector, well, I'm not even going to think about it. 57 00:04:01,639 --> 00:04:03,759 I'm just accepting the default. 58 00:04:03,759 --> 00:04:09,800 And last sector, let's make this a four gigabyte partition, plus 4g. 59 00:04:09,800 --> 00:04:14,240 There, we can see that the new partition is created of the type Linux file system. 60 00:04:14,240 --> 00:04:16,040 Well, that is what I need to change. 61 00:04:16,040 --> 00:04:19,160 So I'm using T to change the partition type. 62 00:04:19,160 --> 00:04:25,279 And for partition number four, I'm setting the partition type to LVM. 63 00:04:25,279 --> 00:04:30,440 And now I'm using P to verify that partition four was correctly set as LVM. 64 00:04:30,440 --> 00:04:35,000 It is, so I can use W to write and exit. 65 00:04:35,000 --> 00:04:39,279 As always, it's a good idea to verify your storage using lsblk. 66 00:04:39,279 --> 00:04:44,839 And there, we can see that we have an NVMe 0n2p4 partition. 67 00:04:44,839 --> 00:04:47,600 That's the one that I just created. 68 00:04:47,600 --> 00:04:56,799 So I'm going to use pvcreate on dev NVMe 0n2p4, which will mark it as a physical volume. 69 00:04:56,799 --> 00:05:00,079 That will make it usable by LVM. 70 00:05:00,079 --> 00:05:02,200 Next, I can use vgcreate. 71 00:05:02,200 --> 00:05:04,600 I'm calling it vgdata. 72 00:05:04,600 --> 00:05:11,320 And I'm putting in my device NVMe 0n2p4. 73 00:05:11,320 --> 00:05:15,239 And that is telling me that the volume group was successfully created. 74 00:05:15,239 --> 00:05:16,399 Well, that was easy. 75 00:05:16,399 --> 00:05:21,119 Now, lvcreate minus l1g. 76 00:05:21,119 --> 00:05:26,839 I want a 1 gigabyte logical volume minus n lvdata. 77 00:05:26,839 --> 00:05:29,920 And I need to do that in vgdata. 78 00:05:29,920 --> 00:05:34,480 And as you can see, the logical volume lvdata was created. 79 00:05:34,480 --> 00:05:34,880 Good. 80 00:05:34,880 --> 00:05:36,600 Now, I can use lvs. 81 00:05:36,600 --> 00:05:44,200 And there, we can see that lvdata is indeed correctly created with a size of 1 gigabyte. 82 00:05:44,200 --> 00:05:50,239 Now, the fun fact is that the logical volume has two different names. 83 00:05:50,239 --> 00:06:00,359 When I use ls minus l on dev vgdata lvdata, I can see that that is one name pointing to a device DM2. 84 00:06:00,359 --> 00:06:03,440 That's a symbolic link to the device mapper device. 85 00:06:03,440 --> 00:06:06,839 Device mapper is a system that is used behind LVM. 86 00:06:06,839 --> 00:06:09,239 And here, we can see the name of that device. 87 00:06:09,239 --> 00:06:18,799 And when I use ls minus l on dev mapper, you can see that right in there, we have vgdata lvdata pointing to the same device. 88 00:06:18,799 --> 00:06:23,079 And it doesn't matter at all which one of these names you are using. 89 00:06:23,079 --> 00:06:24,200 Now, let's verify. 90 00:06:24,200 --> 00:06:27,040 LVS is showing all my logical volumes. 91 00:06:27,040 --> 00:06:29,640 VGS is showing all my volume groups. 92 00:06:29,640 --> 00:06:30,959 We should be good here. 93 00:06:30,959 --> 00:06:33,760 We just created the LVM logical volume.