Scott Hanselman

Step-By-Step: Turning a Windows 7 DVD or ISO into a Bootable VHD Virtual Machine

August 04, 2009 Comment on this post [31] Posted in Tools | Win7
Sponsored By

I'm loving the Windows 7 "Boot to VHD" lifestyle. This isn't Virtual Machines, to be clear, and it's not Dual Booting. It's Boot to VHD.

Let me break it down:

Method Pros Cons
Dual Booting Your OS's always run at full speed. You can screw up your partition table. You have to partition which means disks of fixed size. Or you can have them all share the same disk, which is dangerous.
OS's aren't portable.
Virtual Machines Your OS's are completely separate from each other and can't hurt one other. Your OS's are very portable. You get Undo support for your disks. Everything is virtualized, so you're taking a perf hit on pretty much everything. Often not a good solution for laptops.
Boot to VHD Your OS runs on the hardware directly, except your disk, which is virtualized and runs inside a single file. Estimated 3%-5% perf hit. Seriously. Also is awesome on a laptop if you have the HD space. None! But I'm biased! Neener neener!

Only works on internal drives or ESATA. No USB Drive support. No undo disk support.

Making a VHD is easy with Windows 7 since you can create and mount/attach VHDs in the standard tools. VHD as a disk format is built into the Operating System (although, strangely, you can't mount ISOs.).

You can create a blank VHD, set it up in your boot menu with BCDEdit (details and walkthrough here and a video demo here) and then just boot off your VHD. If you want to install your OS (Windows Server 2008 and Win 7 Enterprise or Ultimate are the only ones supported) then you just install away.

However, this is STILL not convenient enough for me.

I'm always trying crazy new Daily Builds of big stuff that takes a while to be installed. The step where I install an OS onto my VHD takes too long, so I'd like a prepared VHD that's already to be started for the first time, kind of like when you buy a machine from Dell or whoever and you get that nice "starting your computer, detecting drivers" action on first boot.

Well, there's a script over at the MSDN Code Gallery to help with this. It's the Windows Image to Virtual Hard Disk Converter (WIM2VHD).

From their description:

The Windows(R) Image to Virtual Hard Disk (WIM2VHD) command-line tool allows you to create sysprepped VHD images from any Windows 7 installation source. VHDs created by WIM2VHD will boot directly to the Out Of Box Experience, ready for your first-use customizations. You can also automate the OOBE by supplying your own unattend.xml file, making the possibilities limitless.

Fresh squeezed, organically grown, free-range VHDs - just like Mom used to make - that work with Virtual PC, Virtual Server, Microsoft Hyper-V, and Windows 7's new Native VHD-Boot functionality!

I like this guy already.

How to SysPrep your Windows 7 Image

I copied my Windows 7 DVD to a folder on a drive with lots of space free. I probably didn't need to copy it over, but it likely made the process faster.

Then I downloaded and installed the Windows® Automated Installation Kit (AIK) for Windows® 7. This file is a large ISO (1.5G) so be aware. It's meant for admins, not humans. I didn't want to burn the ISO to disk, so I used 7-Zip to open the ISO as an archive and extract it. (If you're not using 7-Zip, you're missing out on life, BTW)

Now, go into C:\Program Files\Windows AIK\Tools and find ImageX.exe and copy it where you put the Windows Image to Virtual Hard Disk Converter (WIM2VHD) script.

Go read the Example Command Lines for Win2VHD, but since I had a Windows 7 Ultimate I ran this command-line. Note that d:\win7working is where I copied my DVD.

cscript wim2vhd.wsf /wim:d:\win7working\sources\install.wim /sku:ultimate

In this example, d:\win7working is the folder I copied the DVD to. Could be your DVD drive too, I suppose.

It chewed for a while, maybe seven minutes. You'll also here the "Device Plugged In" sound as the script automatically connects a VHD as a drive temporarily so don't panic:

D:\>cscript wim2vhd.wsf /wim:d:\win7working\sources\install.wim /sku:ultimate
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

Windows(R) Image to Virtual Hard Disk (WIM2VHD) Converter
Copyright (C) Microsoft Corporation. All rights reserved.
Version 6.1.7100.2

Check for updates at http://code.msdn.microsoft.com/wim2vhd!

MACHINE INFO:
Build=7600
Platform=amd64fre
OS=Windows 7 Ultimate
ServicePack=
Version=6.1
BuildLab=win7_rtm
BuildDate=090713-1255
Language=en-US

INFO: Looking for IMAGEX.EXE...
INFO: Looking for BCDBOOT.EXE...
INFO: Session key is E765F413-44E9-4F9B-AEA5-DBC8A726F7A6
INFO: Inspecting the WIM...
INFO: Configuring and formatting the VHD...
INFO: Applying the WIM...
[ 100% ] Applying progress
INFO: Making the VHD bootable with BCDBoot...
INFO: Unmounting the VHD...
Summary: Errors: 0, Warnings: 0, Successes: 1
INFO: Done.

Magical. Now I've got a 5 gig VHD file that I can setup to boot from directly as described here. The first time I start up, it'll be 95% into the setup process and just ready to detect my hardware. It's a nice "OEM-like" VHD that I can use again and again.

Since I'm only using these VHDs temporarily (for a week or two for testing) I won't use an activation key and instead leave that field blank during setup. That'll buy me 30 days of testing if I need to, and I can easily start over by just starting over with my new fresh VHD.

Enjoy! Now go tell Mike and his team that they're awesome. Go ahead. I'll wait here.

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 bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service
August 04, 2009 8:45
Excellent, I didn't even know about the Win 7 VHD stuffs. Time to check it out and find the details on running it with Vista. I can see others have done this, which is good.
August 04, 2009 8:59
And of course there's a nice screencast of the process at http://blogs.technet.com/keithcombs/archive/2009/05/22/dual-boot-from-vhd-using-windows-7-and-windows-server-2008-r2.aspx
August 04, 2009 11:33
Great writeup. A nice mention also would have been that to use VHD's, and Microsoft Virtual PC, requires that your processor is either AMD-VTM or Intel VT-x capable that it can support virtualization.
August 04, 2009 11:56
Krolly - No, that's not the case. VT extensions are only required for CPU Virtualization like that used by Virtual PC. The BootToVHD solution I'm describing doesn't have this limitation. It's not really virtualizing anything but the disk.
August 04, 2009 13:56
I've been booting to VHD since the RC came out and the only con that I have noticed is that boot time is slightly longer, maybe another 5 secs longer? I ran some performance tests (memory, cpu, disk access etc..) comparing VHD vs Boot VHD vs native and the difference between Boot VHD and native were negligible.

The only other thing which could be improved is the setting up process. It is still a bit of a faff though with articles like it gets a bit easier.
August 04, 2009 15:04
Now I've got a 5 gig VHD file

Sounds wunderful, but what can you do to increase the vhd size? With 5GB i doubt that you can do a lot of demos, the vhd will run full in an instant, or am I wrong?
August 04, 2009 17:07
Is there any way I can include installation programs of my preference and automate the installation of those programs after the VHD is booted ? is it possible or do I have to manually install all the programs ?
August 04, 2009 17:21
Stupid question but, I assume each VHD OS image requires one to purchase a copy of Windows 7 for each one ?

August 04, 2009 17:23

Now I've got a 5 gig VHD file

I thing 5 GB is the size of the dynamically expanded drive.
August 04, 2009 21:30
Interesting post, I like what I've read so far. What I'm looking for is a way to keep a Windows XP Pro system running - I have a very specialized USB film scanner (which doesn't have Vista drivers). My current XP computer died (bad motherboard). I only need to boot into XP when I need to scan something.
August 04, 2009 22:26
Martin - I hear what you're saying, but after doing this a half dozen times, I can say it does get easier with familiarity.

Jakob - Sorry, I was unclear. It's 5 gigs, but it THINKS it's 40 gigs. It grows. ;)

Freefly - As I understand it, using the AIK you can preinstall some programs (I think) and pre-apply service packs and hotfixes (I know).

Steve - Only if you activate them. And I don't.

Robert - Then you should use the Virtual XP technology.
August 05, 2009 19:07
Thanks for the write up, Scott!

Did I read correctly that you can't do the VHD boot with Windows 7 Professional? That's really too bad. It's a really cool feature. I played with it on the Beta release. However, if it's only supported on Ultimate (super-expensive) and enterprise (not available to me or my company -- we're too small), then I won't get any benefit from it.

['ll have to go back and talk to my friends/co-workers. I had been citing the VHD boot feature as a major reason that a developer or technical person would want to upgrade to Windows 7. It sounds like only the big corporate installations (or those willing to shell out megabucks for Ultimate) will get to play with it.
August 05, 2009 23:30
Can you run multiple bootable VHD simultaneously? With Virtual PC, you can have multiple VMs running concurrently provided you have enough RAM and fast CPU.
GQ
August 05, 2009 23:32
GQ - No...only in Virtual PC.
August 05, 2009 23:41
Can you have windows 7 on the physical machine and windows xp/vista on the VHD? or does this only apply to windows 7 VHD?
August 05, 2009 23:49
dabiddo, for the BootToVHD it's a Win7/Win2008R2 only thing. If you want to run Windows XP or Vista under Win7, you can use VHDs and Virtual PC for Win7 (free download).

However, there IS a Vista hack (search for it) for Boot to VHD that basically replaces the boot code in Vista and lets you have Vista as a host and boot to a Win7 VHD, as I recall.
August 06, 2009 4:21
Since Win7 allows me to make an image-based backup to VHD, can you add that VHD to your Boot Environment? This would be a great way to create different configurations and/or roll back your machine via VHD Boot.
August 10, 2009 0:35
This is a great solution until Windows 7 is broadly released. After that I'd hope the IE App Compat VPP images are updated so you can get the same thing with no mucking about. http://www.microsoft.com/Downloads/details.aspx?FamilyID=21eabb90-958f-4b64-b5f1-73d0a413c8ef&displaylang=en
August 10, 2009 11:45
One other tidbit - I didn't want to install the AIK just to get the 470KB ImageX.exe. It's a silly shortcut, but you can just open the ISO in 7-Zip and extract KB3AIK_EN.iso\Neutral.cab\F1_imagex, then rename it to imagex.exe. Worked with this script, and I didn't have to bother with install / copy file / uninstall.

Here's a screenshot of how it looks in 7-Zip:
http://www.screencast.com/users/jongalloway/folders/Jing/media/d0d78c3b-8a28-4af5-bf15-76fe3bb3269f
August 12, 2009 1:10
This is pretty cool. Totally worked. Have only tested it in Virtual PC so far though. But I must say, differential disks are nice! Can just set the vhd made by wim2vhd as read-only and use it as a parent for other disks. Does that work when booting to vhd too? Or is it just a Virtual PC thing?
August 17, 2009 6:42
The VHD mounting idea is great, but from watching the setup video, there is still much that needs to be improved on the setup process. Make the setup process a wizard, similar to bootcamp.

To me this appears some manager said, who cares get it out the door.
-Make it prettier
-Make it easier

Great idea, but no follow through, appears to be half-done. Can't wait to see a finished product!

Ben
August 18, 2009 9:28
Scott, do you know whether a VHD create using imagex can then be booted via Hyper-V?

I currently get a "Boot failure. Reboot and Select proper Boot device or Insert Boot Media in selected Boot device" when I create a new HyperV VM and add this VHD.

Any suggetions?
August 18, 2009 10:38
Just to follow up on my comment above.

I came across this post about need a boot configuration entry for the VHD.
http://www.ravichaganti.com/blog/?p=317

But even doing this caused my Hyper-V image to blue screen...in Safe Mode! :-( I figure it must be some device driver that is installed in that VHD pertinent to my bare metal machine I'm running the VHD on. I found this gem on the link you sent through:
sysprep /generalize /shutdown

Need to try this when I get time.
August 26, 2009 2:06
A little tip: The Windows EULA allows you to "rearm" Windows 7 up 3 times giving you a total of 120 trial days. To do so run "slmgr -rearm" from a command prompt with admin rights. Do this as close to expiration as possible since you get 30 extra days from the day you do this.
September 11, 2009 5:05
I have Win7 Ultimate as a host OS and am trying to boot a WinServer 2008 Enterpize VHD. I followed all of the instructions outlined in the blog. Everything goes smooth up until I attempt my first boot into the Win 2008 VHD. I am then greeting with a dialog telling me that my Boot Configuration is Corrupted (Error 0x490).
October 16, 2009 1:54
Does this work when the native OS is x64 and the VHD is x86? I can boot into the VHD but get an error about "setup cannot configure this computer to run windows" and then it exits.
January 14, 2010 4:14
Just a quick couple of notes I found when trying this:

You can use the /size:<vhdSizeInMb> parameter in the command line to set the size you want the VHD to grow to so you can have larger disks. If not set it defaults to 40GB.

WIM2VHD only runs on Win7 or Win2k8 Server. That's pretty obvious from the website but my Win7 machine is brand new with no tools on it yet, so I tried to do this on my XP machine without reading first. Gave me an error about a regkey that only exists on Win7/Server 2008. Oh well.

Hey Jon Galloway, thanks for the tip on grabbing just the ImageX tool. I was wondering about this but thought it might require something else that's installed behind the scenes.
February 25, 2010 21:36
It is time for someone to post a link to pre-hardware driver install images for all possible windows operatiing systems. it would be nice it Microsoft did just that.

I want to run all of my windows 2008 R2 servers just like this, but I have so many hardware flavors. a 2008 R2 vhd image pre-hardware and license would be perfect.

Anyone got it? Willing to give gold on some game server.... ;)
March 08, 2010 20:13
It runs fine on window 2008 Hyper-V

The problem that I am having is as follow:

I am able to setup the vhd as dual boot, but when I selected from the list I am getting the following error:

Windows is loading file…
Status Repair is checking your system for problem

System repair cant repair this computer automatically


Session Detail:
System disk = \device\harddisk0
Windows directory =
Auto chk Run = 0
Number of root causes = 1

The log for the test performed

Name Result Error code Time taken
Check for update Completed successfully 0x0 0 ms
System disk test Same Same Same
Disk failure diagnosis Same Same 141 ms
Disk metadata Same Same 47 ms
Target OS test Same Same 140 ms



Root cause found
Boot configuration is corrupt
Rapair action: partition table repair
Result: failed: Error code = 0x490
Time taken = 2870 ms
March 18, 2010 0:08
So I'm running Windows 7 32 bit currently.

My hardware is in fact 64 bit.

Could I sysprep the 64bit version of Win7 from my 32bit OS, create a VHD of it, and boot natively into it?

Are there any issues with doing this?

Thanks.
March 24, 2010 1:53
Yes, you can boot either 64 or 32 bit.

Comments are closed.

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