How to extend LVM on qcow2 images

Categories Virtualization

Preparing to add some more space for VM’s swap and /. Commands listed below [note: host = node, VM = virtual machine]

Make sure that the VM is stopped before trying this out.

Current VM space layout (compare with final):


* Extend image to required size

* Boot up the VM,  then log into it, delete and recreate LVM partition

* Reboot then VM, and login back to resize physical volume

* I have to extend swap as well, so better unmount swap which is on LVM before extending it

* Now extend swap LVM

* Make Swap and mount it back again

New Swap = 2GB [success!!]

* Now extend root LVM so that it has ~10GB+ space

* Online resize (WARNING: for ext4 only)


So, final VM layout is as follows:


Resize KVM images in OpenNebula

Categories Virtualization

Although I am doing this for OpenNebula, this can be followed for any KVM setup.

I am using a CentOS 6.2 image downloaded from OpenNebula Marketplace. This is of size 10GB, and my requirement is to extend root partition (/dev/sda1) to 20GB.

All commands on KVM host:

Make a backup of the existing disk image before proceeding..

I wish to add 10 more GB to the current partition (so, total size = 20GB). So, create a new raw disk image of size 20GB first, and then clone the contents from original image file to new image file.

The filesystem should be ready by now, but just in case you wish to run “resize2fs” manually:

Now include the new image in OpenNebula, use it in the VM template and start a new instance again.

NOTE: There are many more ways to resize, this is just one of those methods (like , or even live-resize using “qemu-img resize”).

For example: to extend the entire disk in order to create additional partitions (/dev/vda2, /dev/vda3 etc), “qemu-img resize” command should be enough.