Windows 7 can boot and run in some ways that are a little surprising when you first learn about them. One example is that it can seamlessly install from any sufficiently large USB key; another is that it can natively boot VHD files. Neither of these is hard to configure and both have already been discussed by other web sites. However, it has been my experience that some of the relevant information on the web is confusing, misleading, or incomplete. So in the interest of saving others - and myself! - some trouble, I explain a few interesting scenarios below with exact steps and brief notes on what each step does. (That way, if anything goes wrong, troubleshooting is a lot easier.)

If you already do this kind of thing and have a process that's working for you, there's probably little here that's new. But if you've been thinking of getting your feet wet with any of this, maybe I can help make things a little easier! :)

 

Notes:

  • The tasks described here are potentially dangerous and can result in the complete loss of your data if done improperly. Always back up your data first, think about what you're doing, check your work, and otherwise take sensible precautions! While I've done my best to ensure the steps below work as intended, I can offer no guarantee they'll work the same under all conditions. Caveat emptor.
  • Things you type look like this - things you do look like [this] - things you need to replace when you type them (like drive letters that vary by machine) look like this.
  • Unless otherwise noted, all tasks should be carried out on a machine running Windows 7.
  • Each task is self-contained and can be done independently of the others.
  • Although I refer to Windows 7 everywhere, Windows Server 2008 R2 supports these same scenarios as well.
  • While it's possible to apply BitLocker drive encryption to a natively-booted VHD, the host drive (i.e., the drive containing the VHD) can not be encrypted. (And if you're going to use BitLocker, you should be aware that the default location for pagefile.sys of a natively-booted VHD is on the host disk outside the VHD.)
  • Here are some good resources for more information:

 

Installing Windows 7 (or Vista) from a USB Key

Besides making it possible to install Windows on machines without a DVD drive, installing from a USB key has a big advantage: it's fast. All you need is a blank USB key that's big enough to hold everything on the DVD (typically about 3GB of data). Then follow these easy steps and - BAM! - install runs faster than ever!

  1. [Open a Command Prompt as administrator]

    Open the Start Menu, expand "All Programs", "Accessories", right-click on "Command Prompt", then "Run as administrator".

  2. [Insert the USB key]

    Give the system a moment to identify it.

  3. diskpart

    Run the interactive disk partitioning tool.

  4. list disk

    Display the available disks.

  5. select disk #

    Select the USB key; identify it using the "Size" column. USB keys will usually be near the bottom of the list, especially if they've just been plugged-in (when they're likely to be last).

  6. list disk

    Look for the '*' identifying the selected disk and be sure you've selected the right one because the next step will delete all data on that disk.

  7. clean

    Remove all partition/formatting information from the selected disk.

  8. create partition primary

    Create a primary partition on the selected disk.

  9. format quick

    Format the new partition of the selected disk with the default file system.

  10. active

    Mark the new partition on the selected disk active and bootable.

  11. assign

    Assign a drive letter to the new volume of the selected disk.

  12. list volume

    Display the available volumes. Look for the '*' identifying the newly created volume.

  13. exit

    Exit the interactive disk partitioning tool.

  14. robocopy W:\ U:\ /e

    Copy the entire contents of the Windows 7 (or Vista) DVD in drive W to the USB key at drive U.

  15. [Safely remove/unplug the USB key]

    This key can now be inserted in any machine that supports booting from USB (nearly all of them do these days). The experience will be just the same as if the original DVD were used - but it runs considerably faster!

    Note: You may need to hit a special key as the machine starts to tell it to boot from the USB key instead of the internal hard drive - it's usually one of F2/F12/DEL/ESC, but check the manual if you're not sure.

 

Create a VHD containing an up-to-date Windows 7 image

Installing from USB may be fast, but what's even faster is not having to install at all! If you'll be running Windows 7 in Windows Virtual PC, Hyper-V, or natively from a VHD, it's convenient to start out with an image that already has the bits in the right places and the latest security patches applied. What's cool is that there's a script to make creating one of these VHDs easy: WIM2VHD by Mike Kolitz. Start by going to that web site and following the directions to download WIM2VHD and its dependencies before carrying out the steps below.

  1. [Open a Command Prompt as administrator]

    Open the Start Menu, expand "All Programs", "Accessories", right-click on "Command Prompt", then "Run as administrator".

  2. [Change to the directory containing WIM2VHD.wsf]

    For convenience, this directory should also contain all the QFE patches that will be applied.

  3. cscript WIM2VHD.wsf
      /wim:W:\sources\install.wim
      /sku:ULTIMATE
      /disktype:fixed
      /size:10000
      /vhd:Windows7Ultimate.vhd
      /qfe:Windows6.1-KB973525-x86.msu,Windows6.1-KB974332-x86.msu,Windows6.1-KB974431-x86.msu,Windows6.1-KB974455-x86.msu,Windows6.1-KB974571-x86.msu,Windows6.1-KB975364-x86.msu,Windows6.1-KB975467-x86.msu,Windows6.1-KB976749-x86.msu
    

    Create a VHD named Windows7Ultimate.vhd from the original Windows 7 DVD in drive W using the Ultimate SKU, a fixed size disk of 10GB, and with the listed QFEs pre-applied.

    Note: I'm using the x86 DVD here, so I'm providing the x86 versions of the relevant security patches. This should all work the same for 64-bit, but I prefer 32-bit because it's smaller and works pretty much everywhere.

    Note: You can create a dynamic disk (which starts small and grows as necessary) by omitting the italic /disktype and /size options above. That's going to be faster and easier to deal with for Virtual PC and Hyper-V - but for native VHD boot a fixed size is easier and performs better. That's what I'm going to do in the next task, so I've specified a small, fixed disk above. (Please refer to the FAQ for more detail.)

    Note: Per the FAQ, "Native boot from VHD is only available with Windows 7 Enterprise, Windows 7 Ultimate and all versions of Windows Server 2008 R2."

 

Configure a clean machine for native VHD booting

Is it possible to boot a machine without a "real" operating system? Yes!

The steps below will clean a machine and configure it to boot into a VHD image from a nearly-empty hard drive. While there are some sensible reasons to do this (e.g., implementing poor-man's undo disks or making it easy to transfer a pre-configured Windows 7 install around), this is mainly just a cool way to show off. :) Rumor has it that these steps can even be used to create a USB key that hosts and boots a running copy of Windows 7, though I don't have a USB key large enough to try myself. (And besides, that would probably wear out the USB key's flash memory quite quickly.)

Note: If you already have Windows 7 installed on a machine, and want to add an additional boot option for VHD, please scroll down to the next task instead.

  1. [Boot the machine from the Windows 7 DVD or a Windows 7 USB key created by the steps above]

    Load a simple shell that can be used to make low-level changes to the disk.

  2. [Wait for the "Install Windows" dialog to display]

    Allow the system to boot completely.

  3. [Optional: Plug in an external USB drive containing the VHD image]

    If you're booting from the DVD or using a USB key that's too small to hold the 10GB VHD image, you can store the VHD file on a separate USB hard disk. Plug that disk in now, and give the system a moment to find it and assign it a drive letter.

  4. [Press Shift+F10]

    Open an interactive command prompt with administrator permissions

  5. diskpart

    Run the interactive disk partitioning tool.

  6. list disk

    Display the available disks.

  7. select disk #

    Select the primary hard disk; it will usually be at index 0.

  8. list disk

    Look for the '*' identifying the selected disk and be sure you've selected the right one because the next step will delete all data on that disk.

  9. clean

    Remove all partition/formatting information from the selected disk.

  10. create partition primary

    Create a primary partition on the selected disk.

  11. format quick

    Format the new partition of the selected disk with the default file system.

  12. active

    Mark the new partition on the selected disk active and bootable.

  13. assign

    Assign a drive letter to the new volume of the selected disk.

  14. list volume

    Display the available volumes. Look for the '*' identifying the newly created volume.

  15. exit

    Exit the interactive disk partitioning tool.

  16. copy E:\Windows7Ultimate.vhd C:\

    Copy the VHD file Windows7Ultimate.vhd from (external) drive E to the now-empty primary hard drive C. This may take a little while...

  17. diskpart

    Run the interactive disk partitioning tool.

  18. select vdisk file=C:\Windows7Ultimate.vhd

    Select the VHD file Windows7Ultimate.vhd just copied to the primary hard drive C. Make sure not to reference the VHD file on the removable disk because that disk won't be available in the future.

  19. attach vdisk

    Attach the selected virtual disk to the system.

  20. list volume

    Display the available volumes. Look for the new virtual disk volume; identify it using the "Size" column (it will probably be the last one listed).

  21. exit

    Exit the interactive disk partitioning tool.

  22. bcdboot V:\Windows /s C:

    Configure primary hard disk drive C to boot into the copy of Windows installed on virtual drive V (the newly attached virtual disk volume).

  23. exit

    Close the Command Prompt window.

  24. [Close the "Install Windows" dialog by clicking the 'X' in the upper-right corner]

    Cancel the install process.

  25. [Confirm you want to cancel the install process]

    Yes, really cancel the install process.

  26. [Wait while the machine automatically reboots]

    Allow the machine to boot into the new VHD image. (Note: This may require unplugging the USB key and/or external USB drive.) After booting into the VHD image, Windows will run through the last stages of setup (e.g., user name, time zone, etc.) and finalize the install.

    Enjoy your new VHD-based Windows!

 

Add native VHD booting to a machine with Windows 7

If you already have a machine with Windows 7 installed (perhaps via the previous set of steps), you can modify it to boot a separate instance of Windows 7 from VHD.

  1. [Open a Command Prompt as administrator]

    Open the Start Menu, expand "All Programs", "Accessories", right-click on "Command Prompt", then "Run as administrator".

  2. copy E:\Windows7Ultimate.vhd C:\

    Copy the VHD file Windows7Ultimate2.vhd from (any) drive E to drive C which should be the machine's primary hard disk. (It will already contain a VHD file if you're continuing along from the previous task.) Make sure drive C does not correspond to a VHD-based disk.

  3. bcdedit /copy {default} /d "Windows 7 VHD"

    Creates a copy of the default boot configuration with the name Windows 7 VHD. Note the GUID that is returned by this command; use it in place of GUID in the following commands.

  4. bcdedit /set GUID device vhd=[C:]\Windows7Ultimate2.vhd

    Set the device for the new boot configuration to the Windows7Ultimate2.vhd file on drive C. (Note: Use the "[C:]\..." syntax exactly as shown above with the square brackets.)

  5. bcdedit /set GUID osdevice vhd=[C:]\Windows7Ultimate2.vhd

    Set the OS device for the new configuration to the Windows7Ultimate2.vhd file on drive C. (Note: Use the "[C:]\..." syntax exactly as shown above with the square brackets.)

  6. [Reboot and choose the new ""Windows 7 VHD" option]

    Boot into the new VHD.

    Note: If that doesn't work, please have a look at the end of this document and try the "detecthal on" step. I haven't found this to be necessary, so I haven't listed it - but if others find that it's helpful, I'll call that out.