By: Ray Barley | Updated: 2011-03-15 | Comments (1) | Related: > Testing
Problem
I need to setup a virtual environment for development and testing. I've heard about a new feature in Windows 7 and Windows Server 2008 R2 called boot from a virtual hard disk (VHD) which allows you to create multiple VHDs and select them from the boot menu on startup without having to partition your hard drive to achieve multi-boot. I have a need for SharePoint and SQL Server test and development environments. Can you provide the details of how to set this up?
Solution
Boot from VHD is a great feature that you can use to quickly and easily create multiple environments for testing and development purposes. At a high level you create a VHD, install an operating system, then edit your boot menu so that you can now boot your machine from a VHD. After booting from the VHD you are running your operating system of choice, you can install whatever software you need, and everything is contained in the single .VHD file on your hard drive.
Over the years I've used VMWare as well as Microsoft's Virtual PC, Virtual Server, and Hyper-V to do my development and testing in a virtualized environment. Boot from VHD works best for me given that my development hardware is a single laptop computer. Booting directly from a VHD allows me to pick which environment I want without having to partition my hard drive. Boot from VHD is a built-in feature that is only available with Windows 7 (Enterprise or Ultimate) and Windows Server 2008 R2 at this time.
In this tip I'll discuss some prerequisites that you need, then walk through the steps to create a Windows Server 2008 R2 VHD, add it to the boot menu, and boot from it. I'm running Windows 7 Ultimate on my laptop.
Prerequisites
Just to reiterate you need a machine with Windows 7 or Windows Server 2008 R2 running on it to begin. You will also need the following:
- Installation media for the operating system (Windows 7 or Windows Server 2008 R2) you want to use to create the VHD; this can be a CD, DVD, or .ISO file. There are multiple utilities available to crack open the .ISO file; I use WinRar. After installing WinRar you can right click on the .ISO file, then select one of the extract options from the menu to copy all of the files from the .ISO file to the folder of your choice.
- Download and install the Windows Automated Installation Kit (AIK) for Windows 7 which contains some utilities that we need; if you are running Windows Server 2008 R2, there is a link for that version.
- Download and install the Windows Image to Virtual Hard Disk (WIM2VHD) Converter which is a utility that we can use to create the VHD; WIM2VHD requires the Windows Automated Installation Kit.
- To make things simple, create a folder called VHD where you will store the VHDs that you create; e.g. C:\VHD. WIM2VHD includes the windows script file WIM2VHD.wsf; copy it to your VHD folder.
Create the VHD
After downloading and installing the prerequisites, open a Command Prompt as an administrator (right click on the Command Prompt in the programs list and select run as administrator from the popup menu). Change directory to your VHD folder. Locate the install.wim file in the sources folder of your operating system media. The install.wim file contains the operating system image that we will use to create the VHD.
The install.wim file contains various editions of the operating system. To see the list of available operating system editions, run the following command (assuming the full path to the install.wim file is e:\wim\2008r2\install.wim):
cscript wim2vhd.wsf /wim:e:\wim\2008r2\install.wim
Within the output on the screen you will see the list of operating system images available; e.g.:
Possible images are: SERVERSTANDARD SERVERSTANDARDCORE SERVERENTERPRISE SERVERENTERPRISECORE SERVERDATACENTER SERVERDATACENTERCORE SERVERWEB SERVERWEBCORE
Type the following command to create the VHD (specify one of the available images for the /sku parameter):
cscript wim2vhd.wsf /wim:e:\wim\2008r2\install.wim /sku:SERVERENTERPRISE /vhd:c:\vhd\win08r2.vhd /disktype:dynamic /signdisk:true
Make sure to specify the location of your install.wim file and the location where you want to create the VHD. On my laptop it took approximately 12 minutes to create the VHD. The size of the VHD is a little bit less than 7 gigabytes. You now have a bootable VHD file that you can use to run Windows Server 2008 R2 Enterprise Edition.
Edit the Boot Menu
The BCDEdit tool is used to edit the boot configuration data. Follow these steps to add the VHD file we just created to the boot menu (run the commands as an administrator in a Command Prompt window):
Step 1
Create a new BCD entry by copying the current one; i.e. the BCD entry I selected when I booted my laptop:
bcdedit /copy {current} /d "Windows 2008 R2 Enterprise for MSSQLTips"
The following is the output from the command:
The entry was successfully copied to {fea962cd-fa46-11df-8f2b-c89c3867dbab}.
You will need the GUID from the above output for the remaining commands. Note that your GUID will be different than the one shown above.
Step 2
Specify the device for the new BCD entry:
bcdedit /set {fea962cd-fa46-11df-8f2b-c89c3867dbab} device vhd=[C:]\vhd\win08r2.vhd
Step 3
Specify the osdevice for the new BCD entry:
bcdedit /set {fea962cd-fa46-11df-8f2b-c89c3867dbab} osdevice vhd=[C:]\vhd\win08r2.vhd
Step 4
Set the new VHD as the default (optional):
bcdedit /default {fea962cd-fa46-11df-8f2b-c89c3867dbab}
The default is the OS that will boot if you don't select one.
Step 5
Review the BCD entries (optional):
bcdedit
A portion of the output is shown below; this is the entry for the VHD that I created for this tip:
Windows Boot Loader ------------------- identifier {fea962cd-fa46-11df-8f2b-c89c3867dbab} device vhd=[C:]\vhd\win08r2.vhd path \Windows\system32\winload.exe description Windows 2008 R2 Enterprise for MSSQLTips locale en-US inherit {bootloadersettings} recoverysequence {fea962c5-fa46-11df-8f2b-c89c3867dbab} recoveryenabled Yes osdevice vhd=[C:]\vhd\win08r2.vhd systemroot \Windows resumeobject {fea962c3-fa46-11df-8f2b-c89c3867dbab} nx OptIn
Boot from the VHD
Restart your machine and you will see "Windows 2008 R2 Enterprise for MSSQLTips" as one of your options in the boot menu. Select that option and you will be running Windows Server 2008 R2.
Next Steps
- There are quite a few more things you can do with a VHD; e.g. the VHD can be used with Virtual PC, Virtual Server and Hyper-V. I haven't done that yet myself.
- When you're thinking about a development and test environment for SharePoint, SQL Server, etc. give this a try. I think you'll be pleasantly surprised.
About the author
This author pledges the content of this article is based on professional experience and not AI generated.
View all my tips
Article Last Updated: 2011-03-15