Microsoft

Expand the number of Windows 7 installs with bootable VHDs

Microsoft has made available several techniques that you can use to create a bootable Windows 7 VHDs that run like a dual boot setup.

When you begin experimenting with Microsoft Windows 7, chances are good that you'll want to have several installations of the new operating system on which to test various configurations, settings, and applications. While you could install Windows 7 on several machines for your test environment, wouldn't it be great if you could quickly and easily create several installations on the same system?

You're probably thinking that this idea is nothing new; you can set up a dual-boot system or use Windows Virtual PC to easily create several installations of Windows 7 on the same PC. Well, what if I told you that you can combine these two techniques and get the best of both without having to actually partition your disk for dual booting and without actually having to use a separate virtual management system such as Windows Virtual PC? And, best of all, because the hard disk is the only thing being virtualized, you can actually take advantage of all the power your hardware has to offer!

I recently learned that Microsoft has made available several techniques that you can use to create bootable Windows 7 virtual hard disks (VHDs) that run like a dual-boot setup. For example, you can convert a Windows 7 Windows Image Format (WIM) file to a VHD, you can Sysprep an existing Windows 7 VHD, or you can create a VHD using the Windows 7 DVD and the DiskPart command.

The technique that you choose will depend on what you have to start with. If you have a Windows 7 WIM file or an existing Windows 7 VHD file, you can easily use the first two techniques. If you don't have either of those files, you can use the third technique. Each one of these techniques are relatively painless to perform once you know the necessary steps.

In this edition of the Windows Vista and Windows 7 Report, I'll show you how to create a VHD using the Windows 7 DVD and the DiskPart command. (I'll cover the other techniques in future editions.)

This blog post is also available in PDF format in a free TechRepublic download.

Caveats

Before you use one of these VHD techniques, you need to understand that there are some limitations. First, these VHD techniques are designed to work on top of an existing Windows 7 installation. (Supposedly, you can make it work in Vista, but you have to replace the Boot Manager with the one from Windows 7. However, I have not experimented with that option as of yet.) Second, you cannot use Hibernation on the VHD. Third, you cannot boot a VHD from a Windows 7 installation that is secured with BitLocker nor can you use BitLocker on the VHD.

(At this point, I'm going to assume that these techniques will be available only in the Windows 7 Professional, Ultimate, and Enterprise.)

Getting started

As I mentioned, this technique is designed to work on top of an existing Windows 7 installation. You'll begin by creating a folder in which you will create the VHD. I suggest that you create it in the root folder to make accessing it easy. On my example system, I created the folder win7vhd in the root directory, as shown in Figure A.

Figure A

Begin by creating a folder in which you will create the VHD.
Now, insert the Windows 7 DVD into your drive and restart the system. When the system boots from the DVD, follow along with the prompts as you normally would. When you get to the Install Windows screen, as shown in Figure B, click the Repair Your Computer link.

Figure B

When you get to the Install Windows screen, click the Repair Your Computer link.

While the next screen is loading, press [Shift]+[F10] to open a command prompt window.

The DiskPart commands

Once the command prompt window opens, you'll use a series of DiskPart commands to create and prepare the VHD file. Keep in mind that when you boot from the CD and open the command prompt window, your host hard disk will be temporarily moved up one letter. On my example system, the host hard disk moved up from drive C to drive D. As such, I'll path to the win7vhd folder on drive D.

To create and prepare the VHD file:

  1. Type the command: diskpart
  2. Once the Diskpart environment is ready, create a VHD file called win7 that is expandable up to 20GB, by typing the command: create vdisk file="d:\win7vhd\win7.vhd" type=expandable maximum=20000
  3. Next, select the vdisk by typing the command: select vdisk file="d:\win7vhd\win7.vhd"
  4. Now, attach the vdisk by typing the command: attach vdisk

This entire procedure is illustrated in Figure C.

Figure C

After each command, you should see a success message.

Installing Windows 7 on the VHD

Once the VHD is created, you can install Windows 7 on the VHD. To begin, type Exit to leave the Diskpart environment and then click the Close button the close the command prompt window. You may also have to close the Repair window by clicking the Close button.

When you return to the Install Windows screen, shown in Figure B, you can click the Install Now button. You'll work your way thru the initial Installation wizard screens by accepting the license terms and choosing the Custom (advanced) installation.

When the Installation wizard prompts you to choose where you want to install Windows, select the new VHD. It will be designated as Unallocated Space and be the size that you specified in the DiskPart command. When you select the VHD, you'll see a Warning message that says that Windows cannot be installed to this disk. You'll also find a more detailed explanation of the problem, as shown in Figure D.

Figure D

While the Installation wizard will warn you that Windows cannot be installed to this disk, you can ignore the warning.

Even though the Installation wizard indicates that Windows cannot be installed to this disk, you can ignore the warning as the procedure does indeed function correctly. In fact, the installation procedure will progress quite rapidly and restart several times as it completes the installation on the VHD just like it would on a normal hard disk.

Booting the VHD

When you restart Windows 7, you'll see the Windows Boot Manager menu and you'll see that the Installation wizard names each installation Windows 7, as shown in Figure E. Now, by virtue of being the last installed, the VHD installation should be at the top of the list and be set to the default.

Figure E

Choose your installation of Windows 7.

If you want to rename and change the default start order, you can use the BCDEdit command. To change the name, boot into an installation, open an Administrator command prompt, and use the command:

BCDEdit /set description "New Name"

For example, you can boot into the VHD and use the command:

BCDEdit /set description "Windows 7 VHD"

To change the default, boot into the installation that you want to be the default and use the command:

BCDEdit /default {current}

What's your take?

What do you think about being able to create bootable Windows 7 VHDs that run like a dual-boot setup? Will this be something that you will use to test Windows 7? If you have any questions or comments concerning this VHD technique, please take a moment to drop by the TechRepublic Community Forums and let us hear from you.

TechRepublic's Windows Vista and Windows 7 Report newsletter, delivered every Friday, offers tips, news, and scuttlebutt on Vista and Windows 7, including a look at new features in the latest version of the Windows OS. Automatically sign up today!

About

Greg Shultz is a freelance Technical Writer. Previously, he has worked as Documentation Specialist in the software industry, a Technical Support Specialist in educational industry, and a Technical Journalist in the computer publishing industry.

Editor's Picks