Converting VMware to KVM / QCOW2

De Wiki do Bernardino
Ir para: navegação, pesquisa

There's lots of info on the net on achieving that, but I found it a bit too scattered, and had to combine instructions from multiple sources.

Converting VMware Virtual Disk Files

KVM has the ability to use VMware's .vmdk disk files directly, as long as the disk is wholly contained in a single vmdk file. However, VMware also allows splitting a disk into multiple smaller vmdk files, usually 2 GB each. KVM can't use these. You can convert these files into a single virtual disk file using vmware-vdiskmanager, included in the freely available VMware Server.

$ vmware-vdiskmanager -r <Name of split vmdk base file> -t 0 <Name of new single vmdk file>

IMPORTANT: before converting the disk files into a single disk file, you must first remove all snapshots (through the web interface if you were using VMware Server 2.0). Otherwise your merged disk will not be in the latest known state. Removing these snapshots can take quite some time, after which *-000001.vmdk - type of files may have disappeared from the file system.

Convert VMDK to QCOW2

Convert VMDKs (VM's disk), even when having multiple files, to qcow2 format (note: QVM/QEMU should be able to deal with vmdk files (multiple as well?), so possibly this step is redundant):

# qemu-img convert -O qcow2 <vmdk wildcard> <qcow2 file>

Convert VMDK to RAW

Convert VMDKs (VM's disk), even when having multiple files, to qcow2 format (note: QVM/QEMU should be able to deal with vmdk files (multiple as well?), so possibly this step is redundant):

# qemu-img convert -O raw <vmdk wildcard> <raw file>

Convert the vmx

Convert the vmx (VM's settings) to xml (requires vmware2libvirt tool found in virt-goodies package)

# vmware2libvirt -f <source.vmx> > file.xml

import the xml:

# virsh -c qemu:///system define file.xml


Caveats

While vmware2libvirt works well on simple virtual machines, there are limitations because .vmx files don't always contain enough information, and also because vmware2libvirt tries not to make too many assumptions about what it finds. A couple of things to look out for:

  • While vmware2libvirt attempts to detect a 64-bit guest, be sure that your 64-bit guest has in its .xml file:
 <os>
  <type arch='x86_64' machine='pc'>hvm</type>
  ...
 </os>

vmware2libvirt only detects and uses the first Ethernet interface found. Additional interfaces can be added from within virt-manager. Currently the first scsi disk is used if found, otherwise the first ide disk. Additional disks can be added from within virt-manager.

The converted virtual machine is hard-coded to use 1 CPU. This can be changed with:

 <vcpu>2</vcpu>

vmware2libvirt does not (and cannot) convert anything that was VMware-specific within the guest. See 'Guest Notes' below for more details.

Add qcow2 disk

re-add the disk as a qcow2 disk, steps:

  • Run virt-manager
  • You should see the new VM now, cool! Open it.
  • From the view menu, switch to 'details' mod
  • Remove the existing (VMDK) disk, and re-add the qcow2 disk instead:
  • Find the disk and remove it from the VM. Your probably want to make sure the checkbox for deleting the data is unchecked.
  • Add Hardware -> Storage -> Select "managed or other existing storage" -> Browse -> choose your qcow2 file
  • At "device type" select box, choose the proper type (IDE worked for me)
  • At "storage format" select box, choose 'qcow2'.
  • Click "Finish"