I want to convert a Windows 7 C:\ Drive from my previous laptop into a qcow2 image which I wan to use to create a KVM virtual machine from on a new (linux based) computer.

I guess the simplest way would be some sort of dd plus a qemu-img convertoperation.

1.) Boot the old W7 laptop from a live system and run: dd if=/dev/sda1 of=/path/to/W7.img

(would I need to add any dd options to make that bootable? any other options [for blocksize i.e.]) recommended?)

2.) On the new machine say something like
qemu-img convert -f raw -O qcow2 /path/to/W7.img /path/to/W7.qcow2

that should give me a pretty exact copy with the same size of the C:\ drive I guess.

Now the original C:drive is quite large and half empty, so I'd like to have a dynamically expanding qcow2 image as an end result and likewise reduce it's size.

Is there any option I can add to the qemu-img convert operation which would help to achieve that?


There is a tool already available to do this conversion, called virt-p2v.

To get started, install libguestfs-tools on your Ubuntu system which will serve as the hypervisor for your new KVM virtual machine. This will install virt-p2v, virt-v2v and virt-p2v-make-disk, all of which you will need.

sudo apt install libguestfs-tools

Now insert a USB stick to your Linux system, make note of its /dev/sd* device name, and run virt-p2v-make-disk to create a bootable virt-p2v environment, from which you will later boot the Windows machine. (Or see the man page for other options for creating the bootable image.)

sudo virt-p2v-make-disk -o /dev/sd*

Now boot your Windows system from this USB stick. It will ask you to provide credentials to SSH into the Linux machine. You will either need to enable root on the Ubuntu machine, or set up passwordless sudo for your account.

After you set up ssh, virt-p2v will ask you some questions about the virtual machine you want to create, and then it will begin copying data from your physical machine to the Ubuntu server.

  • sorry, for slow response. I was stuck in "can't load external javascript hell" .... now, sounds like a pretty sophisticated tool. but I am missing the part that makes the size of the qcow2 image smaller then the actually 102 GB of the physical drive. Is that built in? – vrms Apr 18 '18 at 1:22
  • regarding qemu-img convert I came across the -c option which may 'compress' the new file and (maybe also create a (sizewise) dynamic qcow2 image. – vrms Apr 18 '18 at 1:23
  • @vrms The image you get should already be sparse, but if it isn't, you can use virt-sparsify to fix that. As for actually shrinking it, that's probably something you should do with Windows tools before p2ving it. – Michael Hampton Apr 18 '18 at 1:39
  • you mean shrinking the existing physical C:\ drive rahter then trying to shrink an image file I guess. Sounds much more risky that way to me but maybe there is not other way? – vrms Apr 18 '18 at 8:47
  • Or, at least, shrinking the partition(s). The virtual disk can then be shrunk to match later. – Michael Hampton Apr 18 '18 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.