In order to go along with this article, you must have
- A physical volume from your storage drive
- A physical volume under volume group
- Logical volume over volume group
- Filesystem on logical volume
Use the lsblk command to check physical volumes.
Notice the three available physical volumes /dev/sda, /dev/sdb and /dev/sdc in the above screenshots. Now, list all the volume groups on the system using any of these vgdisplay, vgscan and vgs commands.
There is only one volume group vg01 created from only one physical volume. Now, list all the available logical volumes on the volume group vg01 using lvs, lvscan or lvdisplay command.
The output above displays two logical volumes lv01 and lv02 on the volume group vg01. If you don’t have any of the above prerequisites, check the previous articles on LVM.
Extend Logical Volume
Before logical volume extension, make sure there is enough space in the volume group containing the logical volume. Use the vgs, vgdisplay or vgscan command to verify the available space in the volume groups.
The current size of the volume group vg01 is about 30 GB and there is a free space of 15 GB available in the volume group. If there is not enough space available in the volume group, then the volume group will be expanded first to create free space. Alternatively, if there are more logical volumes in the volume group, shrink these volume groups to create free space.
After checking the volume group for free space, now check the current size of the logical volume and estimate its extended size. The lvdisplay command can be used to get the information of the existing logical volume.
So, there are two logical volumes lv01 and lv02 with the size of 10 GB and 5 GB respectively. For this demo, let us increase the size of the logical volume lv01 from 10 GB to 15 GB. In order to increase the logical volume size, the lvextend command will be used along with the -L flag.
The lvextend command has increased the size of volume group lv01 from 10 GB to 15 GB. In order to confirm the size of the logical volume using the command line interface, use any one of the lvdisplay, lvscan and lvs commands.
Use the vgs or vgdisplay commands to display the occupied and free space of the volume group vg01.
As shown above, the volume group vg01 has a free space size of 15GB and now there is only 10 GB of free space which depicts successful logical volume extension.
After extending the size of the logical volume, mount the logical volume on the system to verify file system extension.
After mounting the logical volume, list all the mounted filesystems on the system.
The filesystem is still 10 GB in size and it also needs to be extended separately. The resize2fs command can be used to extend an ext4 filesystem.
Now, use the df command to check the filesystem mounted on the system again to verify extension.
The filesystem mounted on the system is 15 GB in size and has been extended successfully.
Extend Logical Volume via GUI Tool
An easier way to extend logical volume size is using a graphical user interface tool that is kvpm. You can find instructions about installing the tool in the previous articles. Open the kvpm by running the kvpm command in the terminal.
It will open a window containing information about all the block devices connected to the system. For this section, we will extend the logical volume lv02 from 5 GB to 10 GB.
In order to extend the logical volume size, go to the Group:vg01 tab and select the logical volume lv02. Then extend the list of the options by clicking on the arrow sign and click on the Extend option.
For the new size of the logical volume select the General tab, enter the new size of the logical volume and click on the OK button to increase the size.
It increases the logical volume size that can be observed from the kvpm tool.
In order to extend the filesystem, select the Group: vg01 tab, select the logical volume lv02 and click on the Extend fs button.
A window prompts for confirmation before extending the filesystem.
Alternatively, the logical volume size and filesystem can also be confirmed using the command line interface. The lvdisplay and df commands can be used to display all the details of the logical volumes.
Mount the logical volume on the system and check the filesystem size.
Extending the logical volume size for a server is a crucial task as a file system mounted on the server may run out of space. LVM provides facility to extend the logical volume size without facing any downtime. This blog explains all the steps to extend an existing logical volume and the filesystem using the command line interface and graphical user interface tool.