How to extend a Xen VPS Disk space if no space left in the existing Volume Group?
I went through a situation where an LVM based Xen VPS is required to increase the Disk space. We often use lvextend command to extend an LVM partition. But if there is no space left on the existing Volume group how could we increase the logical partition.
I followed the steps below:
Step 1. SSH to the VPS.
Step 2. Use lvdisplay, vgdisplay and pvdisplay to check their status and see if they are full or not.
Step 3. If VG is already full and using all the PV size then we cannot further increase the VG size and LV size.
Step 4. The only option is to extend the size by using an extra partition. Suppose xvda is the main Disk and xvda1 and xvda2 are the existing partitions.
Steps
-> Create partition for /dev/xvda3 with sufficient storage space with LVM filesystem.
-> Create Physical Volume (PV).
-> Extend Volume Group (VG).
-> Extend Logical Volume (LVM).
Create Partition
Command:
fdisk -cu /dev/xvda
Make sure you add it as 8e linux lvm.
Reboot VPS. So at this stage new partition is created (let it be /dev/xvda3) with LVM type file system.
Create Physical Volume
Command:
pvcreate /dev/xvda3
Extend Volume Group (VG)
Use the command vgdisplay to see the current status. Then extend the Volume Group using the following command:
vgextend vol_group_name /dev/xvda3
Run vgdisplay again to verify the changes. We will see extra space added to our VG. We can use this extra space to extend out Logical Volume (LVM).
Extend LVM
Use the command lvdisplay to see the current usage/status. Then extend the size using the following command:
lvextend -L +50G /dev/vol_group_name/LV_name
Above command is for adding extra 50 GB to the LVM. Verify the changes using lvdisplay.
Now run df -h to see if the changes are reflected. It will still shows the OLD size!
The reason is because we would need to update the partition table with the new value of LVM. To do this run the following command:
resize2fs /dev/vol_group_name/LV_name
Now verify again using df -h command. We will see the disk space is extended.
That’s it!