As someone who spends a lot of time at customer sites, I find this invaluable to maintaining a clean, portable secondary environment. My boot-from-vhd enviornment can be joined/disjoined from customer domains without affecting my corporate laptop build; I can run beta apps and install troubleshooting tools without jeopardizing the stability of my daily work computer.
For my installation, I'm using Windows 7 Ultimate as my primary host computer and will install Windows 2008 R2 inside my VM environment.
Requirements:
- Windows Automated Install Kit (necessary for ImageX)
- Windows 2008 R2 Physical Media (or ISO + utility such as Virtual CloneDrive to mount it)
Now, some of you will probaby grumble about needing to download the whole 1.3GB+ WAIK package for less than 1MB of software necessary to perform this task. It does seem ridiculous, that Microsoft has not made it available separately for this specific purpose (and, since WAIK is a free download, most people don't see why you can't just get the tools you need out of it). If you search around, you can find the ImageX pieces available, such as here or here.
If you want to install just the ImageX componets, you need:
- imagex.exe
- intlcfg.exe
- vsp1cln.exe
- wimfltr.inf
- wimfltr.sys
- wimgapi.dll
Extract the files from such a download to C:\Windows\System32; copy wimfltr.sys to C:\Windows\System32\drivers, and then right-click > Install on wimfltr.inf.
Alternatively, download and install WAIK.
Moving on ...
Create a Directory to Store VHDs
- From Windows Explorer, create a new directory (I used C:\VHD).
- Yep, that's it.
Create a VHD
- On the start menu, click Start, type in cmd, and then press Ctrl+Shift+Enter to start an Elevated Command Prompt. right-click Computer, and then click Manage.
- In the User Account Control dialog box, click Yes.
- Type compmgmt.msc and press Enter.
- In the left pane of the Computer Management console, click Disk Management.
- In the right pane, click More Actions, and then click Create VHD.
- On the Create and attach Virtual Hard Disk page, specify the location as C:\VHD\Windows2008R2.vhd, the virtual hard disk size as at 50GB, and then set the virtual hard disk format to Fixed or Dynamically expanding (depending on your preference). If it's not something you're going to use often, you can use a Dynamically Expanding VHD to save space. If you choose Fixed, you're going to have to wait for the entire 50GB (or whatever size file it is) VHD to be formatted.
- Click OK.
- In Disk Management, right-click the newly-created 50 GB disk, and then select Initialize Disk.
- On the Initialize Disk page, verify that the VHD is selected. Choose MBR as the partition style, and then click OK.
- Once the disk is initialized, right-click the unallocated space of the disk, and then select New Simple Volume.
- When the Welcome to the New Simple Volume Wizard starts, click Next.
- On the Specify Volume Size page, leave the default values to use the entire disk, and then click Next.
- In the Assign Drive Letter or Path list, choose an unused drive letter (I chose V:), and then click Next.
- Under Format this volume with the following settings, specify NTFS for the file system, use the default Allocation unit size, specify a volume name Next.
- On the Completing the New Simple Volume Wizard page, click Finish.
Mount the Windows Server 2008 R2 Media (If Necessary)
This example uses Slysoft Virtual CloneDrive
- Navigate to the folder where you have downloaded the Windows 2008 R2 media.
- Right-click the ISO file, and then select Mount (Virtual CloneDrive E:), where E: is the virtual DVD-ROM letter. Mine just so happens to be E:.
Apply the Windows Server 2008 R2 Image to the VHD
- Go back to your Elevated Command Prompt (or launch a new one).
- Run the following command to determine which Windows Server edition you wish to use:
dism /Get-Wiminfo /Wimfile:"E:\Sources\install.wim" - Select an index number that corresponds to the edition that you wish to install. In my case, I chose Index 3.
- Run the following command to apply the installation image in the appropriate index to the VHD that is currently mounted as V:\:
imagex /apply "E:\Sources\install.wim" 3 v:
Update the Boot Configuration Data
We'll use BCDEdit /copy to use the current boot configuration entry as the starting point for our new entry.
- Run the following command from your Elevated Command Prompt:
bcdedit /copy {current} /d "Windows 2008 R2 VHD Boot" - Copy the newly-created GUID to the clipboard.
- Run the following commands (using the new GUID) to instruct the Boot Manager where to look for the VHD:
bcdedit /set {enter-new-GUID-here} device vhd="[locate]\VHD\Windows2008R2.vhd”
bcdedit /set {enter-new-GUID-here} osdevice vhd="[locate]\VHD\Windows2008R2.vhd” - Run the following command to force hardware detection during the initial boot:
bcdedit /set {enter-new-GUID-here} detecthal yes - Close the elevated command prompt.
Detach VHD
- In Disk Management, right-click the disk that is the mounted VHD, and then click Detach VHD.
- On the Detach Virtual Hard Disk page, ensure that the Delete the virtual hard disk file after removing the disk check box is NOT selected, and then click OK.
- Close the Computer Management console.