In our earlier tutorial, we discussed "How we can create LVM " but there might arise a need for resizing LVM. One of the great advantages of using LVM is that we can resize LVM as per our needs. We can increase them in size either by allotting leftover space from our Volume group or we can add a new partition/disk to increase size & we can also reduce them in size. In this tutorial, we will be discussing just that i.e. resizing LVM.
If you are just joining us for this tutorial, I highly recommend that you read our tutorial for ‘Creating LVM’ before you move with this tutorial.
(Recommended Read: Configuring RAID1 (Mirroring) on CentOS/RHEL )
Firstly let us discuss how to reduce the LVM size,
Reducing LVM
So let’s say we have a LVM ‘ /dev/vg01/lv01’of size 40GB is mounted at /data which we wish to reduce by 15GB to 25GB. So firstly, we will unmount the LV from mount point
$ umount /data
Next, we will check our LVM for any disk errors using ‘e2fsck’ command
$ e2fsck –f /dev/vg01/lv01
Once the check is complete & returns with no errors, we will move to next part I.e. reducing the size of LV. We will first resize the filesystem to 25GB by reducing 15GB from it,
$ resize2fs /dev/vg01/lv01 25G
& lastly we will reduce the size of LV,
$ lvreduce –L 25G /dev/vg01/lv01
That’s it, our LV has been reduced to 25GB from original size of 40GB. Now remount the filesystem & check the size of LV
$ mount /data
$ df –h /data
(Also Read: Configuring RAID0 (Stripping) on CentOS/RHEL)
Increasing LVM size
We will now increase the size the LV from 25GB to 40GB,
- Firstly by adding a new disk
- Secondly by using leftover space of vg01
Adding new Disk to increase size
We will prepare new disk /dev/sdd for adding it to LVM with ‘fdisk ’ command
- Firstly we will prepare /dev/sdb disk for LVM, start by
$ fdisk /dev/sdd
- Type ‘n’ for creating new partition,
- Next type ‘p’ for creating the primary partition (since this is new disk, partition number will be 1 )
- Nest for First cylinder value & last cylinder value, press enter to use default values i.e. full hdd space
- Type ‘t’ for accessing the partition followed by ‘1’ (partition number)
- Now this is the part where we will enter the partition id for creating LVM i.e. 8e. Type ‘8e’ now & press ‘w’ to write changes.
Now our disk is ready for to be included in our existing LV i.e. /dev/vg01/lv01. Steps for that are as follows
- Create Physical volume
We will create a Physical volume by running the following command
$ pvcreate /dev/sdd
Check PV by using ‘pvdisplay’ command,
- Extend Volume group ‘vg01’ to include /dev/sdd
$ vgextend vg01 /dev/sdd
Verify by running ‘vgdisplay’ command
- Extend Logical volume ‘lv01’
$ lvextend –L +15G /dev/vg01/lv01
Here, ‘-L +15G’ means that the size of LV’lv01’ is to be increased by 15GB, we can verify the new size by running ‘lvdisplay’ command.
But when we run ‘lvdisplay’ , it will display the old size of LV i.e.25GB. That’s because we have resized the filesystem
- Resizing filesystem
$ resize2fs /dev/vg01/lv01
Now verify by running the ‘lvdisplay’ to see the new size of LV i.e.40GB.
Using Leftover space from vg01
If we have some space, let’s say 10 GB, in our Volume Group ‘vg01’ we can add that to ‘lv01’
& we can do this by only following step 3 & 4 from above process i.e.
- Extend Logical volume ‘lv01’
$ lvextend –L +10G /dev/vg01/lv01
- Resizing filesystem
$ resize2fs /dev/vg01/lv01
Now verify by running the ‘lvdisplay’ to see the new size of LV i.e. 35 GB.
That’s it guys, we have completed our tutorial on resizing LVM partitions. Please feel free to leave your comments/queries in the comment box.
If you think we have helped you or just want to support us, please consider these :-
Connect to us: Facebook | Twitter | Google Plus
Donate us some of you hard earned money: [paypal-donation]
Linux TechLab is thankful for your continued support.
My /home LVM volume is huge, but root (/) is too small. Following your steps for resizing /home seem easy, but…
How do I unmount the root directory?