Developers – Must Learn – Booting Windows 7 from a VHD

For the past few months I’ve been sharpening my Windows 7 skills and discovered what many systems people already know; “you can easily setup and boot Windows 7 or Server 2008 R2 VHD.”

Someone may already be thinking, why do I need to boot a VHD?

It’s no secret that Microsoft will be shipping Visual Studio 2010 Beta2.  If you want to be notified when Beta2 ships you can sign up here:  http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx

Some developers prefer to install beta software on a non-production machine or set up a multi-boot box.

This is where VHD’s come into play.  You can setup a VHD on your desktop or laptop, then from the boot menu, select to boot that VHD or boot the operating system.  I’ve been doing this at home and work for awhile now and love it.

VHD’s also enable you to have a x32 O/S boot and a x64 O/S boot on the same machine.   Possibilities are endless.

When you’re done with the VHD, just delete it and make a new one.

VHD’s sport great performance.  If you use the fixed size VHD, the total performance cost is 3%.  When I boot a VHD on my laptop I don’t see any drop in performance from booting the original O/S.

VHD’s do not require Hyper-V to boot them.  Server 2008 R2 does have a Hyper-V feature that allows you to log onto a VHD.  But what I’m explaining here does not require Hyper-V.  This is why I love this feature, it just works.

Recommendations

Before creating a new VHD, defrag the volume you want to add the VHD to.

I always create a fixed size VHD to ensure maximum performance.  Dynamic sized VHD’s offer flexibility with respect to size but pay a performance hit.

I’ve been allocating 45GB for all my VHDs.  This leaves plenty of room for Windows 7, Visual Studio, Microsoft Office and other applications and data on the VHD.  After you have created and configured a few of these, you’ll determine what works best for you.

I created a c:\vhd folder and locate all my VHD files here.

Possible Configuration Scenarios

Computer has Windows 7 or Server 2008 R2 installed and one or more Windows 7 or Server 2008 R2 VHD’s.

Computer does not have any O/S installed, but has one or more VHD’s that can be booted.  How cool is this?

Possible VHD Installation Options

Create a new VHD and install Windows 7 from a DVD or network location.

Create a new VHD and use imagex.exe to restore a .wim file to the VHD.  This is my favorite.  This saves so much time.  You install an O/S, configure it and install all the other software you need (except Visual Studio).  Then use imagex.exe to save a copy of the O/S and software to a .wim file.  You can then use imagex.exe to restore that .wim file to a VHD or if you need to a boot partition.  I do this at work every 1-2 weeks.  Takes a few minutes to pave my box.  Awesome software imagex.exe is!

On my laptop and desktop systems, I keep an extra VHD file that is all ready to go.  It’s configured and has all the software I need except Visual Studio.  Then when I want to load up another version of Visual Studio, I copy the files I need, delete the old VHD, copy the standby VHD to another new VHD, boot the new one and install Visual Studio.  Even on my laptop with the 45GB file copy and installing a new Visual Studio I’m up and running quickly.

Imagex.exe

What is imagex.exe?  Read this: http://technet.microsoft.com/en-us/library/cc507842.aspx

Where can I get imagex.exe?  Here: http://www.microsoft.com/downloads/details.aspx?familyid=696DD665-9F76-4177-A811-39C26D3B3B34&displaylang=en.  

Read how Scott Hanselman uses imagex.exe.  Great blog post!  Step-By-Step: Turning a Windows 7 DVD or ISO into a Bootable VHD Virtual Machine

Links

Rather that create a new blog post with pictures, etc, I’m going to provide the links that I’ve used to be successful with VHD’s.

Scott Hanselman: Step-By-Step: Turning a Windows 7 DVD or ISO into a Bootable VHD Virtual Machine

Microsoft TechNet: Windows 7 Boot from VHD.  This is actually the home page for a 3 part series on VHD files.  Very well written and covers the scenarios I’ve listed above. 

Microsoft Evangelist Keith Combs: 

Video:  Dual Boot from VHD with Windows 7 and Windows Sever 2008 R2
Article:  Dual Boot from VHD Using Windows 7 and Windows Server 2008 R2

Close

I hope you find this information informative and useful. 

Have a great day,

Just a grain of sand on the worlds beaches.

10 Responses to Developers – Must Learn – Booting Windows 7 from a VHD

  1. lbugnion says:

    Hey Karl,

    Yes VHDs are great. I would love it though if I didn’t have to reboot my main machine to get to the virtual one. A fantastic feature would be allowing to hibernate one machine (real or virtual) to boot into the other one. This way it would be much easier to switch.

    That said, I have been working on VHDs for a few weeks now, and it is fantastic to know that if something goes wrong, I can just delete the VHD and still have a running machine. Also, backing up a prepared state on an external HD allows you to get running on a new project much faster. I have one with VS2008, Silverlight, Word, Excel and a few utilities, and when I start a new project, I just copy it locally, boot into it, and customize it.

    Cheers,
    Laurent

  2. […] Developers – Must Learn – Booting Windows 7 from a VHD (Karl Shifflett) […]

  3. Josh Smith says:

    Great post! Thanks for the tip.

  4. marknadig says:

    Timely. Just ran across Disk2VHD from sysinternals that I am going to try out as well.

  5. dcuccia says:

    Re: “Before creating a new VHD, defrag the volume you want to add the VHD to.”:

    FYI, don’t ever defrag an SSD…

  6. […] Developers – Must Learn – Booting Windows 7 from a VHD – “For the past few months I’ve been sharpening my Windows 7 skills and discovered what many systems people already know; ‘you can easily setup and boot Windows 7 or Server 2008 R2 VHD.’ ..” […]

  7. Anthony V. says:

    Hi Karl,

    Could share with us how did you managed to create your “ready to go vhd”?
    I created a new vhd with Windows7, booted it, configured it and installed default software just like you did.
    But then i am kind of stuck, did you just copied that vhd or did you sysprep it.
    I would like to know which steps you followed and in case of sysprep, what settings did you used because i’m kind of new to this.

    Greetings,
    Anthony

    • Anthony,

      Sorry I was not clear.

      There are two paths.

      1. Create vhd, install software; then copy that vhd to another file. When you need a new vhd, copy that saved copy to another vhd and boot it. (I use this technique, but it has a limitation; you can’t copy it to another computer)

      2. If you use imagex to load your vhd you will have a syspreped vhd. You can load from a .wim file you saved or a .wim file on the Windows 7 Install DVD.

      You can Sysprep a vhd you’ve created and loaded software by following these steps.

      cd c:\windows\system32\sysprep\

      then execut: sysprep.exe /quiet /generalize /shutdown /oobe

      If you get an error then kill these processes:
      wmpnscfg.exe or wmpnetwk.exe

      Repeat the above and it will work

      Does this help?

      Cheers,

      Karl

      • Anthony V. says:

        Karl,

        Thanks for the quick response, I didn’t expected it to be this soon, but after checking your blog today, I can see you’ve been very busy this weekend.
        I choose option 1 for now, I’m to eager to play around with VS2K10 Beta2 and TFS + I can check out the new XAML PowerToys as well.

        Great work and keep up the good stuff.

        Cheers,

        Anthony

  8. […] read posts describing how there’s only around a 3% performance hit using VHD’s. In the post it’s […]

Follow

Get every new post delivered to your Inbox.

Join 248 other followers