You are here

how to resize a kvm / qemu image

what a night! i was trying to expand the size of my spacewalk kvm guest and instead messed it up and so i had to try and fix it. i dint have any luck but i did learn how to take a working kvm guest image and make it bigger.

first of all prepare your host by installing the following

yum -y install libguestfs-tools

next make of a copy of the old guest for the new guest. if you are using this method to expand your current guest, you read right, you will need to make a copy first

cp OLD.img NEW.img

then resize the new image to your desired size

qemu-img resize NEW.img 20G

and now, tell qemu to modify the lvm within the image using the old image as a reference

virt-resize --resize /dev/sda2=20G --LV-expand /dev/VolGroup00/LogVol00 OLD.img NEW.img

finally startup the vm guest and log into into it to do a 

resize2fs -p /dev/VolGroup00/LogVol00 

and thats it you are done. you can also verify with

df -h

resources: http://libguestfs.org/virt-resize.1.html