1 00:00:00,000 --> 00:00:11,000 In this video, I'll show you how to resize an LVM logical volume. 2 00:00:11,000 --> 00:00:15,680 Now in case you are wondering why didn't we do that in the lesson about LVM, well, simple, 3 00:00:15,680 --> 00:00:18,280 because you want to resize the file system as well. 4 00:00:18,280 --> 00:00:20,400 Let me show you what's going on. 5 00:00:20,400 --> 00:00:24,100 In this video, I want to tell you about LVM resize operations. 6 00:00:24,100 --> 00:00:25,100 So how does it work? 7 00:00:25,600 --> 00:00:29,559 Well, we are going back to the volume group. 8 00:00:29,559 --> 00:00:35,599 And when you have defined a file system, then you put it in a logical volume, and the logical 9 00:00:35,599 --> 00:00:39,000 volume is coming from the volume group. 10 00:00:39,000 --> 00:00:46,919 So let's say that on your file system, df minus h is giving you 100% full. 11 00:00:46,919 --> 00:00:48,680 And oh, no, what are you going to do? 12 00:00:48,680 --> 00:00:53,599 Well, then you are going to check in the volume group if any more storage is available. 13 00:00:53,599 --> 00:00:58,560 And if storage is available in the volume group, it's easy, it can be added to the logical 14 00:00:58,560 --> 00:00:59,560 volume. 15 00:00:59,560 --> 00:01:03,840 And the logical volume can dynamically resize including the file system. 16 00:01:03,840 --> 00:01:07,440 But sometimes you will notice that in the volume group, there is no more storage space 17 00:01:07,440 --> 00:01:08,440 available. 18 00:01:08,440 --> 00:01:14,760 Well, then it's also easy, because you are going to add in the lower layer of your LVM 19 00:01:14,760 --> 00:01:15,760 structure. 20 00:01:15,760 --> 00:01:20,160 Just add a physical volume to grow your volume group, which allows you to grow your logical 21 00:01:20,160 --> 00:01:21,160 volume. 22 00:01:21,160 --> 00:01:22,639 And that's all. 23 00:01:22,680 --> 00:01:26,080 So here, I'm going to use df minus h. 24 00:01:26,080 --> 00:01:29,559 And df minus h is showing me what? 25 00:01:29,559 --> 00:01:33,320 Oh, it's showing me that my logical volume is not mounted. 26 00:01:33,320 --> 00:01:42,040 Well, I just created it, so let me do a mount minus a and do the df minus h again. 27 00:01:42,040 --> 00:01:47,480 And there we can see on the bottom line that we have a file system slash data that is on 28 00:01:47,480 --> 00:01:52,400 the logical volume with the name devmapper vgdata lvdata. 29 00:01:53,160 --> 00:01:55,919 Now, let's imagine that this file system is running out of disk space. 30 00:01:55,919 --> 00:02:06,959 I can even do that, dd if is dev0, of is slash data slash big file. 31 00:02:06,959 --> 00:02:10,199 And that will fill up my file system pretty fast. 32 00:02:10,199 --> 00:02:16,039 So if is dev0 is using the input file dev0, the output file data big file. 33 00:02:16,039 --> 00:02:19,600 And as you can see, it fills with no space left on device. 34 00:02:19,600 --> 00:02:20,600 Oh, no. 35 00:02:20,800 --> 00:02:24,240 So du minus hs on slash data is giving me what? 36 00:02:24,240 --> 00:02:27,279 It's giving me two gigabytes in use. 37 00:02:27,279 --> 00:02:32,720 And df minus h is also showing that there is no available disk space. 38 00:02:32,720 --> 00:02:37,119 Let's click this graphical warning away because that's not something that you want to troubleshoot. 39 00:02:37,119 --> 00:02:39,279 Now, what is the issue here? 40 00:02:39,279 --> 00:02:45,279 Well, the issue here is I want more disk space to be available in my file system. 41 00:02:45,279 --> 00:02:49,880 In order to have more disk space in my file system, I need more disk space in my logical 42 00:02:49,880 --> 00:02:51,039 volume. 43 00:02:51,039 --> 00:02:57,559 In order to have more disk space in my logical volume, I need my volume group to have available 44 00:02:57,559 --> 00:02:58,960 disk space. 45 00:02:58,960 --> 00:03:04,320 And if it does not, I might have to add a new LVM storage device and add it to the volume 46 00:03:04,320 --> 00:03:05,839 group. 47 00:03:05,839 --> 00:03:11,360 So the first thing to do is check out the volume group, vgs is how I'm doing it. 48 00:03:11,399 --> 00:03:16,839 Here we can see the VG data details with v3 on VG data set to zero. 49 00:03:16,839 --> 00:03:19,119 So that is not going to work. 50 00:03:19,119 --> 00:03:23,160 So I need to start all the way at the bottom using fdisk. 51 00:03:23,160 --> 00:03:30,000 So lsblk is showing my block devices and I'm going to use fdisk, which in my opinion is the 52 00:03:30,000 --> 00:03:35,160 most powerful partitioning utility on slash dev slash sdb. 53 00:03:35,160 --> 00:03:40,759 I'm ignoring these warnings in red because I know what I'm doing and I'm just going to use n for 54 00:03:40,759 --> 00:03:47,679 new and partition number two and enter for the first sector and push 2g to add a two gigabyte 55 00:03:47,679 --> 00:03:49,399 partition. 56 00:03:49,399 --> 00:03:54,399 Let's not forget, after adding the partition, you need to set the LVM partition type. 57 00:03:54,399 --> 00:03:59,919 So I'm using T on partition number two to set the LVM partition type. 58 00:03:59,919 --> 00:04:06,559 And now before I'm leaving, I'm typing P, all looking good, and W to write. 59 00:04:06,559 --> 00:04:09,839 So at this point, I can use VG. 60 00:04:09,839 --> 00:04:16,119 Now, one little trick, if you are thinking about which utility do I need, as long as you remember you 61 00:04:16,119 --> 00:04:19,679 need to do something with the VG, use VG tab tab. 62 00:04:19,679 --> 00:04:23,839 And there you can see the VG extend utility. 63 00:04:23,839 --> 00:04:26,399 And this utility is very intuitive. 64 00:04:26,399 --> 00:04:32,480 You need the name of the VG and you need the name of the device that you want to add. 65 00:04:32,480 --> 00:04:39,559 And now if I use VGS, you can see that I have about two gigs available on my storage device. 66 00:04:39,559 --> 00:04:43,839 So it's time for the next step, and that will be LV extend. 67 00:04:43,839 --> 00:04:46,920 So LV extend needs a couple of options. 68 00:04:46,920 --> 00:04:54,239 First, I need to specify that I want to extend dev VG data slash LV data. 69 00:04:54,239 --> 00:05:03,359 Very important in most cases is the option minus R because minus R will resize the file system as well. 70 00:05:03,359 --> 00:05:08,959 It's not so useful if you make your logical volume bigger without growing the file system as well. 71 00:05:08,959 --> 00:05:11,799 And there are separate utilities. 72 00:05:11,799 --> 00:05:15,880 On XFS, it is XFS underscore grow FS. 73 00:05:15,880 --> 00:05:22,000 On EXC4, it is resize to FS that you can use to resize. 74 00:05:22,000 --> 00:05:25,839 Interesting to know, XFS can only be grown bigger. 75 00:05:25,839 --> 00:05:30,119 EXC4 can be reduced and extended in size. 76 00:05:30,119 --> 00:05:35,000 In most cases, you will want to extend, and that's exactly what I'm going to do here, 77 00:05:35,040 --> 00:05:41,119 using minus lowercase L plus 50% free. 78 00:05:41,119 --> 00:05:43,600 Now, this minus lowercase L is a nice option. 79 00:05:43,600 --> 00:05:47,320 You can also use it while you are creating your logical volumes. 80 00:05:47,320 --> 00:05:50,040 It allows you to give a relative size. 81 00:05:50,040 --> 00:05:55,320 Plus 50% free makes it I don't have to worry about the exact size that is available. 82 00:05:55,320 --> 00:06:00,799 I'm just going to add 50% of the available disk space. 83 00:06:00,799 --> 00:06:04,640 And there we can see it has found the EXC4 file system. 84 00:06:04,640 --> 00:06:11,519 It is doing the resize to three gigabytes, and then it is calling the resize to FS utility 85 00:06:11,519 --> 00:06:15,480 to automatically trigger the file system resize as well. 86 00:06:15,480 --> 00:06:20,720 And at the end of it, DF minus eight is going to show us that the miracle has happened. 87 00:06:20,720 --> 00:06:25,959 Yay, we suddenly have 865 mebibytes available on the file system, 88 00:06:25,959 --> 00:06:28,559 and we can continue working on it. 89 00:06:28,559 --> 00:06:30,559 And that's how you resize a logical volume.