There are a number of ways to increase the hard-disk size of a VM once it is provisioned, without rebuilding the VM. The chief way of doing it is via LVM and I love it.
My setup uses KVM on the host with all disk images stored in a LVM pool. In each VM, the main hard-disk is also using LVM as well, which is perfect.
To increase the size of the VM, I do this:
- Stop the VM.
Just so I don’t screw anything up accidentally, I will stop the VM. - Extend the volume in the host.
This increases the size of the disk on the host:
lvextend -L+10G /dev/lvmpool0/volumename - Startup the VM.
It should reflect the new disk size. Check this by usingfdiskor similar tool. - Partition the empty space.
Preferably, use a Logical partition. Remember to set the partition type to ‘8E’ for Linux LVM. - Reboot the VM.
To ensure the disk changes are read. VMs sometimes have issues with this. - Create the new PV.
Ready the new partition:
pvcreate /dev/hdaX - Extend the VG to this PV.
This will append the PV to the existing VG instead of creating a new VG:
vgextend vgname /dev/hdaX - Find out the amount of free space.
This is needed for the next step.vgdisplaywill show the amount of Free PE. - Extend the Logical Volume in this VG.
The VG can be extended to any size, or up to the maximum free space above:
lvextend -l + XXXX /dev/vgname/lvname - Resize the File System.
This is the final step to using the new disk:
resize2fs /dev/vgname/lvname