VMDK镜像迁移到KVM(二)

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.

To create a new virtual machine from an existing file, call virt-install with the --import argument (see the virt-install manpage for details).

To use a .vmdk disk in an existing virtual machine, modify the VM's XML file in /etc/libvirt/qemu:

 ...
 <disk type='file' device='disk'>
      <driver name='qemu' type='vmdk'/>
      <source file='/var/lib/libvirt/images/diskname.vmdk'/>
      <target dev='hda' bus='ide'/>
 </disk>
 ...

and redefine it:  

$ virsh -c qemu:///system define NameOfMachine.xml

IMPORTANT: keep in mind that while the .vmx file is converted to .xml, the disks are used as-is. Please make backups, especially if you want to use the virtual machine in VMware later.

KVM is not able to make snapshots when using vmdk disk files, so converting the virtual disk file in qemu's qcow2 format is advisable. The qemu package contains a utility named qemu-img to do this:

qemu-img convert diskname.vmdk -O qcow2 diskname.qcow2
OR for raw
qemu-img convert diskname.vmdk -O raw diskname.raw

The converted image can be used as part of the definition of a new VM, or incorporated into an existing VM (see above). Adding the disk through virt-manager will always add it as a raw disk, so you will need to edit the xml as follows below to make sure it works with qcow2. The important bit is type='qcow2' instead of type='raw'!

...
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/.../diskname.qcow2'/>
      <target dev='hdb' bus='ide'/>
    </disk>
...

Should VMware Tools be kept after conversion?

If converting from vmware to libvirt, be sure to remove vmware-tools if you have it installed (otherwise it will overwrite xorg.conf on reboot)

 

posted on 2015-10-09 17:19  CasonChan  阅读(1342)  评论(0编辑  收藏  举报

导航