Monday, December 5, 2011

Linux on Hyper-V, migrate RedHat VM from XEN to Hyper-V

Short version - we are a mostly Microsoft shop and after a brief foray into XEN on RedHat I now have to migrate a bunch of RedHat ENT 5.x virtual machines from Xen to Hyper-V.


If you just need to migrate a hardware based linus install to a Hyper-V VM, just follow the instructions in the first reference at the bottom of this page.


Surprisingly, couldn't find much out there on this one, but was able to cobble this procedure together from several different posts.  Everything below was done on RedHat Ent 5.x virtual machines running GRUB and Hyper-V on Windows Server 2008 R2 SP1.  For other/newer linux with GRUB2 or other bootloaders you will have make some adjustments.


 It turns out that the linux .img format created by the DD command (which is also the Xen VM format) can be converted to the .vhd format as long as the .img is smaller than 127 GB.  (VHDtool can't handle a larger file)


1. The kernel your XEN VM is running won't work outside the XEN enviroment, you need the plain vanilla hardware version.  Luckily it isn't too hard, I used Yum here, if you have/like another way than have at it.

yum install kernel
2. The new kernel need to create it's boot drivers, with this command:

mkinitrd -v -f --builtin=xenblk  /boot/nameoftheinitrd   kernel-version
An example from kernel version 2.6.18-274.12.1.el5:

mkinitrd -v -f --builtin=xenblk  /boot/initrd-2.6.18-274.12.1.el5.img   2.6.18-274.12.1.el5

3. Now make sure the /etc/sysconfig/kernel file refers to the new kernel. Do so by including the line DEFAULTKERNEL=kernel in this file.


4. edit /boot/grub/device.map. The idea is that the XEN disk type is xvd, but the common IDE type is hd.  The first & second XEN hard drives would be xvda and xvdb, but under hardware or HyperV they should be hda and hdb.
change this line:
(hd0) /dev/xvda
to:
(hd0) /dev/hda


5. Edit /boot/grub/menu.1st so that "default=0"

6. Shutdown VM   (xm destroy)

7. Use WinSCP (free, on internet) to copy the xem vmname.img file to a location on a stand alone hypervisor (temporary location to first run the VM).

8. Use VHDtool.exe (free, internet) to convert the linux img file to a VHD format (This is very fast, less than a second)
VHDTool /convert c:\VMNAME.img

9. rename the file from __.img to ___.VHD

10. create the VM in the HyoerV manager, using your VHD file as the hard drive.  it should boot right up

11. If you get a mesage after booting that 
"INIT: id "co" respawning too fast: disabled for 5 minutes"
then comment out (#) the line in /etc/inttab under 'gettys' that begins with "co"  (it is the xen terminal type)







References:
1.  http://blogs.technet.com/b/enterprise_admin/archive/2010/05/13/linux-p2v-with-dd-and-vhdtool-easy-and-cheap.aspx
Summary, should it ever be deleted:

1. On Linux machine - you will need free space on a local disk or mapped drive equal to the partition size.  Use DD to make a binary image copy (_.img file) of the linux install.  This can take several hours (all depends on the size of the data) format:

dd if=/dev/hda of=/mnt/rhel54.img


"dd" is the command, "if=/dev/hda" is the input - may not be the hda disk type, use "fdisk -l" to see what your hard drive is.  Another common name is "/dev/cciss/c0d0"
If you can map to a windows drive to write to, this is the format to mount the remote share:

mount –t cifs –o username=administrator //192.168.0.10/D$ /mnt


If you use another partition on linux to store the image, you can use WinSCP (free - internet) to transfer the image to the windows server after creating the _.img file.


2. Use VHDtool.exe (free, internet) to convert the linux img file to a VHD format (This is very fast, less than a second)

VHDTool /convert c:\VMNAME.img


9. rename the file from __.img to ___.VHD


10. create the VM in the HyperV manager, using your VHD file as the hard drive.  


11. You will need to install the version of "Linux Integration Services" that matches the version of RedHat you are working with (a download from microsoft).  As of this writing RedHat 5.0 to 5.5 uses Integration Services 2.1.  It appears that 5.6 and higher can run without the integration Services (it is optional for advanced features)


The install instructions are included with the product, it involves pressenting the .iso file to the VM through HyperV manager, then install at the linux console.  


This product recomplies the kernel, so you have to disabled Kernel updates in Yum.conf.  If the kernel is updated the VM will no longer be bootable as the Microsoft linux drivers won’t exist in the new kernel.  Possible long term solution here:
http://support.microsoft.com/kb/2387594




2. http://searchservervirtualization.techtarget.com/tip/Xen-to-KVM-virtual-machine-migration-A-step-by-step-guide


2 comments:

  1. I want you to thank for your time of this wonderful read!!! I definitely enjoy every little bit of it and I have you bookmarked to check out new stuff of your blog a must read blog! Also, check our sites.
    https://hard-drives.co/
    https://hard-drives.co/seagate-personal-cloud-time-machine
    https://hard-drives.co/seagate-personal-cloud-login
    https://hard-drives.co/wd-easystore-not-recognized-by-mac
    https://hard-drives.co/how-to-format-wd-my-passport-hard-drive-mac

    ReplyDelete