Installing Windows 2008 Server R2 into a virtual hard disk (VHD)

This is an old article I wrote back in 2010 but oddly enough gets some traffic still so I have migrated it to my new website

It started as a simple task on a Sunday evening. I wanted to get Windows Server 2008 R2 running on my home network for some dev work, however it’s 64bit only and my trusty home webserver is 32 bit and frozen in time on Windows Server 2003. As I didn’t fancy forking out on new hardware the next plan was to install Windows Server 2008 on my workstation and work directly on it with Visual Studio. The machine is a 64bit Athlon and runs 5Gb of RAM, dual-booting into Windows 7 Enterprise and XP Pro

This seemed a good plan, but I didn’t want to mess around with my machine too much as I heard Windows Server can be a bit brutal with existing boot menus etc. so thought I’d try running it in Virtual PC, which I already use for a couple of Win XP instances on Windows 7. Unfortunately I then discovered Virtual PC doesn’t support 64 bit operating systems (even though I’m running 64 bit Windows 7….) so it was back to the drawing board….

After a bit of nosing around I found that you can install Windows 2008 Server R2 directly into a virtual hard drive (VHD) and, this is the clever bit, boot this VHD like you would any other native operating system. Apparently this is supported by Windows 7 as well, allowing you to build a dual (or more…) boot machine that actually has no operating system and simply boots into local VHD files. This is then a great way of having multiple environments on the same physical machine, and allows you to easily drop an instance and copy over a clean install with minor downtime

The actual steps are pretty straightforward:

  • The physical disk that you intend the VHD file to live on should be formatted, but as it’s a VHD file it doesn’t need to be empty and can hold other data (apparently it can’t be a USB drive but I haven’t checked)
  • Boot the machine from the Windows Server 2008 R2 DVD
  • Wait for the first installation dialogue box then press SHIFT + F10 to open a command prompt window
  • Launch diskpart from the command prompt
  • Type the following command create vdisk file=”c:\win2008r2.vhd” maximum=30000 (this creates a virtual disk of 30Gb on the root of the c-drive, though you can change the path to put the file where you like. Equally the help screen shows you have various other options including making the VHD expandable)
  • Select the VHD file you created using select vdisk file=”c:\win2008r2.vhd”
  • Then run attach vdisk
  • You can then exit from diskpart and the command prompt to return to the Windows Server installation screen
  • Follow the Windows Server install options as usual and then when it prompts for which drive partition to install to choose the one you just created (you may need to refresh the screen). Some of the forums I read implied it would show disk type as VHD but for me all it gave was a normal drive of around 29.5Gb with no name so you need to know your existing drive structure…..
  • Ignore any error messages telling you it can’t boot from this type of partition and let it get on with the installation – which it did after a minute or so on ‘0%’

That’s it really – it added Windows Server 2008 as an option to my main boot menu without removing the Windows 7 or XP entries, and created a neat VHD file with the whole installation on it. You can back this up like any normal VHD, redeploy or even delete the file and edit the boot menu using the bcdedit command to get back to where you started

After this it was an easy job to configure Windows Server for IIS, run the latest updates and install Visual Studio 2010 RC. Job done.