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,080
In this video, I want to tell you about LVM resize operations.

6
00:00:24,080 --> 00:00:25,080
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,680
Well, then it's also easy, because you are going to add in the lower layer of your LVM

19
00:01:14,680 --> 00:01:15,680
structure.

20
00:01:15,680 --> 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,239
Oh, it's showing me that my logical volume is not mounted.

26
00:01:33,239 --> 00:01:42,000
Well, I just created it, so let me do a mount minus a and do the df minus h again.

27
00:01:42,000 --> 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,959
Now, let's imagine that this file system is running out of disk space.

30
00:01:55,959 --> 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,440 --> 00:03:16,960
And here we can see the VG data details with V3 on VG data set to zero.

49
00:03:16,960 --> 00:03:19,199
So that is not going to work.

50
00:03:19,199 --> 00:03:23,320
So I need to start all the way at the bottom using fdisk.

51
00:03:23,320 --> 00:03:29,720
So lsblk is showing my block devices, and I'm going to use fdisk, which in my opinion

52
00:03:29,720 --> 00:03:35,119
is the most powerful partitioning utility on slash dev slash sdb.

53
00:03:35,119 --> 00:03:39,199
I'm ignoring these warnings in red because I know what I'm doing.

54
00:03:39,199 --> 00:03:44,600
And I'm just going to use n for new and partition number two, and enter for the first sector

55
00:03:44,600 --> 00:03:49,639
and push 2g to add a two gigabyte partition.

56
00:03:49,639 --> 00:03:54,559
Let's not forget, after adding the partition, you need to set the LVM partition type.

57
00:03:54,559 --> 00:04:00,199
So I'm using T on partition number two, to set the LVM partition type.

58
00:04:00,199 --> 00:04:06,800
And now before I'm leaving, I'm typing P, all looking good, and W to write.

59
00:04:06,800 --> 00:04:09,960
So at this point, I can use VG.

60
00:04:09,960 --> 00:04:15,039
Now, one little trick, if you are thinking about which utility do I need,

61
00:04:15,039 --> 00:04:19,839
as long as you remember you need to do something with the VG, use VG tab tab.

62
00:04:19,839 --> 00:04:24,000
And there you can see the VG extend utility.

63
00:04:24,000 --> 00:04:26,519
And this utility is very intuitive.

64
00:04:26,519 --> 00:04:32,640
You need the name of the VG, and you need the name of the device that you want to add.

65
00:04:32,640 --> 00:04:39,640
And now if I use VGS, you can see that I have about two gigs available on my storage device.

66
00:04:39,640 --> 00:04:43,920
So it's time for the next step, and that will be LV extend.

67
00:04:43,920 --> 00:04:47,000
So LV extend needs a couple of options.

68
00:04:47,000 --> 00:04:54,320
First, I need to specify that I want to extend dev VG data slash LV data.

69
00:04:54,320 --> 00:04:59,119
Very important, in most cases, is the option minus R,

70
00:04:59,119 --> 00:05:03,399
because minus R will resize the file system as well.

71
00:05:03,399 --> 00:05:09,000
It's not so useful if you make your logical volume bigger without growing the file system as well.

72
00:05:09,000 --> 00:05:11,839
And there are separate utilities.

73
00:05:11,839 --> 00:05:15,920
On XFS, it is XFS underscore grow FS.

74
00:05:15,920 --> 00:05:22,040
On EXC4, it is resize to FS that you can use to resize.

75
00:05:22,040 --> 00:05:25,880
Interesting to know, XFS can only be grown bigger.

76
00:05:25,880 --> 00:05:30,119
EXC4 can be reduced and extended in size.

77
00:05:30,119 --> 00:05:35,040
In most cases, you will want to extend, and that's exactly what I'm going to do here,

78
00:05:35,040 --> 00:05:41,119
using minus lowercase L plus 50% free.

79
00:05:41,119 --> 00:05:43,600
Now, this minus lowercase L is a nice option.

80
00:05:43,600 --> 00:05:47,320
You can also use it while you are creating your logical volumes.

81
00:05:47,320 --> 00:05:50,040
It allows you to give a relative size.

82
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.

83
00:05:55,320 --> 00:06:00,799
I'm just going to add 50% of the available disk space.

84
00:06:00,799 --> 00:06:04,640
And there we can see it has found the EXC4 file system.

85
00:06:04,640 --> 00:06:11,519
It is doing the resize to 3 gigabytes, and then it is calling the resize to FS utility

86
00:06:11,519 --> 00:06:15,519
to automatically trigger the file system resize as well.

87
00:06:15,519 --> 00:06:20,720
And at the end of it, DF minus H is going to show us that the miracle has happened.

88
00:06:20,720 --> 00:06:26,000
Yay, we suddenly have 865 megabytes available on the file system,

89
00:06:26,000 --> 00:06:28,600
and we can continue working on it.

90
00:06:28,600 --> 00:06:30,600
And that's how you resize a logical volume.

