How-to: Getting started with .VHD files in Windows 7

How-to: Getting started with .VHD files in Windows 7

Summary: Some of you seem confused about how Windows 7 goes about supporting .VHD files as used by Virtual PC, Windows Server 2008 R2 and Hyper-V. Here's a quick how-to work with .VHD files in Windows 7.

SHARE:

Special Report: Windows 7

Some of you seem confused about how Windows 7 goes about supporting .VHD files as used by Virtual PC, Windows Server 2008 R2 and Hyper-V. Here's a quick how-to work with .VHD files in Windows 7.

OK, let's begin with a Windows 7 beta 1 install. Fire up a Command Prompt and type the following:

diskpart

Note: Press ENTER after each line to execute the commands.

You're now ready to create a blank .VHD file. The following command creates a 16GB VHD file in a folder called virtual (you can put the .VHD anywhere, but create any folder in advance):

create vdisk file=c:\virtual\win7.vhd type=fixed maximum=16000

It'll take a few minutes for the .VHD file to be created - took about 10 minutes on my test system. Diskpart will tell you once it's done.

OK, now to install Windows 7 beta 1 into the .VHD. Pop the Windows 7 beta DVD into the DVD drive and reboot the system and boot up off the disc. Once the Windows 7 installer is up and running, choose your language and once you're on the Install now screen, press SHIFT+F10 to bring up a Command Prompt.

Into the Command Prompt window, and first check to find out what drive letter has been assigned to your system partition (for me it was d:\). Make a note of the drive letter.

Next -->

Next type the following (substitute "d" for the drive letter of your Windows 7 partition if different):

diskpart select vdisk file=d:\virtual\win7.vhd attach vdisk

Close the Command Prompt and then click Install now. Choose a custom install when given the chance. When asked as to where you want to install Windows you'll find approximately 16GB of unallocated space. Put the new install onto this disk.

Note: Ignore any warning about not being able to boot up off this disk and proceed with the install.

Now continue with the install of the second copy of Windows 7. Because Windows 7 is .VHD aware the system will make all the necessary changes to the book loader ... but there is a catch! The catch is that the new virtual install with become your default install and the system will boot up into this install automatically (this is done so the Windows installation isn't halted when it reboots). Don't worry though, that can be changed.  You'll also notice that both installs are called "Windows 7" in the boot manager - don't worry, we'll change that too!

OK, once your second install of Windows has finished, here's how to fix the boot loader so that you boot by default into the "real" Windows 7 rather than the one in the .VHD file.

To fix the boot manager, boot into either OS, launch a Command Prompt ad an Administrator (right-click on the shortcut and choose Run as administrator) and type the following:

bcdedit /v

Now copy the identifier of the .VHD install and type (substitute the ID for the x's):

bcdedit /set {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} description "Windows 7 - VHD"

The above changes the description for your VHD installation to "Windows 7 - VHD" so you can tell them apart.

Finally, if you'd rather have the .VHD install at the bottom of the boot list do this:

bcdedit /displayorder {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} /addlast

Have fun!

<< Home >>

Topics: Windows, Microsoft, Operating Systems, Software

Kick off your day with ZDNet's daily email newsletter. It's the freshest tech news and opinion, served hot. Get it.

Talkback

15 comments
Log in or register to join the discussion
  • Native or still virtual?

    If you use this method, is the OS being ran natively then or still in a virtual environment?
    crazlunatic
    • It's being run nativly....

      Meaning you should have full access to the host hardware (USB, TV Tuners etc.). It's like booting off a partition contained in a VHD file.
      JoeMama_z
  • More helpfull info....

    1. Vista/Win7 system backups are kept in VHD files, great for P2V conversions and accessing backups without going through the backup/restore stuff.

    2. you can mount VHD's in Vista if you install Virtual Server 2005. A Google search will give you all the info you need. However it should be noted that in Vista, if a VHD is mounted and the computer goes to sleep it will most likely blueScreen, I think the VHD driver doesn't expect this since it was written with always on servers in mind.

    3. If you don't want to play with the command line to manage your BCD entries you can download the freeware utility EasyBCD, http://neosmart.net


    Booting and using a VHD's to test Windows7 is a great idea, great suggestion thanks Adrian!
    JoeMama_z
    • JoeMama_z's easyBCD

      The "freeware utility EasyBCD" is not free. Calling the fee a "donation" doesn't change that.
      Weathervane47
  • RE: How-to: Getting started with .VHD files in Windows 7

    Adrian, I want to install Windows 7 on my Vista Ultimate 64 bit laptop. Can I create the VHD with Virtual PC under Vista, do the config stuff above in vista and then boot and install Windows 7 into the new VHD? Hopefully this will preserve my Vista environment and run faster than actually running it on top of Vista in a virtual machine?
    daryl@...
    • That should work....

      should be pretty trivial using virtual PC and EasyBCD.
      JoeMama_z
  • Jusy FYI...

    It is possible to create and attach Virtual Hard Disk in Disk Management > Action from Computer Management.
    logicearth@...
  • Yikes!

    Does anybody have the same worries as myself? That there's going to be a lot of borked systems by inexperienced users using Diskpart.

    Surely a *VHD only* config utility would be preferable.
    V@...
    • There would be more..

      borked systems if there was such a tool. Creating VHDs are not difficult, using them is another matter.

      It is best that this is a hidden feature for power users at the moment.
      logicearth@...
  • RE: How-to: Getting started with .VHD files in Windows 7

    Joe,

    I just installed Win7 Beta in VirtualPC 2007. The problem I have is that Aero cannot be enabled in that environment. Do you know anything about it? I tried the RDP hack too, but that doesn't work.

    - Praveen
    LPraveen
    • WARP.....

      The emulated graphics in VirtualPC aren't 3D accelerated at all, and I am not sure what requirement have to be met in order to use WARP or if WARP is enabled in Beta1. I've tried this with virtualbox with the same results.

      Someone more familiar with the in's and outs of WARP could probably clarify this better.

      More info on WARP
      http://msdn.microsoft.com/en-us/library/dd285359.aspx#Target_Customers

      - Sam
      JoeMama_z
  • RE: How-to: Getting started with .VHD files in Windows 7

    Adrian,

    You can get my goard sometimes (hey, that's the way it should be :)), but this was one damned fine article.

    Thanks!

    I'd like to see something similar geared towards using Vista 64 as the primary machine.
    BitTwiddler
  • RE: How-to: Getting started with .VHD files in Windows 7

    Portlock Leap Frog, http://www.portlock.com/support/knowledge_base/download_windows_7_vhd.aspx

    Can be used to setup VHD boot as well as pre-created VHD from Microsoft for dual booting.
    Daren253
  • RE: How-to: Getting started with .VHD files in Windows 7

    But I think it's a little difficult for me. I always right-click vhd file and choose "mount to new drive", I forgot to say you need to install WinMount.(www.winmount.com/mount_vhd.html)
    colorzone
  • Running XP from vhd

    I would like to know if it possible to install xp on a virtual hardisk and boot from it using this feature of win7...This way there would be negligible loss in performance...
    ~SlaYer~