Hyper-V Physical to virtual: Moving a natively booted VHD to be a real virtual machine

Introduction

I had a requirement to migrate an existing native boot Windows Server 2008 R2 machine that was booting from an attached VHD on a physical machine to be a virtual machine in Hyper-V. The problem is that this machine had multiple boots and so the booting record was on the physical drive and the VHD image really did not have any booting information. Also because of the fact that it is booting in a physical machine it was using SATA AHCI of that machine and had the drivers to use that which is completely different form the Hyper-V implementation of the feature so I had to switch to Native IDE storage controller instead.

Resolution

What I did was first I created a differencing VHD disk from that virtual machine as I wanted to make sure I am not changing anything in the source VHD in case I decided to switch back to native boot. Then I created the virtual machine and used IDE controller for the HDD pointing to the differencing VHD file. Now because the VHD did not have any booting information I had to build it and I had to add the boot manager to that machine. So here are the steps.

1- Mounted the VHD using the host storage disk management.

2- Copied the files “bootmgr” and all contents of the folder “Boot” from a similar OS machine (Windows 2008 R2) to the root of the VHD.

3- Made sure that the copied files still have the system attribute set correctly.

4- Un-mounted the VHD from the host.

5- Attached a Windows 2008 R2 setup DVD to the DVD drive of the virtual machine.

6- Started the Virtual machine and booted from the setup DVD.

7- Clicked next on the setup screen with default options.

8- Clicked repair my computer and opened command prompt.

9- Since the virtual drive did not have the partition set as active I changed that as per the command lines below:

Diskpart

List disk

Select disk 0

List partition

Select partition 1

Active

Exit (to close disk part)

10- Now I need to fix the boot sector information so I typed the following commands:

Bootrec /fixmbr

Bootrec /fixboot

Bootrec/ RebuildBCD

11- If you had hypervisor enabled on the physical machine then you also need to disable that using the command

bcdedit /set {default} hypervisor off

12- I have now the booting information in-place and ready to boot but when I booted it hit BSOD and I remembered that I need to correct the use of storage driver to be IDE since that machine was using SATA. So I switched back to the command prompt from the Windows setup DVD.

13- Started Regedit.

14- Selected HKEY_LOCAL_MACHINE and clicked File then “Load Hive”

15- Browsed to the file “C:\Windows\System32\Config\System”

16- I entered a name for the key to be “OfflineSys”

17- I browsed to the key “HKLM/OfflineSys/System/CurrentControlSet001/Services/” and then under the following keys I changed the “Start” values according to the following table.

Key name

Value of the Start

Aliide

3

Amdide

3

Atapi

0

Cmdide

3

iaStorV

3

Intelide

0

Msahci

3

Pciide

3

viaide

3

18- I selected back to the key “HKEY_LOCAL_MACHINE\OfflineSys”

19- Then clicked “File” then “Unload Hive”

20- Now restarted the machine and it worked like a charm and started installation of new device drivers and everything.

Conclusion

Although moving a machine from the physical boot to be a virtual machine is possible it is very risky I advise you to do with the great care. It is also highly advisable to use Physical-to-virtual conversion tools such as the Virtual Machine Manager that comes with the System Center suite.