Migrate KVM .img to VirtualBox .vdi

I am trying to migrate a VM from KVM to Virtualbox (win7 64bit). I was able to convert the disk image using these commands:

VBoxManage convertfromraw -format VDI XX.img XX.vdi

qemu-img convert -f qcow2 XX.img -O vdi XX.vdi

I also tried to convert first to raw then to vdi. Still when i mount the new disk to virtual box either under IDE or SATA controller. The system does not boot at all. Gives (windows loading files..) then reboots.

Any advice is much appreciated, I might be missing a detail.


Solution 1:

When you move the disk image, the installed OS is not aware of that, and it tries to boot with the drivers for the controllers of the previously used virtualization platform. Windows, when it cannot find the driver for the currently installed disk controller, BSOD's and reboots.

This is pretty much the same as moving a windows hard drive between different hardware platforms.

There can be two solutions - either use a v2v converter that can convert from KVM to VBox (I don't know of any, but if you do, please share), or inject the drivers into the VM's image before you start it in a new environment. The easiest way to do that would be to do the follwoing:

  • Before the conversion, in KVM, run mergeide.reg (you can find it on MS website and pretty much all over the internets)
  • Switch the boot disk under KVM to IDE, and start the VM up
  • If everything works, convert the image with qemu-img to a vbox format
  • Create a VM in VBox, with the first boot disk as IDE (not SATA or SCSI)
  • Attach the converted disk - the system should boot
  • Install the Vbox disk drivers (might have to attach a secondary
    small disk for them to take effect)
  • Switch the boot disk's interface to the desired controller type, and start the VM up again

Solution 2:

You should be able to run sysprep on the Windows VM before making the conversion. This tells Windows to check the drivers before loading because they will change.