Tuesday, October 2, 2012

Convert Windows Server 2008 R2 from Physical to Virtual

I rebuild my computer recently.  By that, I mean I bought a new motherboard, cpu, memory, hard drive, and case.  I reused the power supply and dvd burner, keyboard, and mouse.  I even got a new monitor.  So it wasn't so much a rebuild as a replacement.

Anyway, I had Windows Server 2008 R2 on the old machine.  I backed up all of the data, but I thought it would be nice if I could virtualize the old machine.  That way I could go back and get data, run old programs, check settings, etc.

I mounted the old hard drive in the new computer so that I could do a physical-to-virtual image.  The old drive was 600GB with a 100GB boot partition and a 500GB data partition.  There are several physical-to-virtual tools available.  Some run on an already running system, and some run on a disk.  I wanted one that ran on a disk.

I use VirtualBox instead of VMware, so I didn't want to use the VMware tools.  I decided to use Disk2vhd from the excellent Systernals Suite.  It creates a .vhd file, which is a microsoft format.  VirtualBox can read those natively.

I had the drive that I wanted to image already mounted as e:\ and f:\.  I chose just the e:\ drive to image and let the software run.  When it was done, I had a new .vhd file.

I created a new windows 2008 machine in VirtualBox and attached the virtual drive.  I started it up, and of course got a blue screen.  The OS couldn't find the boot drive.  This is caused because the disk controllers/IDs/or something else is different.  The solution is to make changes to the registry.

To change the registry of the virtual disk, first take the physical disk online.  If you don't there will be a conflict with disk IDs later when we try to mount the virtual drive.  I used Windows 7 to mount the vhd.

Go to Computer Management, then Disk Management.  Click on one of the drives in the lower right so that the module is active.  Then right click on Disk Management and select Attach VHD.  Select the .vhd and make sure it gets mounted to a drive letter.

Now, open a command prompt.  I did this as administrator.  Assuming that the .vhd is mounted to drive e:\, I ran these commands:
C:\>reg load HKLM\VHDSYS e:\windows\system32\config\system

This loaded the .vhd registry to the current registry under HKLM\VHDSYS.  I started regedit and modified the Start key from 3 to 0 under these two entries:

HKEY_LOCAL_MACHINE\VHDSYS\CurrentControlSet1\Services\Msahci
HKEY_LOCAL_MACHINE\VHDSYS\CurrentControlSet1\Services\IastorV
I closed regedit and then unloaded the .vhd registry with this command in the command prompt:
C:\>reg unload HKLM\VHDSYS

Then, I started up the virtual machine.  It booted normally.  Then I installed host additions.  That gave me a better resolution and mouse integration.

However, the machine was not activated, and the old key did not work.  I'll have to research this more.