Resizing file based xen virtual machine

You can create file based xen instances (eg, blarblar.img). If you have partitions in the file and want to increase the disk space, you cannot use resize2fs straight away on it. So you need to create a new larger file, then transfer the old file data onto it:

say I want the new filesize to be 4Mb,

dd if=/dev/zeo of=newImage.img count=4000 bs=1M

now, transfer the files over. Note that notrunc is important because we still want the output file to be 4 Mb.

xm shutdown oldImage.img
dd if=oldImage.img of=newImage.img conv=notrunc

Next, rename the images and boot up!

mv oldImage.img oldImage-dd-mm-yyyy.img
mv newImage.img oldImage.img
xm create /etc/xen/newImage

you can then do resizefs once the vm is booted up. You can copy the files even if the vm is up but then there is a danger of data inconsistency. Easier to manage than using LV.

Author: bpeh

Bernard Peh is a great passioner of web technologies and one of the co-founder of Sitecritic.net Website Design and Reviews. He works with experienced web designers and developers everyday, developing and designing commercial websites. He specialises mainly in SEO and PHP programming.