通过virt-v2v将VMware ESXi 5中的vm迁移至kvm中

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bobpen/article/details/53064291

环境说明

Vmware Esxi 5.5

virt-v2v 1.28

kvm host:Centos 7.2

vm:Windows Server 2003


       在很多文章中看见过通过virt-v2v连接esxi直接读取esxi中的数据,将数据迁移至kvm host中,但是查看man virt-v2v,virt-v2v不支持直接连接esxi,需要通过vCenter才行。


INPUT FROM VMWARE VCENTER SERVER
       Virt-v2v is able to import guests from VMware vCenter Server.


       vCenter 猊 5.0 is required.  Virt-v2v cannot import guests directly from an ESXi hypervisor.  If you don't have vCenter, using OVA is recommended instead (see "INPUT FROM VMWARE OVA" below).


       Virt-v2v uses libvirt for access to vCenter, and therefore the input mode should be -i libvirt.  As this is the default, you don't need to specify it on the command line.

   
       所以不能通过virt-v2v直接连接esxi读取数据,我们查看man virt-v2中INPUT FROM VMWARE OVA章节


INPUT FROM VMWARE OVA
       Virt-v2v is able to import guests from VMware's OVA (Open Virtualization Appliance) files.  Only OVAs exported from VMware vSphere will work.


   OVA: REMOVE VMWARE TOOLS FROM WINDOWS GUESTS
       For Windows guests, you should remove VMware tools before conversion.  Although this is not strictly necessary, and the guest will still be able to run, if you don't do this then the converted guest will complain on every boot.  The tools cannot be removed
       after conversion because the uninstaller checks if it is running on VMware and refuses to start (which is also the reason that virt-v2v cannot remove them).


       This is not necessary for Linux guests, as virt-v2v is able to remove VMware tools.


   OVA: CREATE OVA
       To create an OVA in vSphere, use the "Export OVF Template" option (from the VM context menu, or from the File menu).  Either "Folder of files" (OVF) or "Single file" (OVA) will work, but OVA is probably easier to deal with.  OVA files are really just
       uncompressed tar files, so you can use commands like "tar tf VM.ova" to view their contents.


   OVA: IMPORTING A GUEST
       To import an OVA file called "VM.ova", do;


        $ virt-v2v -i ova VM.ova -o local -os /var/tmp


       If you exported the guest as a "Folder of files", or if you unpacked the OVA tarball yourself, then you can point virt-v2v at the directory containing the files:


        $ virt-v2v -i ova /path/to/files -o local -os /var/tmp

       我们需要先将vm从vmware esxi导出,而后通过virt-v2v将ova导入至kvm中。

操作步骤


1. 我们需要在vm上安装一个ide驱动,在https://www.virtualbox.org/raw-attachment/wiki/Migrate_Windows/MergeIDE.zip连接可以下载,解压后,安装.bat文件。如果不安装

该文件,在vm迁移完成后,在kvm host端启动该vm的时候,系统会提示因为硬盘错误蓝屏。

2.连接vmware vsphere控制台将vm导出ova




3.将ova文件导入至kvm host中

[root@ovirt-host-227 home]# virt-v2v -i ova win2003-convert.ova -o local -os /home/pool1/ -of qcow2
[   0.0] Opening the source -i ova win2003-convert.ova
[   1.0] Creating an overlay to protect the source from being modified
[  16.0] Opening the overlay
[  19.0] Initializing the target -o local -os /home/pool1/
[  19.0] Inspecting the overlay
[  20.0] Checking for sufficient free disk space in the guest
[  20.0] Estimating space required on target for each disk
[  20.0] Converting Microsoft Windows Server 2003 to run on KVM
virt-v2v: warning: there are no virtio drivers available for this version 
of Windows (5.2 i386 unknown).  virt-v2v looks for drivers in 
/usr/share/virtio-win

The guest will be configured to use slower emulated devices.
virt-v2v: This guest does not have virtio drivers installed.
[  21.0] Mapping filesystem data to avoid copying unused and blank areas
[  21.0] Closing the overlay
[  21.0] Checking if the guest needs BIOS or UEFI to boot
[  21.0] Copying disk 1/1 to /home/pool1/win2003-convert-sda (qcow2)
    (100.00/100%)
[  49.0] Creating output metadata
[  49.0] Finishing off


这时候我们进入/home/pool1目录下面可以看见以下文件

-rw-r--r-- 1 root root 1917845504 Nov  7 21:19 win2003-convert-sda
-rw-r--r-- 1 root root       1069 Nov  7 20:43 win2003-convert.xml


我们查看xml

<?xml version='1.0' encoding='utf-8'?>
<domain type='kvm'>
  <name>win2003-convert</name>
  <memory unit='KiB'>1048576</memory>
  <currentMemory unit='KiB'>1048576</currentMemory>
  <vcpu>1</vcpu>
  <os>
    <type arch='x86_64'>hvm</type>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' cache='none'/>
      <source file='/home/pool1/win2003-convert-sda'/>
      <target dev='hda' bus='ide'/>
    </disk>
    <disk device='cdrom' type='file'>
      <driver name='qemu' type='raw'/>
      <target dev='hdb' bus='ide'/>
    </disk>
    <interface type='network'>
      <source network='Ethernet 1'/>
      <model type='rtl8139'/>
    </interface>
    <video type='qxl' ram='65536' heads='1'/>
    <graphics type='vnc' autoport='yes' port='-1'/>
    <input type='tablet' bus='usb'/>
    <input type='mouse' bus='ps2'/>
    <console type='pty'/>
  </devices>
</domain>



我们主要修改网卡部分

a.修改网卡source network 为vdsm-ovirtmgmt

b.修改网卡使用virtio

网卡修改后如下:

  <interface type='network'>
      <source network='vdsm-ovirtmgmt'/>
      <model type='virtio'/>
    </interface>

启动vm
#virsh define win2003-convert.xml
#virsh start win2003-convert

启动后,会提示更新网卡驱动,根据Centos7下通过virt-p2v虚拟化windows Server 2008R2中的操作步骤可以更新网卡驱动。

在更新完成驱动后,设置网卡ip与原来在vmware esxi中相同的时候,系统会提示如下该ip已经被计算机的另一个网卡占用,但是另一个网卡在系统中被隐藏。

我们需要做的时候在注册表中删除该ip信息,在HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/Tcpip/Parameters/Interfaces中找到源ip的数值,并删除那条

注册表信息即可,重新设置ip为原来的ip地址就可以了










展开阅读全文

没有更多推荐了,返回首页