I already wrote about installing Windows 7 (and their Windows 2008 R2 cousin) into VHD (Virtual Disk) file, but there is a quicker way of doing it. You don’t even need to go through installation process.
On MSDN, script appeared that does conversion from .wim files to VHD. As you may know, .wim is extension of Windows Imaging Format that serves as installation image from Vista onward. This script just reads this file and using native Windows 7 VHD mounting (yes, you need to have Windows 7 for this) creates new virtual disk with Windows installed inside of it (only Windows 7 and above). This speeds things considerably since there is no booting inside installation, loading it’s drivers or even answering any questions (for that you need to use unattended answer file).
This tool has much more possibilities that described here (e.g. applying of patches) but I will go only into installing base system.
Creating virtual disk
In order to create bootable windows you can call script (in elevated prompt – administrator rights are required):
cscript.exe WIM2VHD.wsf /wim:X:\sources\install.wim /sku:ULTIMATE /vhd:"D:\Virtual Machines\Native\Windows7.vhd" /size:20480 /disktype:Fixed
INFO: Inspecting the WIM...
INFO: Creating a Fixed VHD. This can be a time consuming process...
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.
Notice that here X: is Windows 7 installation disc (or Windows 2008 R2, works the same).
Only required parameters are /wim and /sku, but I wanted to include /vhd, /size and /disktype in order to make same .vhd file like in original post. Do be carefull since it overwrites without any questions.
If you are wondering how to find which /sku value you should use, you can check which ones are available with:
cscript.exe WIM2VHD.wsf /wim:X:\sources\install.wim
Error: 0: The supplied WIM does not contain a(n) "UNSPECIFIED" image.
Possible images are:
In order to boot from this disk image, you need to work a little with bcdedit. I will not describe it here since it is same procedure as booting from any other VHD file. For booting inside of Hyper-V or Virtual PC, there is no need for any action other that attaching VHD to virtual machine.
Don’t forget to install Windows Automated Installation Kit. If you do forget, you will get rather unhelpful message (Error: 0: No filePath was specified. This file was marked as critical.) and script will refuse to do any work. This same message will appear if imagex.exe cannot be found (usually at C:\Program Files\Windows AIK\Tools\amd64 or C:\Program Files\Windows AIK\Tools\x86). Just put it in PATH environment variable and you will be fine.
Is it any good?
Whole process took around ten minutes. Installation step took only four minutes (rest was creation of fixed VHD) which is much faster than DVD based installation. It does leave you at Out of Box Experience (some five minutes more), but if you really need speed, you can prepare answer file and that step is gone.
If you need to install Windows 7 into VHD (not only on your native system but also for use with Hyper-V or Virtual PC) this is a way to go.
[2009-05-13: Updated with Windows 7 RC links]