【v2v迁移】Xen2kvm 迁移-linux篇

发布时间 2023-10-07 17:10:31作者: wang272

迁移环境:

源平台:华为FusionComputeV100R006C10SPC101
目标平台:基于KVM虚拟化的云平台,本文以原生的libvirt为例
虚拟机:centos 7.6

具体操作步骤:

1、在源平台导出格式为ovf的磁盘镜像

导出后,得到vhd文件:centos_xen-1.vhd。将该文件传输到一个装有libvirt和相关工具套件的Linux环境上,本文所使用的是一台centos7.6物理机,部署了GUI界面,安装了libvirt libvirt-client qemu-img virt-manager等工具。

2、下载华为自研的qemu-img-hw命令

解压得到命令,为命令赋予执行权限:

[root@hyperhost ~ ]$ unzip qemu-img-hw.zip
[root@hyperhost ~ ]$ cd qemu-img-hw.zip
[root@hyperhost ~ ]$ chmod a+x qemu-img-hw

使用该命令查看导出vhd文件格式:
华为公有云文档描述:zvhd和zvhd2是云服务内部自研格式,qemu-img工具无法识别这两种格式的镜像文件,需要使用华为自研的qemu-img-hw工具:

[root@hyperhost ~ ]$ ./qemu-img-hw info centos_xen-1.vhd
image: centos_xen-1.vhd
file format: zvhd
virtual size: 100G (107374182400 bytes)
disk size: 769M

如果使用原生的qemu-img命令查看镜像格式,会显示raw,会误导用户接下来错误的执行转换命令:

[root@hyperhost ~]$ qemu-img info centos_xen-1.vhd
image: centos_xen-1.vhd
file format: raw
virtual size: 769M (806404096 bytes)
disk size: 769M

3、将zvhd格式转换为qcow2格式

转换时间依数据量而定

[root@hyperhost ~]$ ./qemu-img-hw convert -p -f zvhd -O qcow2 centos_xen-1.vhd centos_xen.qcow2
    (100.00/100%)

# 转换成功:
[root@hyperhost ~]$ qemu-img info centos_xen.qcow2
image: centos_xen.qcow2
file format: qcow2
virtual size: 100G (107374182400 bytes)
disk size: 1.6G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

4、部署为kvm虚拟机

本文使用virt-manager将qcow2磁盘部署为虚拟机:

5、启动虚拟机,处理故障

本虚拟机安装时使用了lvm逻辑卷,会报此卡在启动界面:

超时后提示用户,找不到逻辑卷:

重启:

按鼠标下键,进入rescue kernel:

重建initramfs文件,扫描vg,激活vg,重启虚拟机
先尝试重建initramfs文件,如果不行再尝试扫描、激活vg。

# 重建initramfs文件
[root@localhost ~]# dracut -f

# 扫描vg
[root@localhost ~]# lvm vgscan

# 激活vg
[root@localhost ~]# lvm vgchange -ay

# 重启
[root@localhost ~]# init 6

以默认内核启动

启动正常: