Windows

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.

23 comments
DavidJenssen
DavidJenssen

I tried the proposed solution with what i consider a minor change. I already have Windows 7 x86 as a virtual machine in a Windows 7 x64 installation. I used diskpart to select the .vhd file for the Windows 7 x86 installation and then attached this vdisk. The only difference from this article should be the path to the .vhd file. When i reboot, the .vhd file is not longer mounted, hence the boot manager can't find it. I can add a .cmd file to mount it when starting windows, but then it will be to late to boot from it. Why doesn't this work if the article's solution works?

bus66vw
bus66vw

I'm not sure I see the point. Why? Is this more like a profile tester?

h681
h681

Legal??! Is it legal to have 2 (two) installs of the same OS with the same key running at same time? What happens when it comes to registering the 2nd (upto 7th) installation(s) with MS? Does the "Trial" period of 30 days apply here? (I think maximum is upto 90 days with a hack somewhere)

albertspijkers
albertspijkers

Nice to have a dualboot option on a virtual harddrive of Windows 7. This makes it possible to have a version you go online with and a primary version for more secure applications. This makes it interesting also to install a version on VHD on your own workstation and use it as a template for distibution to client machines. Saves on hardware for the IT department.

bill.gorman
bill.gorman

Does it require that the host PC have hardware virtualization support?

johnpowers6
johnpowers6

I'm curious that since 7 has XP Mode which runs VHDs, is there a method, or tool, I can use to create a VHD of my existing XP system (while it's running would be ideal)? I would like to create the VHD of my running system, install Windows 7 from scratch, then use my VHD.

Mark W. Kaelin
Mark W. Kaelin

Are you testing Windows 7 for your enterprise? Did you know you could create VHDs in this manner?

jbfleischauer
jbfleischauer

Can this VHD be used on another machine with different hardware such as moving from a Toshiba laptop to a HP desktop?

Greg Shultz
Greg Shultz

...because with this technique, you are using your actual hardware: CPU, RAM, Video... the only thing that is virtual is the hard disk. That's why this technique allows you to have the best of both worlds!

Greg Shultz
Greg Shultz

...and unfortunately, I haven't been able to find good answer. What you propose makes sense, but there doesn't seem to be a tool from MS that will convert an XP installation into a VMC / VHD configuration. Even if there were, it would have to take a lot of configuration changed to make the transition from real to virtual hardware. I'll keep my eyes open though. Anyone else have ideas...

Royc_1
Royc_1

I support several people running different apps. If I can use this on 1 system I can charge a lot less to work with Win 7. Now I have a separate machine for each person so I can research the answer and get it right without tying up their system.

mccolld1
mccolld1

Does it completely isolate the VHD installs from the primary (or host) OS and other physical hard drive files? In other words, when operating in a VHD instance, can one access files outside the VDH? I'm looking at this as an alternative to Virtual PC sandboxes for internet access without virtual OS overhead and virus/malware/spyware protection overhead.

wobblyo
wobblyo

I tried this technique (with Vista already installed) and went all the way through (including entering my Windows 7 license details) until the final reboot when Windows 7 stated my license was not vaild for a virtual install!! Most frustrating and a wasted a couple of hours of my time.

anne.powel
anne.powel

Allows us to test some apps without having to allocate another machine. Could be very handy. Thanks!

tehpea
tehpea

Yes, I am, and it seems to flow more than Vista used to... i'm running 4 pcs and i'm probably gonna get Windows 7 Ultimate x64 upgrade edition for all pcs :) Seems to have been a step forward, wp Microsoft!

kb2tdu
kb2tdu

2 questions: is an install like this "saveable" i.e. can I do my install then backup the directory, and restore it later to put the install back to a "fresh" state? Like a sandbox that I can recreate without the (admittedly easy) Win 7 install? AND is it "legal" to install Win 7 multiple times this way with one activation code (post-RC)? It's on 1 PC, the same PC, the only diff being the hard drive from the OS' point of view, and only 1 of the installs can be used at a time. I can't see M$ being too porky about it, but then ...

Dogcatcher
Dogcatcher

Thanks for the absolutely on-point post.

johnpowers6
johnpowers6

Hey, that's really terrific! Thanks for the post. I think this will drop a huge barrier to Windows 7 migration.

h681
h681

Would this be possible using Acronis 2010? As far as I understand this program supports writing\recovering to VHD. If so, you could make an image of your existing setup and then boot into VHD and using Acronis TI 2010 recovery\emergency disk there restore the saved (Acronis) image to the VHD. Ernie

Master0fPuppets
Master0fPuppets

You can use Ghost to image the partition, then it can be converted to VHD (using winimage) or VIM (using WAIK tools) depending on what you need to do with it.

johnpowers6
johnpowers6

Thanks. I'll keeping digging too. It seems like such a good idea that someone must have a solution.

Greg Shultz
Greg Shultz

...Once you create the VHD file, you can make a copy of it and use the original. When you are ready for a "clean install," just load the copy. I've have to spend some time reading the EULA to see how "legal" such an installation set is, but it is definitly possible and would appear to be legal because you can only use one intallation at a time. However, we'll have to wait until after October 22nd to tell for sure how the real Windows 7 code will react to this type of configuration...

Editor's Picks