How to Extend Logical Volumes on Ubuntu Server After Installation

Extending your logical volume on an Ubuntu server is easy with the lvextend command.
Normally, you’d do that with the df command, but it will not display the correct size of the logical volumes.
Instead, use the vgdisplay (Volume Group Display) command, which displays comprehensive information on volume groups and logical volumes.

There are three important parameters you must pay attention to:

VG Size: This is the volume group size and shows the total available disk size.

Alloc PE/Size: This shows the amount of space that your server is currently allocated

Free PE/Size: Shows the free space out of the total possible storage space
vgdisplay

The df command only displays the allocated space and not the entire possible space, and this can lead you to assume that you do not have much space left on your server when a lot of space is lying idle as part of the volume group.
df -h command

To extend the logical volume, use the lvextend command. But first, get the mount point of the logical volume using the lvdisplay command:
sudo lvdisplay
lvdisplay
From the lvdisplay output, you can see that the disk is mounted on the path /dev/ubuntu-vg/ubuntu-lv.
Next, increase the logical volume space using the following command:
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
100% means using up the entire space, so assign the required percentage according to your needs, e.g. 50%, 60%, etc.
lvextend
For the changes to take effect you also need to resize the file system comprising the logical volume. Get the file system path from the df -h command; in this case, it is /dev/mapper/ubuntu–vg-ubuntu–lv.
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More post