Centos – Extending a logical volume in a virtual machine LVM Resize Extend

Step 1 Extend virtual disk

Power off the virtual machine.
Edit the virtual machine settings and extend the virtual disk size. For more information, see Increasing the size of a virtual disk (1004047).
Power on the virtual machine.
Identify the device name, which is by default /dev/sda, and confirm the new size by running the command:

fdisk -l

Step 2 Create a new primary partition

Run the command:

fdisk /dev/sda

1.Press p to print the partition table to identify the number of partitions. By default, there are 2: sda1 and sda2.
2.Press n to create a new primary partition.
3.Press p for primary.
4.Press 3 for the partition number, depending on the output of the partition table print.
5.Press Enter Two times.
6.Press t to change the system’s partition ID.
7.Press 3 to select the newly creation partition.
8.Type 8e to change the Hex Code of the partition for Linux LVM.
9.Press w to write the changes to the partition table.

Restart the virtual machine!!!

Step 3 Add space to virtual partition

1.Run this command to verify that the changes were saved to the partition table and that the new partition has an 8e type:

fdisk -l

2.Run this command to convert the new partition to a physical volume:

pvcreate /dev/sda3

3.Determine which volume group to extend, use the command

vgdisplay

For Centos

For FreePBX

4.Run this command to extend the Physical volume
For FreePBX

vgextend SangomaVG /dev/sda3

For Centos

vgextend centos /dev/sda3

5. Run the following command to extend the Logical Volume
For Centos

lvextend -L +80000 /dev/centos/root

For FreePBX

lvextend -L +20000 /dev/SangomaVG/root

Note +20000 = 20GB
6.Run the following command to expand the ext3 filesystem
For FreePBX

xfs_growfs /dev/SangomaVG/root

For Centos

xfs_growfs /dev/centos/root

Useful commands to check:

vgdisplay
pvs
vgs
lvs
pvscan