Converting VMware ESXi Linux VM to KVM (virt-v2v)


1. Install package virt-v2v

$ yum install virt-v2v 

위와 같이 virt-v2v package 를 설치 합니다.

2. ESXi - KVM 간 ssh key 인증 설정

KVM 호스트에서 ESXi 의 데이터스토어에 Password 없이 접근이 가능하도록 설정을 해야 virt-v2v 를 이용하여 VM 을 이관 할 수 있습니다.

+ VMware ESXi ssh Daemon 시작

위와 같이 ESXi Web Console 에서 작업 > 서비스 > SSH 사용 선택

+ KVM, ssh-keygen 명령 수행

[root@testh ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:bj7DLUsbaRSeVu299zzPOKKpuK88cnjZi0UxxZSSxqE root@testh.example.com
The key`s randomart image is:
+---[RSA 2048]----+
|       ..=o.     |
|       .=.o.     |
|      E.+.. .    |
|       . * . .   |
|        S   . .  |
|       = .     . |
|     . +O.    . .|
|    o.=O*o... .*.|
|     +*=BBo. ...B|
+----[SHA256]-----+
[root@testh ~]#
  • 생성된 key 확인 진행
    [root@testh ~]# cat /root/.ssh/id_rsa.pub
    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDYVu7UYN39ue2UqAlH1D+wNTnKM6z8/JloAG0Om8w9vUTGuowXLHTRV9CGIcQ4NfGiUI/lqI2XV+ZY4XeGCE2H5LWDagRGCutJ9vh5/D3FGIEMOGez7qXdJm8/3xrhRa56rY9ie1NFGLpoi9Lkka/6Z48CJ20vvb9vJWZdX91WGkT8G0L5nv3B3JzCrY4VxYOYmxTwmu13DOeW0bbLs08pWWrbL10cIIP76NhZJG98wulQQYDo9091lqOGUsMQ1WQudw3ggIMxZ3N9eU+0nrpfsO5yKAOlRn9fQUYXFWaED1FKyOFYwYq26x8R9o/CMyQEfETv2Em2+sto7aSyK1eh root@testh.example.com
    

+ ESXi 에 KVM ssh key 등록

[root@testh ~]# scp /root/.ssh/id_rsa.pub 192.168.13.6:/etc/ssh/keys-root/
Password:
id_rsa.pub                                             100%  404     1.3MB/s   00:00
[root@testh ~]#

key 를 ESXi 에 /etc/ssh/keys-root/ 에 복사합니다.

[root@testh ~]# ssh root@192.168.13.6
Password:
The time and date of this login have been sent to the system logs.

VMware offers supported, powerful system administration tools.  Please
see www.vmware.com/go/sysadmintools for details.

The ESXi Shell can be disabled by an administrative user. See the
vSphere Security documentation for more information.
[root@esxi4:~]
[root@esxi4:~] cd /etc/ssh/keys-root/
[root@esxi4:/etc/ssh/keys-root] ls
id_rsa.pub
[root@esxi4:/etc/ssh/keys-root] mv id_rsa.pub authorized_keys
[root@esxi4:/etc/ssh/keys-root] chmod 600 authorized_keys

위와 같이 authorized_keys 로 이름을 수정하거나, id_rsa.pub key 의 내용을 authorized_keys 에 추가하는 방법도 괜찮습니다.

3. virt-v2v 수행

[root@testh ~]# export LIBGUESTFS_BACKEND=direct
[root@testh ~]# virt-v2v -i vmx -it ssh "ssh://root@192.168.13.6/vmfs/volumes/NT_datastore/mtest1/mtest1.vmx"
[   0.0] Opening the source -i vmx ssh://root@192.168.13.6/vmfs/volumes/NT_datastore/mtest1/mtest1.vmx
[   0.7] Creating an overlay to protect the source from being modified
[   1.6] Opening the overlay
[   8.1] Inspecting the overlay
[  17.2] Checking for sufficient free disk space in the guest
[  17.2] Estimating space required on target for each disk
[  17.2] Converting CentOS Linux release 7.4.1708 (Core)  to run on KVM
virt-v2v: This guest has virtio drivers installed.
[  83.0] Mapping filesystem data to avoid copying unused and blank areas
[  83.9] Closing the overlay
[  84.0] Assigning disks to buses
[  84.0] Checking if the guest needs BIOS or UEFI to boot
[  84.0] Initializing the target -o libvirt -os default
[  84.0] Copying disk 1/2 to /var/lib/libvirt/images/mtest1-sda (raw)
    (100.00/100%)
[ 193.6] Copying disk 2/2 to /var/lib/libvirt/images/mtest1-sdb (raw)
    (100.00/100%)
[ 346.7] Creating output metadata
풀 default가 새로고침 되었습니다

mtest1에서 정의된 도메인 /tmp/v2vlibvirtc84a5d.xml

[ 346.8] Finishing off

[root@testh ~]# virsh list --all
 Id    이름                         상태
----------------------------------------------------
 2     centos7.0                      실행중
 -     mtest1                         종료
 -     testvm                         종료

[root@testh ~]# virsh edit mtest1
도메인 mtest1 XML 설정이 편집되었습니다.

위와 같이 convert 작업을 수행합니다.
convert 작업 이후, virsh edit <VM name> 명령을 수행하여 아래와 같이 KVM 환경에 맞게 네트워크 정보를 수정합니다.

+ 예제

... 중략 ...

--<interface type='network'>
++<interface type='bridge'>
--        <source network='default'/>
++        <source bridge='br0'/>
      <model type='virtio'/>

... 중략 ...
  • VM 시작
    [root@testh ~]# virsh  start mtest1
    도메인 mtest1가 시작됨
    

    VM 부팅 후 /etc/sysconfig/network-scripts/ifcfg-XXX 파일을 KVM 환경에 맞게 수정합니다.

이관 완료!

참고 자료


chhanz's profile image

chhanz

2019-10-22

Read more posts by this author