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 http://docs.openstack.org/image-guide/content/ch_modifying_images.html , 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.