第一种方法:直接迁移
    1、开启ESXI上的ssh服务和ESXI Shell服务。
    ESXI5.5如下:
    image.png
    ESXI6.7如下:
    image.png

    2、配置KVM到ESXI免密认证

    1. [root@SIT-KVM01 ~]# ssh-keygen
    2. Generating public/private rsa key pair.
    3. Enter file in which to save the key (/root/.ssh/id_rsa):
    4. Created directory '/root/.ssh'.
    5. Enter passphrase (empty for no passphrase):
    6. Enter same passphrase again:
    7. Your identification has been saved in /root/.ssh/id_rsa.
    8. Your public key has been saved in /root/.ssh/id_rsa.pub.
    9. The key fingerprint is:
    10. SHA256:Cd2XpDjQiR0Nz1eGRDcJhQFm6hyapIXLQ3BeAzRectk root@SIT-KVM01
    11. The key's randomart image is:
    12. +---[RSA 2048]----+
    13. | ...o=++. |
    14. | = Bo+EO.oo=.. |
    15. | = + * = + |
    16. | o = * + o |
    17. | = o S |
    18. | . |
    19. | |
    20. | |
    21. | |
    22. +----[SHA256]-----+
    23. [root@SIT-KVM01 ~]# ssh-copy-id -i .ssh/id_rsa.pub 10.xxx.128.145
    24. /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: ".ssh/id_rsa.pub"
    25. The authenticity of host '10.xxx.128.145 (10.xxx.128.145)' can't be established.
    26. RSA key fingerprint is SHA256:DUhcdrc8dWdwMVv6RwOQs9AVjonPqIFwD7kumhURcjQ.
    27. RSA key fingerprint is MD5:86:2f:b2:02:e4:75:6b:13:3e:ec:32:48:c9:01:85:d3.
    28. Are you sure you want to continue connecting (yes/no)? yes
    29. /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
    30. /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
    31. Password:
    32. Number of key(s) added: 1
    33. Now try logging into the machine, with: "ssh '10.xxx.128.145'"
    34. and check to make sure that only the key(s) you wanted were added.
    35. [root@SIT-KVM01 ~]#

    3、调整ESXI中上一步添加的KEY认证文件

    1. [root@SIT-KVM01 ~]# ssh 10.xxx.128.145
    2. Password:
    3. The time and date of this login have been sent to the system logs.
    4. VMware offers supported, powerful system administration tools. Please
    5. see www.vmware.com/go/sysadmintools for details.
    6. The ESXi Shell can be disabled by an administrative user. See the
    7. vSphere Security documentation for more information.
    8. ~ # cd /etc/ssh/
    9. /etc/ssh # ls
    10. keys-root moduli ssh_host_dsa_key ssh_host_dsa_key.pub ssh_host_rsa_key ssh_host_rsa_key.pub sshd_config
    11. /etc/ssh # cd keys-root/
    12. /etc/ssh/keys-root # ls
    13. authorized_keys
    14. /etc/ssh/keys-root # cd
    15. ~ # cat .ssh/authorized_keys >> /etc/ssh/keys-root/authorized_keys
    16. ~ # exit
    17. Connection to 10.xxx.128.145 closed.
    18. [root@SIT-KVM01 ~]# ssh 10.xxx.128.145
    19. The time and date of this login have been sent to the system logs.
    20. VMware offers supported, powerful system administration tools. Please
    21. see www.vmware.com/go/sysadmintools for details.
    22. The ESXi Shell can be disabled by an administrative user. See the
    23. vSphere Security documentation for more information.
    24. ~ #

    4、开始迁移,(注:迁移前需要将虚拟机关机,虚拟机路径里面不要包含空格,中文字符,否则汇报URI错误)。

    1. [root@SIT-KVM01 ~]# eval `ssh-agent`
    2. Agent pid 30714
    3. [root@SIT-KVM01 ~]# ssh-add .ssh/id_rsa
    4. Identity added: .ssh/id_rsa (.ssh/id_rsa)
    5. [root@SIT-KVM01 ~]# export LIBGUESTFS_BACKEND=direct
    6. [root@SIT-KVM01 vmfs]# virt-v2v -i vmx -it ssh "ssh://root@10.xxx.128.145/vmfs/volumes/553503c1-37053e17-f472-a0369f6/d1search02--10.xxx.128.55/d1search02--10.xxx.128.55.vmx" -os vmfs -of qcow2 --bridge br128
    7. [ 0.0] Opening the source -i vmx ssh://root@10.xxx.128.145/vmfs/volumes/553503c1-37053e17-f472-a0369f677064/d1searc
    8. [ 0.6] Creating an overlay to protect the source from being modified
    9. [ 1.0] Opening the overlay
    10. [ 5.6] Inspecting the overlay
    11. [ 19.4] Checking for sufficient free disk space in the guest
    12. [ 19.4] Estimating space required on target for each disk
    13. [ 19.4] Converting Red Hat Enterprise Linux Server release 6.5 (Santiago) to run on KVM
    14. virt-v2v: This guest has virtio drivers installed.
    15. [ 110.6] Mapping filesystem data to avoid copying unused and blank areas
    16. [ 112.1] Closing the overlay
    17. [ 112.2] Assigning disks to buses
    18. [ 112.2] Checking if the guest needs BIOS or UEFI to boot
    19. [ 112.2] Initializing the target -o libvirt -os vmfs
    20. [ 112.2] Copying disk 1/1 to /vmfs/d1search02--10.xxx.128.55-sda (qcow2)
    21. (100.00/100%)
    22. [2321.3] Creating output metadata
    23. Pool vmfs refreshed
    24. Domain d1search02--10.xxx.128.55 defined from /tmp/v2vlibvirt56ad9d.xml
    25. [2321.4] Finishing off
    26. [root@SIT-KVM01 ~]# virt-v2v -i vmx -it ssh "ssh://root@10.xxx.128.145/vmfs/volumes/553503c1-37053e17-f472-a0369f677064/sitdns2 --10.xxx.128.203/sitdns2 --10.xxx.128.203.vmx" -os vmfs -of qcow2 --bridge br128
    27. [ 0.0] Opening the source -i vmx ssh://root@10.xxx.128.145/vmfs/volumes/553503c1-37053e17-f472-a0369f677064/sitdns2 --10.xxx.128.203/sitdns2 --10.xxx.128.203.vmx
    28. virt-v2v: error: remote vmx
    29. ssh://root@10.xxx.128.145/vmfs/volumes/553503c1-37053e17-f472-a0369f677064/sitdns2
    30. --10.xxx.128.203/sitdns2 --10.xxx.128.203.vmx could not be parsed as a
    31. URI

    5、查看迁移完成的虚拟机。

    1. [root@SIT-KVM01 ~]# virsh list --all
    2. Id Name State
    3. ----------------------------------------------------
    4. 1 d1test-10.xxx.128.213 running
    5. 2 d1rongyiwang-10.xxx.128.135 running
    6. 3 d1search02--10.xxx.128.55 running
    7. 4 D1openAPI--10.xxx.128.239--IBM running
    8. 5 d1search04-10.xxx.128.136 running

    第二种方法:将虚拟机导出为OVF模板,然后转换为KVM。

    1. [root@SIT-KVM01 OVF]# virt-v2v -i ova 'sitdns2 --10.xxx.128.203' -os vmfs -of qcow2 -b br128
    2. [ 0.0] Opening the source -i ova sitdns2 --10.xxx.128.203
    3. [ 6.4] Creating an overlay to protect the source from being modified
    4. [ 6.5] Opening the overlay
    5. [ 10.1] Inspecting the overlay
    6. [ 21.5] Checking for sufficient free disk space in the guest
    7. [ 21.5] Estimating space required on target for each disk
    8. [ 21.5] Converting Red Hat Enterprise Linux Server release 6.5 (Santiago) to run on KVM
    9. virt-v2v: This guest has virtio drivers installed.
    10. [ 83.2] Mapping filesystem data to avoid copying unused and blank areas
    11. [ 85.5] Closing the overlay
    12. [ 85.5] Assigning disks to buses
    13. [ 85.5] Checking if the guest needs BIOS or UEFI to boot
    14. [ 85.5] Initializing the target -o libvirt -os vmfs
    15. [ 85.6] Copying disk 1/1 to /vmfs/sitdns2 --10.xxx.128.203-sda (qcow2)
    16. (100.00/100%)
    17. [ 247.0] Creating output metadata
    18. Pool vmfs refreshed
    19. Domain sitdns2 --10.xxx.128.203 defined from /tmp/v2vlibvirt3a4adb.xml
    20. [ 247.0] Finishing off
    21. [root@SIT-KVM01 OVF]# virsh list --all
    22. Id Name State
    23. ----------------------------------------------------
    24. 1 d1test-10.xxx.128.213 running
    25. 2 d1rongyiwang-10.xxx.128.135 running
    26. 3 d1search02--10.xxx.128.55 running
    27. 4 D1openAPI--10.xxx.128.239--IBM running
    28. 5 d1search04-10.xxx.128.136 running
    29. 6 d1search03--10.xxx.128.56 running
    30. 7 sitdns2 --10.xxx.128.203 running

    第三种方法:将虚拟机导出为OVF模板,然后将磁盘文件转换为KVM磁盘文件格式,再导入KVM。

    1. [root@SIT-KVM01 OVF]#qemu-img convert -f vmdk -O qcow2 redhat-6.5--10.xxx.128.136-disk1.vmdk redhat-6.5--10.xxx.128.136-disk1.qcow2
    2. [root@SIT-KVM01 OVF]#virt-manager

    image.png
    https://access.redhat.com/articles/1353463

    查看KVM支持machine列表
    root@sit-kvm04:/vmfs# /usr/libexec/qemu-kvm -M help
    Supported machines are:
    microvm microvm (i386)
    pc-i440fx-zesty Ubuntu 17.04 PC (i440FX + PIIX, 1996)
    pc-i440fx-yakkety Ubuntu 16.10 PC (i440FX + PIIX, 1996)
    pc-i440fx-xenial Ubuntu 16.04 PC (i440FX + PIIX, 1996)
    pc-i440fx-wily Ubuntu 15.04 PC (i440FX + PIIX, 1996)
    pc-i440fx-trusty Ubuntu 14.04 PC (i440FX + PIIX, 1996)
    ubuntu Ubuntu 20.04 PC (i440FX + PIIX, 1996) (alias of pc-i440fx-focal)
    pc-i440fx-focal Ubuntu 20.04 PC (i440FX + PIIX, 1996) (default)
    pc-i440fx-focal-hpb Ubuntu 20.04 PC (i440FX + PIIX +host-phys-bits=true, 1996)
    pc-i440fx-eoan Ubuntu 19.10 PC (i440FX + PIIX, 1996)
    pc-i440fx-eoan-hpb Ubuntu 19.10 PC (i440FX + PIIX +host-phys-bits=true, 1996)

    排错一
    root@sit-kvm04:/vmfs# virsh start D1ConfigManage—10.201.129.126
    error: Failed to start domain D1ConfigManage—10.201.129.126
    error: internal error: qemu unexpectedly closed the monitor: 2020-12-24T02:40:06.716466Z qemu-system-x86_64: -blockdev {“driver”:”file”,”filename”:”/vmfs/D1ConfigManage—10.201.129.126-sda”,”node-name”:”libvirt-2-storage”,”cache”:{“direct”:true,”no-flush”:false},”auto-read-only”:true,”discard”:”unmap”}: Could not open ‘/vmfs/D1ConfigManage—10.201.129.126-sda’: Permission denied







    修改为