Scott Hanselman

Less Virtual, More Machine - Windows 7 and the magic of Boot to VHD

May 22, 2009 Comment on this post [46] Posted in Tools | Win7
Sponsored By

NOTE: This is some advanced stuff and you may lose a finger. No warranty express or implied. There's always workarounds somewhere on the 'tubes, but this stuff works only in Win7 or Windows Server 2008 R2. Be afraid.

I use a lot of Virtual Machines. I've used VMWare, VirtualBox, HyperV and Virtual PC. Recently, since all my machines have been updated to Windows 7 RC, I've downloaded Windows Virtual PC so I could use "Virtual XP." I've got a lot of VHD (Virtual Hard Drive Files) around now.

You can see here where I've got a VM called "Dev10onVista" because I can use not just Windows XP, but also Vista. However, it's still a VM and it's slower than I'd like.

Dan has a great post on the pros and cons of Virtualization vs. Dual Booting. He points out:

  • Multiboot:
    • Good performance (runs natively on the machine, no extra abstraction layers)
    • Good hardware integration (everything that is built into or attached to the machine is visible to the running OS)
    • Clunky setup (different boot loaders overwriting each other, partitions cannot easily be resized or moved around)
  • Virtualisation
    • Very flexible (only takes up as much hard disk space as the solution requires)
    • Can run virtually any Operating System
    • Non-Optimal performance (running piggyback off another Operating System, consuming resource in both)
    • Marginal hardware integration (all major system components are virtual only; depending on the virtualisation solution, SOME components might be surfaced inside the virtual machine)

This is right on. I'm always afraid to multi-boot, concerned that one OS will some how make one of the others angry, as they are all sharing disks.

Virtual Machines

I'm just not willing to install VS2010 Beta 1 on bare hardware just now, as I know I'll want to put the Next Beta on a clean machine. I *could* sacrifice an extra machine, but I'd rather use the main machine I always use. I want less virtual, more machine.

Mounting/Attaching VHDs like Hard Drives

With Windows 7 I can mount VHD and use them like regular hard drives. Just type in "Disk Management" from your start menu. From the Action menu I can select "Create VHD" or "Attach VHD." Below I'd just attached a 7 GIG VHD file that thinks it's a 40 gig hard drive. Notice that the disk icon is blue. This is a really convenient way to just "pass a hard drive around as a file" as well as a nice way to get files on and off VMs that aren't running.

Disk Management (3)

The best part is that I can make one of these during Windows 7 setup (NOTE: This is advanced and may hurt you, your computer, or your cat.) and install Win7 directly to it.

Install Windows 7 to a new, fresh VHD

Assuming you already have a Windows 7 installation, you can boot off the Windows 7 DVD, and when it gets to "Install Now" click "Repair Your Computer." Don't select an installation, then select Command Prompt. (You can also press Shift-F10) to open a command prompt.

From the Command Prompt, run "diskpart."

Make a new VHD on an internal fixed disk:

create vdisk file="C:\win7\win7.vhd" type=expandable maximum=50000

This will make an expandable VHD with a 50Gig max, for example. Now select it and attach/mount it:

select vdisk file="c:\win7\win7.vhd"
attach vdisk

Type "exit" and go back to the setup window and install Win7. Make sure you select the correct disk - the new virtual one!

Setting up your Windows Boot Menu to boot to an Existing VHD

If you have an existing Win 7 VHD already, or perhaps you've taking your Windows 7 installation Disc and "syspreped" a VHD image. Now, from an Administrator Command Prompt, you need to tell the Windows Boot Manager that there's another option. You go:

C:\>bcdedit /copy {current} /d "My New VHD Option"

This will return a GUID. Select it using the Mark command by right-clicking in the Command Prompt and copy it to the clipboard.

Now, using that {guid}, type these commands:

C:\>bcdedit /set {guid} device vhd=[driveletter:]\<directory>\<vhd filename>
C:\>bcdedit /set {guid} osdevice vhd=[driverletter:]\<directory>\<vhd filename>
C:\>bcdedit /set {guid} detecthal on

See the [driveletter:] stuff in brackets? It's NOT obvious, but you need to include those, so:

bcdedit /set {guid} device vhd=[C:]\win7\win7.vhd

You can confirm it's setup with bcdedit /v:. You'll see something like this. The interesting part is at the bottom.

Windows Boot Manager
identifier {9dea862c-5cdd-4e70-acc1-f32b344d4795}
device partition=C:
description Windows Boot Manager
locale en-US
inherit {7ea2e1ac-2e61-4728-aaa3-896d9d0a9f0e}
default {34433bb7-628f-11dc-a941-001a6bcd5d3a}
resumeobject {34433bb8-628f-11dc-a941-001a6bcd5d3a}
displayorder {34433bb7-628f-11dc-a941-001a6bcd5d3a}
toolsdisplayorder {b2721d73-1db4-4c62-bf78-c548a880142d}
timeout 30
custom:45000001 1

Windows Boot Loader
identifier {34433bb7-628f-11dc-a941-001a6bcd5d3a}
device partition=C:
path \Windows\system32\winload.exe
description Windows 7
locale en-US
inherit {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}
recoverysequence {280ffa1b-f8a9-11dd-b0a9-001c26fdc6b4}
recoveryenabled Yes
testsigning Yes
osdevice partition=C:
systemroot \Windows
resumeobject {34433bb8-628f-11dc-a941-001a6bcd5d3a}
nx OptIn
custom:42000002 \system32\winload.exe
custom:45000001 2
custom:47000005 301989892

Windows Boot Loader
identifier {280ffa1e-f8a9-11dd-b0a9-001c26fdc6b4}
device vhd=[C:]\VMs\Win7\Win7.vhd,locate=custom:12000002
path \Windows\system32\winload.exe
description Win 7 VHD - Dev10
locale en-US
inherit {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}
recoverysequence {280ffa1b-f8a9-11dd-b0a9-001c26fdc6b4}
recoveryenabled Yes
testsigning Yes
osdevice vhd=[C:]\VMs\Win7\Win7.vhd,locate=custom:22000002
systemroot \Windows
resumeobject {34433bb8-628f-11dc-a941-001a6bcd5d3a}
nx OptIn
detecthal Yes
custom:42000002 \system32\winload.exe
custom:45000001 2
custom:47000005 301989892

If it doesn't work, you can always run bcdedit /delete {guid} /cleanup and try again.

Here's what my Boot Manager (pressing F8 when I start up my machine) looks like now:

 My Win 7 Boot Manager

Now, I can boot up with my VHD mounted. Am I running a Virtual machine? No. I'm running Windows, on the hardware, with only the DISK Virtualized. I don't work for that team, but I'm guessing I'm losing 3-5% (that number came out of my butt) on the disk side - and nothing anywhere else. How do I know? Well, Windows Experience is smart enough to keep me from checking (although I could use another disk tester tool, but I'll leave that as an exercise to the Reader.).

Performance Information and Tools

I notice that Disk Management still gives me access to my was-C: drive, even though the VHD is now my C. My hardware C: drive got moved down, and it's E: now. Nice than I can still see it!

Disk Management (2)

What does the Device Manager say? It says the Msft Virtual Disk SCSI Disk Drive is there! That's the only "virtual" thing going on here. Notice I've still got my actual Video Drivers (running multiple monitors across multiple display drivers). All my stuff is there, because I've got, forgive me, less virtual and more machine. 

Computer Management

Hey, are those my four processors and my 8 gigs or RAM? Ah, yes, they are.

Windows Task Manager

Love it. I'm going to use the hell out of it.

A few caveats. One, I haven't figured out how boot off a VHD that is on USB or External Drive. I'm looking into it. It may be because there's no drive letter assigned yet, or that I'm an idiot. We'll see. Second, doing this makes your VHD less portable, because if you move it inside Virtual PC or to another machine, all the devices will freak out and try to reinstall (or maybe just not work) so be aware of that.

That said, I'm running Visual Studio 2010 Beta 1 without fear on my awesome hardware with hardware-speeds. Shiny.

Related Links

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
May 22, 2009 3:32
you can also mount diff disks via the PARENT= command in DiskPart. only downside is the BCD Edit commands are manual, but you have them all listed here.

works pretty well so far!
May 22, 2009 3:41
what about doing difference disks?
May 22, 2009 3:49
Thanks Scott.

This look amazingly useful!

Will definitely try this on my work laptop. The lack of noticeable performance drop is quite attractive. It's worth a reboot for legacy dev environments I rarely use.
May 22, 2009 4:44
Great article!

Something for a future article: is is possible to easily do physical to virtual on Virtual PC? I've thought this could be handy to keep a copy of the installation when I rebuild my PC. If I leave behind some important file on the old machine, I can boot it up in Virtual PC to check.
May 22, 2009 6:20
Sounds great, Scott, except for one thing.

The version of Windows 7 that does double duty as a Virtual machine and a real machine will almost undoubtedly run afoul of Activation and Genuine Advantage.

People do this right now using Windows XP under VMWare:

If you can use your pull to get THAT problem solved without a headache, then you have really accomplished something. :)
May 22, 2009 6:38
Hi Scott,

Great post! I really like the bcdedit details you shared.

I have been dying to try Windows 7 RC on real hardware. Been playing with the Windows 7 Beta for a while in Virtual PC 2007 sessions but I know I wasn't getting a true test of it's capabilities.

I had seem some posts about the VHD boot support in Win 7 and some methods to dual boot with that method. However both my laptops are Vista and I really didn't want to pave them to make room for Win 7.

Eventually enough material was posted to allow me to hobble together swapping the vista boot loader file with the updated one in Windows 7 (which supports VHD booting).

GSD How To: Dual Boot Windows 7 on Vista via VHD file- shameless blog post self promotion.

I swapped them out, then created my VHD file and set it to be a boot option. Then I installed Windows 7 RC...but this time the 64-bit version for grins.

Worked absolutely fine on both our systems. What amazed me most was that I didn't have to find a single driver for either laptop. Period. And our systems are originally running Vista 32-bit. I was concerned that (as laptops often have specialized OEM drivers) would be a deal-breaker jumping to 64-bit Windows 7 but it wasn't. Go figure.

So now I can dual-boot both laptops. My original 32-bit Vista installs are still in place and I can go back and forth. Also, as you pointed out, because the "real" drive is still listed, I just made shortcuts to my portable apps, docs, etc. on that system and can still access and run them without "installing" them in the Windows 7 64-bit system. Amazing!

Subjectively, like you observe, I can't tell any performance hit at all by operating off the VHD disk in Windows 7. But then Windows 7 RC seems soooo much smoother and consistent than my Vista installation ever did. Even after Vista SP1 got installed, I'm still getting stutters and freezes under Vista when I copy/transfer files and even delete the recycle bin contents. None of that happens under Windows 7.

I've got my teen-daughter's third laptop to go and here is my "project". I'm welcome to any thoughts on it.

It is XP Home, with 512 MB RAM and a 64-bit supported processor. Because it is XP and not Vista, I can't do the Windows 7/Vista bootloader file swap like I did before. Instead, I'm going to capture a WIM image of the primary partition that has the XP system. Then format it, and install the Vista 64-bit system on it.

Then I'm going to create the VHD file and attach to it in Windows 7.

Then with one of my handy Win PE 3.0 boot disks, I will dump the WIM image containing the original XP system into it.

This should allow me to then boot the original XP system as an option.

Because all the hardware is the "same" I shouldn't need to do any sysprep on it.

I know, it's madness, madness...but it's just so darn geeky fun to do!

Windows 7 is really impressing me with the additional "tricks". Most average consumers probably won't care, but to a sysadmin/geek, this is pure bliss.

Also, the free EasyBCD 1.7.2 utility seems to be working fine for Windows 7 as well since it is Vista compatible. Some folks might find the GUI interface it provides helpful for tweaking the boot loader options rather than the command-line bcdedit method. However...some care should be used as Windows 7 does not appeart to be officially supported by this tool..yet.


--Claus V.
May 22, 2009 7:06
Sounds really cool. But lots of details.

I almost prefer building a new bootable VM image and have something that is more portable.

The thing I hate about Virtual XP and the VPC that's installed is that I have not found a way to turn off hardware assisted virtualization. You cannot have VPC and VMWorkstation running at the same time. As soon as a VM Workstation VM starts up, it dumps with a CPU error. I was able to get around this on VPC 2007 by just making sure hardware assistant was turned off and turned on under VM Workstation (since I used that the most).

If the both can co-exist nicely under Win7, I'd be even more enclined to use the Virtual XP for routine things.

Oh well --
May 22, 2009 8:02
Great post...just have one question:

When you install Windows 7 to your virtual disk, Windows still refuses to calculate your experience score. Were you able to run the Aero interface (with Aero Peek), or did you get the toned down UI?
May 22, 2009 8:06
You have just made my day. Thanks!
May 22, 2009 8:25
Yes, I did get Aero out of the box because the Video assessment did complete.
May 22, 2009 10:12
I'm just so happy that you're here to figure this stuff out before I even think of trying to hurt myself on something like this. Great article, thanks.
May 22, 2009 11:50
One extra step I had to follow was to sysprep the Windows 7 VHD:
From within the booted VHD (in Virtual PC), open:
Select OOBE, Generalize and Shutdown.

Remember, this will erase all of your user preferences!

Sysprep failed with an error for me the first time, but when I killed a process related to windows media player, it worked (just kill anything starting with wmp in your processes, remember to show processes from all users).
May 22, 2009 12:09
That's some nice stuff!
May 22, 2009 12:16
Great article Scott!
If we could only figure out how to still have the VHDs be portable, we would be dangerously close to Utopia. As you mention, there are device "issues" at the moment. Maybe this could be solved using multiple hardware profiles some how? Last time I used that stuff was on Windows XP, and I'm not even sure Windows 7 has that concept anymore.
May 22, 2009 12:21
Cool - lets see who has the most boot options...
I can think of 4 that I need right now...
May 22, 2009 13:56
Maybe this is a stupid question, but does this work with non-Windows operating systems? ie. could I install Ubuntu into a VHD image and boot it up in this way? Is it HyperV under the hood here? Is it a case of requiring some kernel extension in Ubuntu that makes it compatible with HyperV?

Or is it just Windows OS's that can be booted this way (or in fact, is it just Windows 7 images that can be booted).
May 22, 2009 15:09
What can i say dude, top stuff.

Now i can mount all my winsdows (95- todate) and i am about to run out of drive letters :(

any work around for that?

May 22, 2009 15:51
Second, doing this makes your VHD less portable, because if you move it inside Virtual PC or to another machine, all the devices will freak out and try to reinstall (or maybe just not work) so be aware of that.

Probably very obvious question incoming. If I made a backup of the VHD to say an external drive in case I corrupt it by installing VS2010, is it possible to overwrite the original VHD with the backup and have a "fresh" install of windows without actually installing windows again?
May 22, 2009 18:46
I just saw that "Attach VHD" option the other day. This is a genius move on your part. Excellent post. I'm totally going to try this this weekend and use it from here on out. Game on.
May 22, 2009 18:59
I have also played with having the vhd be on an external drive & still bootable.. Failure.. Would love to see you figure it out Scott. As always, thanks for the information.
May 22, 2009 19:21
Awesome article, that's a really interesting way of using "virtual" machines.

One question though, is there any way (supported or unsupported) to mount a VHD and boot from it like that when my PC runs Windows Vista? I've really been wanting to play around with the Windows 7 RC, but I don't want to use Virtual PC because I lose my video card and I really don't want to attempt a dual-boot with a pre-release OS.
May 22, 2009 19:25
Sorry, that's what I get for posting before reading all the comments. I see that Claus Valca already posted a solution to this. Ignore my previous post.
May 22, 2009 22:02
Hey Scott
One more caveat: the medium on which the VHD is stored needs enough free space to fully expand the VHD to the size the drive is created with (default 127GB) if you're using a dynamically expanding hard disk. If this space isn't available, you're treated with a BSOD on booting the VHD.
May 22, 2009 22:42
only bugging you because you promised it - where are the XSD tools for VS 2008?

ok, it was only a book you wrote for wrox, and I've always been a bit suspect about wrox content, but... it DOES have your name and picture on it! ;).

GL with the fund raising!


PS - I did try your "email" link but that failed with a "CAPTCHA not read" whatever that means - I think it means your tool is broken tho.
May 23, 2009 3:07
Another extremely helpful post- thanks. Have also just upgraded to W7 RC - and have a pet collection of VPCs. Will be experimenting further.
May 23, 2009 6:00
I did this tonight. It works like a charm. Even though the hard drive is visualized everything installed pretty quick. I agree with Scott in that I did not notice a difference in performance. I like this over virtual PC due to the performance different. Since I had to buy a "budget" laptop booting off of a VHD is soo much better then running a virtual PC. Great feature! Greate HowTo!
May 24, 2009 0:06

Have spent much of the Saturday morning trying to complete my "project" on dumping an XP system into a VHD file then setting the Windows 7 boot loader to present that as an option to "dual boot" from.

Got it all set up and had to do some extra bcdedit work to get it to pick up.

Add a Native-Boot Virtual Hard Disk to the Boot Menu - MS TechNet

I was actually able to get it to pass off from the Windows 7 boot loader to the NTLDR within my XP VHD file...but then it consistently errored out.

Turns out (big DOH! to self) that XP doesn't seem to offer the needed VHD drivers/support that Windows 7 brings to the table. And I'm not aware that there is any currently known method to swap the XP NTLDR config with Windows 7 loader.

Yes, you can boot and XP system from within a VHD by using Virtual PC...however the Virtual PC application wraps the VHD around it's hardware abstraction so the XP NTLDR doesn't actually realize it is operating in a VHD. It still thinks it is a physical drive.

Windows 7 boot loader is more sophisticated and can handle this internally just fine without any assistance.

Vista can be "tricked" into working by swapping out it's boot-loader version with the kissing-cousin version in Windows 7. Doesn't seem to be any issue.

At least that's the way it seems to me.

I'm open to suggestions or corrections by anyone....


--Claus V.
May 27, 2009 2:26
Here's some answers. Looks like Boot from VHD off USB isn't supported.

This excellent VHD FAQ has lots more detail as does this post from the team.
June 15, 2009 21:34
I suspect that a Windows Server 2003 VHD is not supported. However, I'm trying it out and getting a specific error related to the boot loader config: "The configuration for an element within the object is invalid in the boot configuration data store."

Has anyone seen this error before and have some insight into what might cause it? Here's my "bcdedit /v" output on the relevant entry.

Windows Boot Loader
identifier {e8684c5d-37ee-11de-a04f-aced438f3deb}
device vhd=[D:]\vhd\my.vhd,locate=custom:12000
path \Windows\system32\winload.exe
description VHD-20090615
locale en-US
inherit {6efb52bf-1766-41db-a6b3-0ee5eff72bd7}
recoverysequence {e8684c5a-37ee-11de-a04f-aced438f3deb}
recoveryenabled Yes
osdevice vhd=[D:]\vhd\my.vhd,locate=custom:22000
systemroot \Windows
resumeobject {e8684c56-37ee-11de-a04f-aced438f3deb}
nx OptIn
detecthal Yes
July 10, 2009 5:33
I'm booting solely to VHD's using Win7 RC now. One 'work' 64-bit build. One 32-bit build for a couple of old games that won't run in 64 (thanks EA C&C devs), and another 64-build 'just in case'.

Problem I have is with the Windows Experience Index (WEI). Whilst it runs and fails, but gets enough of the way through to get Areo working - it doesn't provide a score that other apps might call in order to work.

For example - if you run Windows Live picture gallery, and want to use it for a screensaver with themes turned on - it's impossible without a WEI. The Themes relies on the WEI to work.

So the question is - can you fake out the WEI? I understand there's an XML file in \Windows\Performance\WinSat\Datastore that you could edit to apply a WEI - but I don't think the file needed is generated unless you can complete at least one successful WEI.

Any way to hack in a WEI on a VHD??
July 16, 2009 0:54
Very interesting post, but I'm confused as to how this actually does anything for except to lower your performance. Isn't setting aside 50 GB for a VHD file and booting off it pretty much the same as creating a 50 GB partition and booting off that? I've been running in a Vista/Win7/Win28k multi boot for a long time now (they all share some drives between them) and never had an issue.
July 16, 2009 1:14
Well, Partitions can't be copied to other machines. Partitions are scary and partition tables get screwed up. There's no way boot to VHD can cripple my machine or keep it from booting, but messing with partitions can. With a VHD if I want the space back, I just delete or move the VHD. Also, partitions are fixed in size, while VHDs can start small and grow.

That seems like a lot of really powerful and significant reasons.
July 30, 2009 3:39
Alright, now I'm sold on this as a cool feature once I tried it.

The powerful feature for me was building a VM using Virtual PC (which meant I can keep working and not be stuck in setup mode) and then booting to that VM with mostly real hardware. Very cool!

I didn't notice the VM seemed to be weird when I booted it up as a VM again, but I haven't looked too much into it yet. Overall through, a cool feature to add for developers.

Thanks for convincing me! :)
August 04, 2009 17:03
@James Webster I'm not sure if this works with other operating systems, but for booting Ubuntu from a virtual hd you can use Wubi:
August 05, 2009 23:07
So far I am very impressed with Windows 7. I have created several VMs in Windows Virtual PC and created several bootable VHDs, but I have been unable to create a single VHD that I can boot directly into (for maximum performance) and also launch as a VM in Virtual PC (for convenience when I am already logged into another instance of Windows). Is this possible?
August 05, 2009 23:13
Louis - Nope, not that I know of...if you do that, it'll re-detect the drivers each'll think it's on two different machines.
August 07, 2009 3:59
I ran into the invalid configuration error with the BCD as well. I don't know yet if it's related, but the VHD FAQ that Scott points to includes the following which indicates that you can't boot from VHD if the host volume is encrypted by BitLocker, which mine is:

"Configuring native VHD boot if the host volume is protected by Bitlockerâ„¢. You can save a VHD file on a file system that is protected by BitLocker, but you cannot use the VHD for native boot or enable Bitlocker on the volume(s) that are contained inside a VHD."

I'm in the process of turning off BitLocker to test whether that will allow me to boot to the VHD, and I'll report back with the results.
August 07, 2009 8:52
So, it looks like removing BitLocker is allowing me to boot from the VHD, or at least I no longer get the invalid configuration error message. I initially got an error indicating that the host volume doesn't have enough free space to allow the VHD to expand, but after clearing out some additional space on my hard drive, the initial setup proceeded, and I'm now booted into a Windows 7 Ultimate VHD.

Thanks for the posts detailing how to get this set up, Scott!
August 10, 2009 21:51
I tried the method of booting to the win7 cd to create the vdisk. It's a little bit sketchy to get to the repair area, but that all worked and I was able to create the vhd and attach it. My problem came in when trying to install windows to that new drive. I got the message "Windows cannot be installed to this disk. This computer's hardware may not support booting to this disk. Ensure that the disk's controller is enabled in the computer's BIOS menu." Any thoughts?
August 11, 2009 17:05
im having the same problems re: Windows cannot be installed to this disk. This computer's hardware may not support booting to this disk. Ensure that the disk's controller is enabled in the computer's BIOS menu." Any thoughts?
August 11, 2009 21:53
Arno - Do you have enough disk space? You can get errors or even a BSOD if you're running out of space.
August 21, 2009 0:00
can a single windows 7 ultimate license be used to create multiple vhd installs, or do you have to have a valid license for each one you want to create?
January 27, 2010 23:22
is it possible to re-mount a simple disk vhd during boot? I have a vhd that is simply used for extra drive space, but I need to remount it after each restart.
February 04, 2010 18:12
I read your comments and the main subject. Tried every step more than once and many times but in the end all i find is that windows 7 starts a recovery operation and no OS is loaded

i try to run a Windows server 2003 as a VM without the main OS windows 7 loaded but every time fails

can anyone help me i'd really really appreciate it.
February 08, 2010 17:05
The local disk must have at least two partitions: a system partition that contains the Windows 7 boot-environment files and Boot Configuration Data (BCD) store, and a partition to store the VHD file. For more information about disk partitions, see Understanding Disk Partitions. For more information about adding a Windows 7 boot environment for native VHD boot, see Add a Native-Boot Virtual Hard Disk to the Boot Menu.

The way I read that, is , if you create a new system partition on the external, it will work

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.