You can easily resize your storage, by expanding an LVM volume involves two main steps: extending the logical volume and then resizing the file system to fit the additional space.
Before making changes to your logical volumes and filesystem, it's highly recommended that you backup any important data.
1) Important basic concepts:
-
Physical Volumes: Hold raw storage divided into physical storage devices, like /dev/sda or /dev/sdb, which are treated as raw storage for the LVM layer.
-
Volume Groups (VG): These aggregate multiple PVs and can be found with the vgdisplay command, showing properties including the VG name, which you'll use to reference the group. In general these provide the tools to add multiple Physical Volumes into one storage pool, providing an abstraction layer over physical storage.
-
Logical Volumes (LV): Partition-like spaces created from VG. These are typically referenced as /dev/vg1/lv1, where vgname is your volume group name and lvname is your logical volume name. Each LV is a device file that can be formatted with a file system.
-
File Systems: Methods for data storage/retrieval. Once a LV is formatted with a file system (like ext4 or xfs), it's mounted to a mount point in the filesystem hierarchy, e.g., /mnt/volume.
2) Volume Group
You can confirm that the Volume Group has already enough space available, by executing:
$ sudo vgdisplay
Which should return: Free PE / Size with enough space. In case it does not, the VG will need to be resized.
Keep in mind the VG Name
3) Expand Logical volume
Now that we have confirmed there is space free within the volume group,
Next we will use the command below to see logical volumes in detail. It will also show the volume group that the logical volume is a member of, check for the VG Name, same as above, so no mistakes are made.
$ sudo lvdisplay
Expanding the Logical Volume can be done in different ways, here are two examples:
$ sudo lvextend -L +10G /dev/vgname/lvname
$ sudo lvextend -l +100%FREE /dev/vgname/lvname
4) Resize File System
Now that the logical volume has been extended, we can resize the file system.
For ext
$ sudo resize2fs /dev/vgname/lvname
For XFS
$ sudo xfs_growfs /dev/vgname/lvname
5) Verify
$ df -hT