Thursday, 14 May 2009

Booting from a VHD with Windows Server 2008 R2

*Updated 11 June 2010* - fixed some incorrect text when attaching the VHD and added a gotcha when building the VHD in a drive other than your primary c: drive

To skip straight to the technical setup click here
I have been developing on virtual machines for quite some time now. First with Virtual PC/Server and then a little more recently with HyperV and although there are many well documented major benefits throughout the web to this approach to development, there is a downside

    • You have to share processor power and RAM between two Operating Systems

    • You get no decent native graphics hardware support so no luck with duel monitors (i do realise you could use /span in remote desktop but it is a pain to configure the setup and if anything crashes or you need to reboot…. you get to start all over again)

    • No native graphics support also rules out developing for WPF or XNA in an meaningful way
      With the release in the last few weeks of the RC versions of Windows 7 and Windows Server 2008 R2 came the latest virtualisation offering from Microsoft  ‘booting from a VHD’. A couple of quick points to note. First, this is not meant as a replacement for running VMs on HyperV, VMWare, et cetera,  it is just another arrow in the developer quiver. Secondly, if you are not a fan of duel booting your machine then this approach will probably not have much appeal to you either, as essentially this is the same behaviour but with some extra niceness. You can boot from the VHD and get all the *RAM/cores/processor speed your dev machine has to offer plus all the native hardware support (duel monitors baby!!!)  and then like any VM when are done with the project you can park it.
      *There is a small amount (~120MB) of RAM that is set aside to run the VHD that the VHD cannot see.
      For me the decision to go down this path was a no brainer. My current machine is no slouch -duel core  2.83GHz, 4GB RAM and running windows server 2008 with no themes installed and desktop experience turned off . However when I was using HyperV to run my development VM, the host OS was only running Outlook and my browsers and I was having to set aside  1.5GB for the base OS when i was creating my VMs. Think about that for a second… 1.5GB to run Outlook, IE and Chrome/Firefox! While this in of itself is not necessarily a bad thing, when you combine this with my development VM setup (2.5GB RAM ) which is running SQL Server 2008, SQL Reporting Services, Navision 2009 and Visual Studio 2008 (with ReSharper obviously) running a WinForms solution of some 125915 lines of code (not including comments, region tags or curly braces) then you can probably start to see my pain point. So short of applying some dilithium crystals to my VM i needed a way to realise all the processing power on my machine.

        *The technical stuff*

        To boot from a VHD requires either Server2008 R2 (RC) or Windows 7 (RC)
        There are two ways to set this up you can upgrade from a previous version or run through a clean install which also happens to be the MS recommended approach.
        I choose the upgrade path and went from Server 2008 to Server 2008 RC. To do this upgrade requires 15GB of HD space and if you are running HyperV you have to disable the role as the upgrade will not proceed with it enabled.
        I ran through the upgrade process and it took about 80 minutes. Much longer than the 20 minute install but worth it to keep my system intact.
        Once the upgrade/install is complete reboot from the Server2008R2/Windows7 disk and when you get to your first splash screen (for me it was the select keyboard configuration) press SHIFT+F10 to launch a command window

        *Important* Be aware that if you are going to build your file at a location other than the c: drive then the letters might not match up. I assume this has something to do with reserved letters not being allocated at this point and the partitions just get allocated when they appear. Hence what might be f:\ for you might be e:\ at this point.

          • type diskpart at the promt. Then

          • type create vdisk file c:\Server2008R2vhd.vhd type=fixed maximum=30000

          • You can call your file whatever you like I called mine Server2008R2vhd.vhd. For the size of the VHD, I choose 30GB (30000) which is huge for a VM but really whatever suits you.

          • type select vdisk file=c:\Server2008R2vhd.vhd (selects the VHD)

          • type attach vdisk (this used to be called 'surface'). Essentially it mounts the VHD as a visible partition

          • we're done. Type exit and then exit again

          • Continue on with the installation configuration i.e. pick an OS version etc. until you get to the point where you choose your partition to install to.

          • Select the newly added partition which should be the same size as you added (fingers crossed) and hit go.

          • Sit back, configure as required and enjoy.

            Things to watch for

              • You cannot use an existing VHD i.e. a backup, HyperV, Virtual Server or PC versions. It must be a brand spanking new clean version. There probably is a nice workaround for modifying an existing VHD for this purpose. If anyone knows what to do then please let me know :)

              • The VHD was added as boot menu option with the exact same name as my host OS (they both said Windows Server 2008 R2.) The top option is the newly added VHD. Which is useful as the machine needs to reboot several times as part of the install process. You can rename this options using BCDEdit (see below)

              • I was able to rename and remove my first few unsuccessful attempts through BCDEdit

              • typing bcdedit gives a list of the all profiles for booting

              • bcdedit /set {ntldr} description "My Awesome boot VHD" with {ntldr} being the identifier of the profile or {current} or {default}

              • you can delete by typing bcdedit /delete {GUID} /cleanup
              Good luck and happy booting

              No comments:

              Post a Comment