P2V migration - converting RHEL5/CentOS5 physical server into Hyper-V VM

Published on Author admin

As there is no direct VM conversion tool (from physical Linux server to Hyper-V VM), to perform P2V migration of RHEL5/CentOS5 physical server into Microsoft Hyper-V Virtual Machine you should use VMware platform as an intermediate point.
Below you will find instruction how to do it:
• migrate physical RHEL5/CentOS5 server to VMware ESXi Virtual Machine using VMware vCenter Converter Standalone Client (it support LVM)
• inside RHEL5 Virtual Machine (run on VMware ESXi host) install new kernel (kernel 2.6.18-398.el5) and Xorg server (1.1.1-, you can use DVD install of CentOS 5.11

#create repo from DVD
mkdir /media/cdrom
mount /dev/cdrom /media/cdrom
cd /media/cdrom/CentOS/
#install createrepo
rpm -i createrepo-0.4.11-3.el5.noarch.rpm
#copy files from DVD to HDD
mkdir /repo
cp /media/cdrom/* /samba/repo -R -v
#create repository
cd /repo
createrepo .
#set proper path inside *.repo file
#there are 3 "/" characters
#remove RHN plugin (you will be no longer able to use RHN)
yum remove yum-rhn-plugin
#perform packages update (it will convert RHEL into CentOS when using CentOS repo)
yum update
#as alternative (to not perform full system update)
yum update kernel xorg-* selinux libselinux-*
#or when SELinux is disabled
yum update kernel xorg-*

• inside RHEL5/CentOS5 generate new initrd file (using mkinitrd command) containing proper modules for running Linux on Hyper-V hypervisor:

mkinitrd --with=hid-base-hv --with=hid-hyperv --with=hv_utils --with=hv_vmbus --with=hv_storvsc --with=hv_netvsc /boot/initrd-`uname -r`.img `uname -r` -f

• export VMware ESXi Virtual Machine virtual disk using VMware vSphere Client (export to OVF format, OVF contains VMDK disk files)
• convert virtual disks files from VMDK format (used by VMware) to VHDX format (used by Hyper-V) by using Microsoft Virtual Machine Converter (Powershell commands)

Import-Module ‘C:\Program Files\Microsoft Virtual Machine Converter\MvmcCmdlet.psd1’
ConvertTo-MvmcVirtualHardDisk -SourceLiteralPath \\host.local\C$\ClusterStorage\Volume1\VMs\redhat5\redhat5-disk1.vmdk -VhdType DynamicHardDisk -VhdFormat vhdx -destination \\host.local\C$\ClusterStorage\Volume1\VMs\redhat5

• create new Virtual Machine (Type 1) on Hyper-V cluster (by using Failover Cluster Manager) an manually attach VHDX files as IDE disks