- 博客/
VMware虚拟机迁移KVM部署
·599 字·3 分钟
Linux
KVM
VMware
部分服务器是由VMware虚拟化平台创建,平台版本低维护困难,需要迁移至libvirt管理的KVM环境。由于服务器部署的服务年代久远,重新部署有困难,需使用virt-v2v工具一键迁移
VMware虚拟机列表#
libvirt服务器作为客户端可以查看VMware ESXi hypervisor虚拟机列表
[root@kvmpool-1] ~$ virsh -c 'esx://root@192.168.81.12/?no_verify=1' list --all
Enter root's password for 192.168.81.12:
Id Name State
-------------------------------------------------------
80 test-win7 running
基于SSH协议传输模式#
SSH传输模式的限制:VMware快照会生成一系列增量VMDK文件(如 guest-000001.vmdk),形成父子磁盘链。使用 -it ssh 选项时,工具仅能通过 SSH 读取 guest.vmx 中直接引用的磁盘文件,无法自动遍历快照链中的子磁盘,导致数据不完整。建议使用 VMware 管理工具(如 vSphere Client)删除所有快照(此操作会自动触发磁盘合并)
命令参数
virt-v2v -i vmx
-it ssh
-ip passwordfile
'ssh://root@esxi.example.com/vmfs/volumes/datastore1/guest/guest.vmx'
[-o* options]
登录ESXi服务器,在目录/vmfs/volumes
获取虚拟机文件guest.vmx
位置
启动ssh-agent并配置免密登录#
#登录ESXi导入kvmpool-1的ssh公钥
~ # cat /etc/ssh/keys-root/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC60+w7myFW/2lPu8uY/v7xvys7wOqHXJvQHLE8mRrG5+cTDW4dhCaydszzzjYxaoTJw7kap9/gtgK9LOxWlXM7sS0ZcewSMJVIKA4Lht6RzQRHyfxxYWIt+jT/hG3BEtI4wsrxH3FQLqEmVsPwqVOPqf2DfVVtIIcM+nslzVFRhYjg1zfk+2Qi5Vp8kAyVBMT0ZHJiMacO+OsCvEIDqDNRP7ZcHepyggg/gsSAWeP8csIxduoUqaiZDZdiDP2/bhN1dW7VYtUQZZUpJa3cTuDQTcRFlro83gyWw7DHG8Iw8PBV7sG+0hetLkx1mwiUdy5WYkaT5k4Csl4Iqk0p+/F1 root@kvmpool-1
#kvmpool-1 libvirt服务器上启动ssh-agent
[root@kvmpool-1 ~]# ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-MaNJWfPV5ItN/agent.191357; export SSH_AUTH_SOCK;
SSH_AGENT_PID=191358; export SSH_AGENT_PID;
echo Agent pid 191358;
[root@kvmpool-1 ~]# export SSH_AUTH_SOCK=/tmp/ssh-MaNJWfPV5ItN/agent.191357
[root@kvmpool-1 ~]# export LIBGUESTFS_BACKEND=direct
[root@kvmpool-1 ~]# ssh-add ~/.ssh/id_rsa
Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)
开启传输任务#
# -of 参数可以指定镜像格式,默认row格式的
[root@kvmpool-1 ~]# virt-v2v -i vmx -it ssh "ssh://root@192.168.81.12/vmfs/volumes/datastore1/test-win7/test-win7.vmx" -o local -os /data0/instances/
[ 0.0] Opening the source -i vmx ssh://root@192.168.81.12/vmfs/volumes/datastore1/test-win7/test-win7.vmx
[ 0.8] Creating an overlay to protect the source from being modified
[ 1.4] Opening the overlay
[ 6.2] Inspecting the overlay
[ 17.0] Checking for sufficient free disk space in the guest
[ 17.0] Estimating space required on target for each disk
[ 17.0] Converting Windows 7 Ultimate to run on KVM
virt-v2v: warning: /usr/share/virt-tools/pnp_wait.exe is missing.
Firstboot scripts may conflict with PnP.
virt-v2v: This guest has virtio drivers installed.
[ 27.7] Mapping filesystem data to avoid copying unused and blank areas
[ 28.6] Closing the overlay
[ 28.7] Assigning disks to buses
[ 28.7] Checking if the guest needs BIOS or UEFI to boot
[ 28.7] Initializing the target -o local -os huorong
[ 28.7] Copying disk 1/1 to /data0/instances/test-win7-sda (raw)
(100.00/100%)7/100%)
[1182.1] Creating output metadata
[1182.1] Finishing off
#转换后的虚拟机镜像文件和libvirt domain xml文件
[root@kvmpool-1 ~]# ls /data0/instances
test-win7-sda
test-win7-sda.xml
任务完成后,可以转换镜像row格式为qcow2,使用virt-install启动虚拟机
基于 VDDK 传输模式#
使用 VMware 专有 VDDK 库( VixDiskLib)导入虚拟机要求
- 许可证限制 ,需自行从 VMware获取 VDDK库
- nbdkit ≥ 1.6
- 获取 VMware 服务器的 SSL 证书指纹(Thumbprint)
- libvirt ≥ 3.7
命令参数
virt-v2v
-ic 'vpx://root@vcenter.example.com/Datacenter/esxi?no_verify=1'
-it vddk
-io vddk-libdir=/path/to/vmware-vix-disklib-distrib
-io vddk-thumbprint=xx:xx:xx:...
"GUEST NAME"
[-o* options]
下载VDDK库#
[root@kvmpool-1 ~]# tar xf VMware-vix-disklib-8.0.1-21562716.x86_64.tar.gz -C /usr/local
获取VMware服务器的SSL指纹#
~ # ls /etc/vmware/ssl/rui.crt
/etc/vmware/ssl/rui.crt
~ # openssl x509 -in /etc/vmware/ssl/rui.crt -fingerprint -sha1 -noout
SHA1 Fingerprint=XX:XX:XX:XX:XX:XX:XX:XX:XX
开启传输#
[root@kvmpool-1 ] ~$ virt-v2v -ic 'esx://root@192.168.81.12/?no_verify=1' -it vddk -io vddk-libdir=/usr/local/vmware-vix-disklib-distrib/ -io vddk-thumbprint=XX:XX:XX:XX:XX:XX:XX:XX:XX test-win7 -o local -os /data0/instances/
[ 0.0] Setting up the source: -i libvirt -ic esx://root@192.168.81.12/?no_verify=1 -it vddk test-win7
Enter root's password for 192.168.81.12:
password:
[ 7.3] Opening the source
[ 15.5] Inspecting the source
[ 20.8] Checking for sufficient free disk space in the guest
[ 20.8] Converting Windows 7 Ultimate to run on KVM
virt-v2v: This guest has virtio drivers installed.
[ 25.9] Mapping filesystem data to avoid copying unused and blank areas
[ 26.5] Closing the overlay
[ 26.8] Assigning disks to buses
[ 26.8] Checking if the guest needs BIOS or UEFI to boot
[ 26.8] Setting up the destination: -o disk -os /data0/instances/
[ 31.7] Copying disk 1/1
nbdkit: error: [NFC ERROR]NfcFssrvr_IOEx: Received unexpected message: NFC_SESSION_COMPLETE from server. Expected message: NFC_FSSRVR_IO_EX
nbdkit: error: command 3: asynchronous read failed: Unknown error
nbdkit: vddk[3]: error: [NFC ERROR]NfcNetTcpSetError: Broken pipe
nbdkit: vddk[3]: error: [NFC ERROR]NfcNetTcpWrite: bWritten: -1. Errno: 32.
nbdkit: vddk[3]: error: [NFC ERROR]NfcSendMessage: NfcNet_Send failed: NFC_NETWORK_ERROR
nbdkit: vddk[3]: error: [NFC ERROR]NfcFssrvrSendDDBMessage: Failed to send NFC_FSSRVR_DDBGET message: The operation experienced a network error (NFC_NETWORK_ERROR)
nbdkit: vddk[3]: error: SSL: Unknown SSL Error
nbdkit: vddk[3]: error: [NFC ERROR]NfcNetTcpSetError: Success
nbdkit: vddk[3]: error: [NFC ERROR]NfcNetTcpWrite: bWritten: -1. Errno: 0.
nbdkit: vddk[3]: error: [NFC ERROR]NfcSendMessage: NfcNet_Send failed: NFC_NETWORK_ERROR
nbdkit: vddk[3]: error: [NFC ERROR]NfcFssrvr_Close: Failed to send close message: The operation experienced a network error (NFC_NETWORK_ERROR)
nbdkit: vddk[3]: error: [NFC ERROR]NfcNetTcpSetError: Success
nbdkit: vddk[3]: error: [NFC ERROR]NfcNetTcpWrite: bWritten: -1. Errno: 0.
nbdkit: vddk[3]: error: [NFC ERROR]NfcSendMessage: NfcNet_Send failed: NFC_NETWORK_ERROR
█ 100% [****************************************]
[ 846.4] Creating output metadata
[ 846.4] Finishing off
#error可以忽略 https://bugzilla.redhat.com/show_bug.cgi?id=1709211
使用VMware的专有VDDK库速度最快,可以缩短30%的时间
Related
kvm虚拟机磁盘扩容
·2036 字·10 分钟
KVM
Linux
WindowsServer
一次请求超时问题排查记录
·1906 字·9 分钟
Linux
TCP
bpftrace
kvm部署WindowsServer2019
·692 字·4 分钟
KVM
WindowsServer