Scott Hanselman recently had a post detailing how to setup a virtual hard drive using Windows Automated Installation Kit for Windows 7. It looks surprisingly easy, and I can’t wait to take it for a spin. I’ve copied the how-to part below for future reference:
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!
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 RC. Note this isn't the RTM version. I'm not sure what'll change, but be aware. 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:
1: D:\>cscript wim2vhd.wsf /wim:d:\win7working\sources\install.wim /sku:ultimate
2: Microsoft (R) Windows Script Host Version 5.8
3: Copyright (C) Microsoft Corporation. All rights reserved.
4:
5: Windows(R) Image to Virtual Hard Disk (WIM2VHD) Converter
6: Copyright (C) Microsoft Corporation. All rights reserved.
7: Version 6.1.7100.2
8:
9: Check for updates at http://code.msdn.microsoft.com/wim2vhd!
10:
11: MACHINE INFO:
12: Build=7600
13: Platform=amd64fre
14: OS=Windows 7 Ultimate
15: ServicePack=
16: Version=6.1
17: BuildLab=win7_rtm
18: BuildDate=090713-1255
19: Language=en-US
20:
21: INFO: Looking for IMAGEX.EXE...
22: INFO: Looking for BCDBOOT.EXE...
23: INFO: Session key is E765F413-44E9-4F9B-AEA5-DBC8A726F7A6
24: INFO: Inspecting the WIM...
25: INFO: Configuring and formatting the VHD...
26: INFO: Applying the WIM...
27: [ 100% ] Applying progress
28: INFO: Making the VHD bootable with BCDBoot...
29: INFO: Unmounting the VHD...
30: Summary: Errors: 0, Warnings: 0, Successes: 1
31: INFO: Done.
Magical. Now I've got a 5 gig VHD file that I can setup to boot from directly as described here. Summarized below.
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.
Boot from the VHD:
1. Mouting VHD: 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.
2. Setting up Windows Boot Menu: From an Administrator Command Prompt, you need to tell the Windows Boot Manager that there's another option.
1: 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:
1: C:\>bcdedit /set {guid} device vhd=[driveletter:]\<directory>\<vhd filename>
2: C:\>bcdedit /set {guid} osdevice vhd=[driverletter:]\<directory>\<vhd filename>
3: C:\>bcdedit /set {guid} detecthal on
See the [driveletter:] stuff in brackets? It's NOT obvious, but you need to include those, so:
1: bcdedit /set {guid} device vhd=[C:]\win7\win7.vhd
You can confirm it's setup with bcdedit /v:. If it doesn't work, you can always run bcdedit /delete {guid} /cleanup and try again.