Moving a CentOS 7 VM from VMWare to Xenserver
- December
- 14
11:32 am Linux
After searching and finding all the little pieces of this process I thought I would document it here for future referral.
Â
The main issue with moving the VM from one hypervisor platform to the other is that the initial RAM disk doesn't have the Xen network and block device drivers. So even if you can successfully convert the disk through export/import or a third party (QEMU perhaps) application, the machine won't come up.
Â
What's needed is to rebuild the RAM disk with the right drivers and then tell grub to use it.
Â
First, let's build the new RAM disk image. Log into the running VM under VMWare and do the following:
Â
Â
# cd /boot
# ls initramfs*
initramfs-0-rescue-898e9089de1c4bcfac2d751bbd9e7f10.img
initramfs-3.10.0-693.21.1.el7.x86_64.img
initramfs-3.10.0-693.21.1.el7.x86_64kdump.img
initramfs-3.10.0-693.el7.x86_64.img
initramfs-3.10.0-693.el7.x86_64kdump.img
initramfs-3.10.0-862.el7.x86_64.img
initramfs-3.10.0-862.el7.x86_64kdump.img
Â
I'm going to use the newest kernel to build my RAM disk. If you have a different kernel (likely), adjust the name as needed.
Â
Â
# mkinitrd --omit-scsi-modules --with=xennet --with=xenblk --preload=xenblk /boot/initramfs-3.10.0-862.el7.x86_64-XEN.img 3.10.0-862.el7.x86_64
ls -ld initramfs*
-rw-------. 1 root root 51307405 Mar 14 2018 initramfs-0-rescue-898e9089de1c4bcfac2d751bbd9e7f10.img
-rw------- 1 root root 21008864 May 10 2018 initramfs-3.10.0-693.21.1.el7.x86_64.img
-rw------- 1 root root 13336203 May 10 2018 initramfs-3.10.0-693.21.1.el7.x86_64kdump.img
-rw-------. 1 root root 20349498 Mar 14 2018 initramfs-3.10.0-693.el7.x86_64.img
-rw-------. 1 root root 18730293 Mar 14 2018 initramfs-3.10.0-693.el7.x86_64kdump.img
-rw------- 1 root root 21049754 May 10 2018 initramfs-3.10.0-862.el7.x86_64.img
-rw------- 1 root root 12976861 Jul 13 07:33 initramfs-3.10.0-862.el7.x86_64kdump.img
-rw------- 1 root root 21075430 Dec 14 10:29 initramfs-3.10.0-862.el7.x86_64-XEN.img
Â
Okay, you can see the new image and it's about the same size as the other one too.
Next, we need to copy the text from a boot entry that grub uses. Find it in /boot/grub2/grub.cfg. Don't edit this file, just find the section that looks like this:
Â
menuentry 'CentOS Linux (3.10.0-862.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-693.el7.x86_64-advanced-0a5149be-1fe5-40bf-8597-c0c588af88c8' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1' efa02a93-827e-4734-8a44-7eb1ef93119a
else
search --no-floppy --fs-uuid --set=root efa02a93-827e-4734-8a44-7eb1ef93119a
fi
linux16 /vmlinuz-3.10.0-862.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=en_US.UTF-8
initrd16 /initramfs-3.10.0-862.el7.x86_64.img
}
Â
Take that text and add it to the end of the file in /etc/grub.d/40_custom. You then want to change two things. First change the name of the entry so you 'll be able to see it when you boot. Then change the name of the RAM disk image being used. My finished file looks like this:
Â
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry 'CentOS Linux (3.10.0-862.el7.x86_64) 7 (Core) with xen' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-693.el7.x86_64-advanced-0a5149be-1fe5-40bf-8597-c0c588af88c8' {
load_video
set gfxpayload=keep
insmod gzio
insmod part_msdos
insmod xfs
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1' efa02a93-827e-4734-8a44-7eb
1ef93119a
else
search --no-floppy --fs-uuid --set=root efa02a93-827e-4734-8a44-7eb1ef93119a
fi
linux16 /vmlinuz-3.10.0-862.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=en_US.UTF-8
initrd16 /initramfs-3.10.0-862.el7.x86_64-XEN.img
}
Â
Lastly, we need to rebuild the grub menu.
Â
#Â grub2-mkconfig --output=/boot/grub2/grub.cfg
Â
That should do it. Now you can export your machine and when it boots under Xenserver make sure you choose the right boot option when it starts up. You can make that the default option in grub if you want to.
Â
I did not have any issue using the RAM disk containing the xen drivers under VMWare either so I'll bet you could just copy the file over the other RAM disk and it would boot under either OS. May try that just to make sure it works okay.
Â
Â
Â
Â
« Using networksetup to add static route(s) to a Mac OS VPN | CentOS 7 and VMWare ESXi Networking via CLI » |