Step-By-Step: Turning a Windows 7 DVD or ISO into a Bootable VHD Virtual Machine
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
- Frequently Asked Questions: Virtual Hard Disks in Windows 7
- Windows(R) Image to Virtual Hard Disk (WIM2VHD) Converter
- MikeKol's Virtual Blog
- Windows Automated Installation Kit (AIK) for Windows 7 - For this, all I needed was the imagex.exe, but the Kit includes LOTS of stuff that IT folks and OEMs care about.
- Screencast from Keith Combs on Dual-Booting VHD using Windows 7 and Windows Server 2008 R2
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.
About Newsletter
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.
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?
Now I've got a 5 gig VHD file
I thing 5 GB is the size of the dynamically expanded drive.
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.
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.
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.
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
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
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?
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.
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.
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.... ;)
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
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.
Comments are closed.