Sunday, 30 March 2014

Migrating CentOS / cPanel from VMWare to Hyper-V

To migrate a CentOS / cPanel virtual machine from VMWare to Hyper-V there are a few steps you need to remember if you want to keep things easy.

The following steps assume you're attempting to migrate an existing CentOS installation, between host servers in the same network, eg you don't need or want to change any settings on the guest server like IP addresses etc. Simply convert, copy, import and power up.

Before shutting down the guest, it's advisable to uninstall the VMWare Tools from the server if they have been installed. While not always an issue, there are some reports of people having difficulties uninstalling it once the server has been migrated. Additionally, I'd suggest installing the Hyper-V Linux Integration Services prior to migration (current version at time of writing is 3.5 available here http://www.microsoft.com/en-gb/download/details.aspx?id=41554). This ensures when you power up the guest in Hyper-V that you don't have any issues with it recognising the network adaptor.

Linux installations hard code the MAC address of the NIC alongside the IP address details, which means if the MAC address changes (as it will by default when moving to another host), you'll find your network settings no longer work. Make a note of the current MAC address, either from the network settings in VMWare, or by looking in /etc/sysconfig/networking/devices/ifcfg-eth0.

Shutdown the server being migrated, and copy the files to the new Hyper-V server to convert them. You could convert them on the old server, but it's probably older and slower (hence you migrating) so moving them now saves time.

To convert the files I recommend using WinImage. Simply point it at the target vmdk file, tell it where to put the resulting .vhd file and its name, and it gets on with it. Note, some people report issues converting single large vmdk files (I don't know if this applies to WinImage), in which case the advise is to use VMWare Converter to split them into smaller files before the conversion. Once finished, copy the now converted .vhd file into the folder you'll create as part of the setup for the VM in the next step.

While the conversion is taking place create the new Hyper-V VM. At time of writing it will need to be a generation 1 virtual machine if you're running 2012 R2, as CentOS doesn't support generation 2 machines. Create the VM as normal, but when prompted to configure the HDD choose the option to Attach a virtual hard disk later.

Once configured, go into the Settings for the new VM. Newer versions of CentOS may be fine, but for 5.10 I found the NIC must be configured as a Legacy Network Adaptor, so remove the Network Adaptor that's there and then add a Legacy Network Adaptor instead. Within the Adaptor settings, go into the Advanced Features and statically assign the MAC address to the one you previously recorded from VMWare. Finally, select IDE Controller 0, select Hard Drive and click Add, then click Browse and find the .vhd file you converted earlier. Obviously if you have multiple drives then repeat this for each of them.

Once all this is done you can start the VM. You should find it starts successfully and works exactly the same as previously without the need to adjust anything on the server.