Tuesday, November 1, 2022

Extending LVM By Adding New Disk To a Virtual Machine

In previous post, we have covered the way to make LVM and filesystem aware of the disk size increase that happen in the virtual machine layer. 

There is another way to increase LVM volume capacity, that is to add new disk into the system. 

1. First, shutdown the virtual machine

2. Add a new virtual disk size into the virtual machine manager

3. Start the virtual machine

4. Check the new disk availability for LVM
$ sudo lvmdiskscan

5. To be able to use the new disk, it needs to be converted into physical volume (PV)
$ sudo pvcreate <path to the new disk>

6. Check list of PVs. Memorize the PV name
$ sudo pvs

7. Extend the volume group using the new PV
$ sudo vgextend <VG name> <PV name>

We can get the name of the VG by using this command. This command also will show how much free space is now available in the VG.
$ sudo vgs

8. Increase the size of logical volume, to use 100% of the free space available inside VG, using this command
$ sudo lvextend -l +100%FREE <LV PATH>

We can get the full  path of LV using this command
$ sudo lvdisplay | grep Path

9. Now, make the filesystem aware that the partition size has been increased. The command to do this differ from filesystem to filesystem, but we include 2 of the most used (based on our experience) filesystem
For xfs:
$ sudo xfs_growfs <mountpoint>

For  ext4:
$ sudo resize2fs <mountpoint>

10. Verify that the mountpoint is now increase in size
$ df -Th

No comments:

Post a Comment