I learned of a tool last year during Geek Week: VDI called Windows Image to Virtual Hard Disk (WIM2VHD) that I’ve started using again recently after shifting my lab to Hyper-V. WIM2VDI has been around since early 2009, so maybe you’ve heard of it. If not, then welcome to the world of easy VHD creation!
Before reading on, you’ll need to download the Windows Automated Installation Kit for Windows 7. You really only need two files out of that 1.6GB package, though, so if you can get your hands on IMAGEX.EXE and BCDBOOT.EXE, just put those in the same folder as WIM2VHD and you’ll be ready to go.
WIM2VHD is actually a WSF script that you point to a .WIM file on the installation media (usually under the Sources folder). Using various configuration options, it takes the information from the .WIM file (Windows Imaging format) and spins it into a VHD file in a fraction of the time it takes to actually install Windows. Then it’s just a matter of creating a new virtual machine and assigning your newly-created VHD (or a copy of it) to the new VM.
When running, WIM2VHD creates and mounts a VHD file, into which it copies all the system files. When finished, it makes the VHD bootable, giving you a portable Windows VM.
A simple command might look like this:
CSCRIPT WIM2VHD.WSF /WIM:D:\Sources\install.wim /SKU:ULTIMATE /VHD:C:\Win7Image.vhd
This command uses the install .wim file located on the installation media, matches the SKU to the installation media so it knows what version of Windows it’s working with, and tells the script where to place the VHD file when done.
In addition to simple commands like this, it is possible to add other parameters. Since each VHD is essentially created as a sysprepped image, you can include unattend scripts to quickly run through setup once the VM is powered on.
You can also specify the VHD size, disk type (dynamic or fixed), and a list of patches to apply at run time. For a full list, check out WIM2VHD’s MSDN page.
One other powerful switch called /passthru allows you to skip VHD creation, while still copying all the relevant files to a destination drive and making it bootable. In theory, this means that you could also use WIM2VHD to create VMDK files. I spent a considerable amount of time looking for a way to do this, though, and I’ve yet to find the right combination of tools that will get the job done.
In general, however, the process would look like this:
1. Create a VMDK disk image that is blank
2. Create a partition on that image
3. Format and the partition and mark it as active (WIM2VHD only marks VHD volumes active, not what it perceives to be a physical disk)
4. Mount it in Windows as a separate drive using a tool like VMware DiskMount
5. Use the WIM2VHD to prepare the disk
6. Unmount the VMDK and boot up your VM
My best result following this basic process was that my VM would boot to a Microsoft error stating that “The Windows Boot Configuration Data file is missing required information.” If someone can come up with a way to do this for VMDK files, I’ll send you an autographed picture of Muppet Gabe, the April Fool’s Day anchor on Brian Madden TV and post the method right here on SearchVirtualDesktop.com. In the meantime, if you’re a XenServer or Hyper-V fan, give WIM2VHD a shot—it can definitely save you some time.
ABOUT THE AUTHOR:
Gabe Knuth is an independent industry analyst and blogger, known throughout the world as "the other guy" at BrianMadden.com. He has been in the application delivery space for over 12 years and has seen the industry evolve from the one-trick pony of terminal services to the application and desktop virtualization of today. Gabe's focus tends to lean more toward practical, real-world technology in the industry, essentially boiling off the hype and reducing solutions to their usefulness in today's corporate environments.