迁移exsi下的虚拟机到openstack

检查virtio驱动

  • 检查虚拟机内核是否支持virtio驱动
1
2
3
# grep -E -i "VIRTIO_BLK|VIRTIO_NET" /boot/config-$(uname -r)
CONFIG_VIRTIO_BLK=m
CONFIG_VIRTIO_NET=m
  • 如果在输出信息中没有找到VIRTIO_BLK及VIRTIO_NET的信息,表示该操作系统没有安装virtio相关驱动,需要编译安装virtio驱动
  • 如果参数CONFIG_VIRTIO_BLKCONFIG_VIRTIO_NET取值为y,表示包含了virtio驱动,可直接迁移到kvm环境
  • 如果参数CONFIG_VIRTIO_BLKCONFIG_VIRTIO_NET取值为m,需要检查virtio驱动是否加入initramfs,否则需要修复initramfs
1
# lsinitrd /boot/initramfs-$(uname -r).img | grep virtio

修复initramfs

如果initramfs中未包含virtio驱动,且实例launch时指定以virtio方式启动,则会导致无法加载磁盘启动失败。

1
2
3
4
5
6
7
8
9
10
# mkinitrd -f --allow-missing --with=virtio_blk --preload=virtio_blk --with=virtio_pci --preload=virtio_pci --with=virtio_console --preload=virtio_console  /boot/initramfs-$(uname -r).img $(uname -r)

# lsinitrd /boot/initramfs-$(uname -r).img | grep virtio
Arguments: -f --add-drivers ' virtio_blk virtio_blk virtio_pci virtio_pci virtio_console virtio_console'
-rw-r--r-- 1 root root 27853 Nov 20 2015 usr/lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/block/virti_blk.ko
-rw-r--r-- 1 root root 53533 Nov 20 2015 usr/lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/char/virtio_console.ko
drwxr-xr-x 2 root root 0 Sep 28 15:09 usr/lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/virtio
-rw-r--r-- 1 root root 17989 Nov 20 2015 usr/lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/virtio/virtio.ko
-rw-r--r-- 1 root root 35461 Nov 20 2015 usr/lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/virtio/virtio_pci.ko
-rw-r--r-- 1 root root 22757 Nov 20 2015 usr/lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/virtio/virtio_ring.ko

拷贝vmdk文件并转化为qcow2

如果exsi下的磁盘使用了精简置备,则会生成2个vmdk文件,分别是<vm-name>.vmdk<vm-name>-flat.vmdk需要同时拷贝2个,但转化时指定<vm-name>.vmdk
另外即使使用精简置备,但创建的磁盘属于稀疏文件,因此远程拷贝的时候实际仍然是创建的磁盘大小

1
2
# qemu-img convert -f vmdk -O qcow2 Ops-Base-Kanboard-151.vmdk vmware.qcow2
# openstack image create --file vmware.qcow2 --disk-format qcow2 --container-format bare --public vmware

trouble shooting


由于迁移过来的实例磁盘比较大,如果以boot from volume方式启动实例,可能会导致下载image到volume超时,出现如下报错。需要在nova.conf配置文件中修改block_device_allocate_retries参数(默认60),并重启nova相关服务

1
Build of instance 3af65fea-00c3-4593-80fc-d6a373cf93b3 aborted: Volume d26a4479-24e3-4dd0-88d6-d0c47f73747f did not finish being created even after we waited 201 seconds or 61 attempts. And its status is downloading.

由于OpenStack中Neutron使用的是vxlan的网络类型,而其对应的默认MTU是1450,但是迁移过来的实例未安装cloud-init,无法初始化MTU配置,将会导致ssh时卡在debug1: SSH2_MSG_KEXINIT sent而无法登录,需要手动修改实例的MTU值
关于Neutron网络的MTU可参考 Neutron VxLAN + Linux Bridge 环境中的网络 MTU

1
2
3
4
5
6
7
8
9
10
# ip link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether fa:16:3e:a2:21:ec brd ff:ff:ff:ff:ff:ff

# vi /etc/sysconfig/network-scripts/ifcfg-eth0
MTU=1450
# systemctl restart network
# ip link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether fa:16:3e:a2:21:ec brd ff:ff:ff:ff:ff:ff
坚持原创技术分享,您的支持将鼓励我继续创作!
0%