After all of the Windows and Linux virtual machines I have setup I decided to try a Windows p2v (Physical to Virtual) conversion. After bracing for the worst it ended up being fairly straight forward. Steps as follows:
- Create a disk image of sufficient size
- Copy the Windows HDD to the disk image
- Boot the image with KVM
Yip. Only three steps. Beware that Windows p2v images have all run quite slow for me compared to Windows images that were originally installed in KVM. This I guess is just because of the cruft buildup in Windows and all the driver changes that Windows seems to balk at so much.
Although these instructions are written using Window XP as the guest image, it will work equally (extremely) well for Linux too. The only exception with linux being that you can substitute the clonezilla step for a straight tar copy of the images. Using clonezilla for Windows and Linux though reduces the number of different steps to remember.
Create a disk image of sufficient size
I chose to use qcow2 for spaces sake as I am only testing this on my laptop. Feel free to use any type of disk image that KVM supports.
qemu-img create -f qcow2 windowsxp.qcow2 80G
Copy the Windows HDD to the disk image
For this step I pulled the HDD from the machine to convert and connected it via a usb sata converter. The HDD was then accessible at /dev/sdc. However you connect the HDD to your computer, be it internally or externally, you will need to be able to access it as a block device. So just substitute my references to /dev/sdc with the location of your source HDD.
kvm -m 256 -boot d -cdrom clonezilla-live-1.2.1-39.iso -hda /dev/sdc -hdb widowsxp.qcow2
After booting I selected a disk to disk copy and just accepted all of the default options. I will work both with NTFS and FAT32 partitions. The main thing to be aware of when using clonezilla is that the PHYSICAL drive gets selected as the source. It’s description in clonezilla will be similar to the writing on the HDD label.
If you have more than one HDD for this machine then just repeat the above steps for each disk.
If there source machine is using RAID then you first need to burn the clonezilla iso to cd or create a clonezilla live usb stick. Boot the source machine with clonezilla and copy the source HDD to a spare HDD first, then connect the spare HDD to your machine and copy that. Clonezilla does have options for network copy that may save a lot of extra work in this step, but I have not had time to explore them yet.
Boot the image with KVM
On first boot Windows will detect all the hardware changes and install drivers for them. Most emulated hardware in KVM already has drivers in Windows and I did not get prompted for any drivers etc.
kvm -m 512 -usb -usbdevice tablet -hda windowsxp.qcow2
Upon Windows detecting such hardware changes you will also need to reactivate Windows again too. If you are using libvirt then you can also create a new xml definition and manage the image that way.
If you had any static ip addresses defined in Windows these will need to be setup again too as Windows will have detected new network cards. For Ubuntu it is not so much that the network cards have changed but that the MAC address has changed and the new card is likely assigned to eth1 instead of eth0. If you still want the network card referred to as eth0 the edit /etc/udev/rules.d/70-persistent-net.rules and remove the two line referencing your old network card then reboot and your cards will be named correctly. Or just change /etc/network/interfaces to from eth0 to eth1 as appropriate.