virt-v2v将Esxi虚拟机迁移到Openstack中

virt-v2v简介

virt-v2v是将外部的虚拟化平台上的虚拟机转化到可以运行的KVM平台上。
它可以读取在VMware、Xen运行Hyper-V和其他虚拟机管理程序上的Windows和Linux的虚拟机,并将其转换为KVM的libvirt,OpenStack等几种方式。
ESXI平台下线,将虚机迁移至openstack运行,但windows虚机,大多是存在驱动问题的,因此需要先考虑驱动问题。

virt-v2v安装

1
yum install -y qemu-kvm libvirt virt-manager virt-v2v

virt-v2v使用

1、查看EXSI主机虚机列表

1
virsh -c esx://root@EXSI_server_IP?no_verify=1 list --all 

EXSI_server_IP: EXSI 主机IP,需要输入服务器的root密码

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@controller ~]# virsh -c esx://root@10.200.115.55?no_verify=1 list --all
2024-03-27 03:55:58.375+0000: 25986: info : libvirt version: 4.5.0, package: 10.el7 (CentOS BuildSystem <http://bugs.centos.org>, 2018-10-31-00:13:25, x86-01.bsys.centos.org)
2024-03-27 03:55:58.375+0000: 25986: info : hostname: controller
2024-03-27 03:55:58.375+0000: 25986: warning : esxConnectOpen:857 : Ignoring unexpected path '' for non-vpx scheme 'esx'
Enter root's password for 10.200.115.55:
Id Name State
----------------------------------------------------
9 new28 running
12 Openstack-Train-Control running
14 Kd Security Labo running
- KDPA-SC shut off
- test shut off
- test-centos7 shut off

2、拷贝虚拟机到本地,拷贝完成后会在当前目录生成一个xml文件和disk1磁盘文件

1
virt-v2v-copy-to-local -ic esx://root@EXSI_server_IP?no_verify=1 vm_name

vm_name: 需要拷贝到本地的虚机名称(在步骤1中获取)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@controller data]# virt-v2v-copy-to-local -ic esx://root@10.200.115.55?no_verify=1 test-centos7
[ 0.0] Fetching the remote libvirt XML metadata ...
2024-03-27 03:58:07.008+0000: 26523: info : libvirt version: 4.5.0, package: 10.el7 (CentOS BuildSystem <http://bugs.centos.org>, 2018-10-31-00:13:25, x86-01.bsys.centos.org)
2024-03-27 03:58:07.008+0000: 26523: info : hostname: controller
2024-03-27 03:58:07.008+0000: 26523: warning : esxConnectOpen:857 : Ignoring unexpected path '' for non-vpx scheme 'esx'
Enter root's password for 10.200.115.55:
[ 4.0] Parsing the remote libvirt XML metadata ...
Enter host password for user 'root':
Enter host password for user 'root':
[ 11.3] Copying remote disk 1/1 to test-centos7-disk1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 10.0G 100 10.0G 0 0 85.0M 0 0:02:00 0:02:00 --:--:-- 87.4M
[ 131.7] Writing libvirt XML metadata to test-centos7.xml ...
[ 131.7] Finishing off

3、转换数据格式,把磁盘文件的格式转换成OpenStack能够识别的格式

1
virt-v2v -i libvirtxml vm_name.xml -o local -os /data/vms/ -of raw

-of: 转换为raw格式
-os: 指定输出路径
vm_name.xml: 为步骤2中生成的文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@controller data]# export LIBGUESTFS_BACKEND=direct;virt-v2v -i libvirtxml test-centos7.xml -o local -os /root/data/vms/ -of raw 
[ 0.0] Opening the source -i libvirtxml test-centos7.xml
[ 0.0] Creating an overlay to protect the source from being modified
[ 0.3] Initializing the target -o local -os /root/data/vms/
[ 0.3] Opening the overlay
[ 4.7] Inspecting the overlay
[ 16.9] Checking for sufficient free disk space in the guest
[ 16.9] Estimating space required on target for each disk
[ 16.9] Converting CentOS Linux release 7.5.1804 (Core) to run on KVM
virt-v2v: This guest has virtio drivers installed.
[ 75.7] Mapping filesystem data to avoid copying unused and blank areas
[ 75.9] Closing the overlay
[ 76.1] Checking if the guest needs BIOS or UEFI to boot
[ 76.1] Assigning disks to buses
[ 76.1] Copying disk 1/1 to /root/data/vms/test-centos7-sda (raw)
(100.00/100%)
[ 134.4] Creating output metadata
[ 134.4] Finishing off

4、将转换完成后的vm_name-sda文件上传至openstack中,启动新的虚机验证。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[root@controller vms]# openstack image create centos7-raw --file /root/data/vms/test-centos7-sda --disk-format raw --container-format bare --public
+------------------+------------------------------------------------------+
| Field | Value |
+------------------+------------------------------------------------------+
| checksum | e806c2c3b3b0645da2083b1296b75805 |
| container_format | bare |
| created_at | 2024-03-27T04:11:02Z |
| disk_format | raw |
| file | /v2/images/badc7372-6eae-4e43-ba01-95a6ac0e3c8a/file |
| id | badc7372-6eae-4e43-ba01-95a6ac0e3c8a |
| min_disk | 0 |
| min_ram | 0 |
| name | centos7-raw |
| owner | f2eaaa2489f54f9ebef74f454befb257 |
| protected | False |
| schema | /v2/schemas/image |
| size | 10737418240 |
| status | active |
| tags | |
| updated_at | 2024-03-27T04:13:48Z |
| virtual_size | None |
| visibility | public |
+------------------+------------------------------------------------------+

virt-v2v将Esxi虚拟机迁移到Openstack中
http://maitianxin.github.io/2024/03/27/vmware/virt-v2v/
作者
Matianxin
发布于
2024年3月27日
许可协议