In this video, I'll show you how to resize an LVM logical volume.
Now in case you are wondering why didn't we do that in the lesson about LVM, well, simple,
because you want to resize the file system as well.
Let me show you what's going on.
In this video, I want to tell you about LVM resize operations.
So how does it work?
Well, we are going back to the volume group.
And when you have defined a file system, then you put it in a logical volume, and the logical
volume is coming from the volume group.
So let's say that on your file system, df minus h is giving you 100% full.
And oh, no, what are you going to do?
Well, then you are going to check in the volume group if any more storage is available.
And if storage is available in the volume group, it's easy, it can be added to the logical
volume.
And the logical volume can dynamically resize including the file system.
But sometimes you will notice that in the volume group, there is no more storage space
available.
Well, then it's also easy, because you are going to add in the lower layer of your LVM
structure.
Just add a physical volume to grow your volume group, which allows you to grow your logical
volume.
And that's all.
So here, I'm going to use df minus h.
And df minus h is showing me what?
Oh, it's showing me that my logical volume is not mounted.
Well, I just created it, so let me do a mount minus a and do the df minus h again.
And there we can see on the bottom line that we have a file system slash data that is on
the logical volume with the name devmapper vgdata lvdata.
Now, let's imagine that this file system is running out of disk space.
I can even do that, dd if is dev0, of is slash data slash big file.
And that will fill up my file system pretty fast.
So if is dev0 is using the input file dev0, the output file data big file.
And as you can see, it fills with no space left on device.
Oh, no.
So du minus hs on slash data is giving me what?
It's giving me two gigabytes in use.
And df minus h is also showing that there is no available disk space.
Let's click this graphical warning away because that's not something that you want to troubleshoot.
Now, what is the issue here?
Well, the issue here is I want more disk space to be available in my file system.
In order to have more disk space in my file system, I need more disk space in my logical
volume.
In order to have more disk space in my logical volume, I need my volume group to have available
disk space.
And if it does not, I might have to add a new LVM storage device and add it to the volume
group.
So the first thing to do is check out the volume group, vgs is how I'm doing it.
Here we can see the VG data details with v3 on VG data set to zero.
So that is not going to work.
So I need to start all the way at the bottom using fdisk.
So lsblk is showing my block devices and I'm going to use fdisk, which in my opinion is the
most powerful partitioning utility on slash dev slash sdb.
I'm ignoring these warnings in red because I know what I'm doing and I'm just going to use n for
new and partition number two and enter for the first sector and push 2g to add a two gigabyte
partition.
Let's not forget, after adding the partition, you need to set the LVM partition type.
So I'm using T on partition number two to set the LVM partition type.
And now before I'm leaving, I'm typing P, all looking good, and W to write.
So at this point, I can use VG.
Now, one little trick, if you are thinking about which utility do I need, as long as you remember you
need to do something with the VG, use VG tab tab.
And there you can see the VG extend utility.
And this utility is very intuitive.
You need the name of the VG and you need the name of the device that you want to add.
And now if I use VGS, you can see that I have about two gigs available on my storage device.
So it's time for the next step, and that will be LV extend.
So LV extend needs a couple of options.
First, I need to specify that I want to extend dev VG data slash LV data.
Very important in most cases is the option minus R because minus R will resize the file system as well.
It's not so useful if you make your logical volume bigger without growing the file system as well.
And there are separate utilities.
On XFS, it is XFS underscore grow FS.
On EXC4, it is resize to FS that you can use to resize.
Interesting to know, XFS can only be grown bigger.
EXC4 can be reduced and extended in size.
In most cases, you will want to extend, and that's exactly what I'm going to do here,
using minus lowercase L plus 50% free.
Now, this minus lowercase L is a nice option.
You can also use it while you are creating your logical volumes.
It allows you to give a relative size.
Plus 50% free makes it I don't have to worry about the exact size that is available.
I'm just going to add 50% of the available disk space.
And there we can see it has found the EXC4 file system.
It is doing the resize to three gigabytes, and then it is calling the resize to FS utility
to automatically trigger the file system resize as well.
And at the end of it, DF minus eight is going to show us that the miracle has happened.
Yay, we suddenly have 865 mebibytes available on the file system,
and we can continue working on it.
And that's how you resize a logical volume.