Resize a QEMU/KVM Windows Disk Image

After playing with kvm and qemu during my knee surgery recovery, I got hooked. I have a working windoze XP install running under kvm on my Core 2 Duo, Ubuntu Gutsy Gibbon box, and it flies. It almost, almost feels like native speed (I also got help here and here). It's great. Except, not being a regular windoze user, I'd lost track of how much space a windoze installation (and all the service packs and security updates) needs. When I created my original hard drive image file I made it 6 GB, which, it turns out, is too small. I didn't want to just create a new disk image and re-install, it took a lot of work to get this image up to it's full 6 GB glory.

I hunted and found some instructions for resizing qcow (qemu copy-on-write) disk images, but they just didn't work for me. Once I converted from qcow (qcow2 actually) to raw, windoze wouldn't boot on the raw image. Gparted didn't show any partitioned drive space either. Then I remembered I'd always wanted to try clonezilla. Perfect. After downloading the bootable clonezilla iso, and the bootable gparted iso, I went to work like so:

First, create a new, bigger drive image (Don't worry, it will start really small and grow as you use the space):

qemu-img create -f qcow2 windoze.qcow2 100G

Next, boot up windoze with this new second hard drive (this also shows some of the extra options I use to get sound and stuff, as well as wrapping it all in aoss so I can hear the annoying windoze boot-up sounds):

aoss kvm -soundhw all -cdrom /dev/cdrom -localtime -m 512 -hda original-windoze.img -hdb windoze.qcow2

I don't know if that was needed, but a "Found New Hardware" bubble came up and I felt good that the second hard drive seemed to have been found.

Next, boot from the clonezilla CD image:

aoss kvm -soundhw all -cdrom ~/downloads/clonezilla-live-1.0.3-21.iso -localtime -m 512 -hda original-windoze.img -hdb windoze.qcow2 -boot d

Then you go through the clonezilla wizard to clone the one hard drive to the other. This was very straightforward. I went away for a few hours and when I came back it was done. I'm not sure how long it took.

I think I booted windows again at this point with just the new windoze.qcow2 image to make sure it worked, and it did. Amazing.

Then I booted gparted to grow the partition to be the full size of the disk:

aoss kvm -soundhw all -cdrom ~/downloads/gparted-livecd-0.3.4-10.iso -localtime -m 512 -boot d windoze.qcow2 

Gparted was very simple to use and it grew the ntfs partition to the full 100 GB in about 2 seconds. One more reboot back into windows and I had my new, larger virtual hard drive all working. Pretty sweet.

Comments

neo said…
Good solution.
and if you pre fdisk the new large disk image, gparted is not needed.
use partition copy in clonezilla.
Anonymous said…
Fantastic. Worked like a charm! Thank you for taking the time to share this "how-to" with us.
Anonymous said…
Nice guide! However it does not work for me. After creating and copying my old partition to the new one with clonezilla I can get (QEMU) to boot the new image. I get an error: "A disk read error occurred". I guess this has to do with me not copying the MBR correctly or something. But I don't quite understand what to choose in clonezilla regarding what to copy and what to generate. Anyone can give any hits about this?

Thanks!
Anonymous said…
Bryan, I hope you are running now avoid the ski slopes. I loved this how to. You demonstrate great comprehension and experience with different technologies from this post.

Thanks, Lindylex
neuro said…
Thanks for inspiration! I used some of it for cloning my image to USB connected drive.
Mike said…
Looks like a good guide, but it's a little hard to take you seriously when you keep calling it "windoze."
/mnt said…
Mike,
Some of also call it windblows.
Roger said…
Thanks, this was a very helpful blog entry. In another search I found I could do the same thing a bit simpler. Works at least in windows 7.

First create a raw image with the extra space you want.

qemu-create -f raw temp_image.img 10G

then concatenate the primary image and the additional space image to a new image.

cat existing_image.img temp_image.img > new_image.img

Boot up on new_image.img and for windows 7, it sees the extra space under disk management, just expand the primary volume into the new space. I would think this would work for XP and Vista as well.
Rose Weber said…
Appreciate your bllog post

Popular posts from this blog

SystemVerilog Fork Disable "Gotchas"

'git revert' Is Not Equivalent To 'svn revert'

Put /etc Under Revision Control (with git)