Scenario 1: Configuring Native VHD Boot on a Single Computer
Applies To: Windows 7, Windows Server 2008 R2
The goal of this scenario is to gain familiarity with the steps that are required to enable native VHD boot by using an existing installation of Windows 7. Alternatively, you can use Windows Server 2008 R2 in this scenario as the steps are the same for both operating systems.
Note
Only Windows 7 Enterprise or Windows 7 Ultimate can be used with native VHD boot.
In this scenario, you will create a VHD and apply an image to the new VHD by using tools from the Windows Automated Installation Kit (Windows AIK). Then, you will alter the BCD store so that you can boot to the operating system within the VHD. To summarize, you will take the following steps:
Install the Windows AIK
Create a VHD through the user interface
Mount the VHD and create a partition on it
Apply Windows 7 to the VHD
Configure the BCD store
To illustrate, Figure 1 represents the disk layout and placement of the VHD disk for this scenario.
Figure 1 Disk and VHD configuration for this scenario
Scenario prerequisites
Before you proceed, ensure you have the following available:
A computer running Windows 7 Enterprise, Windows 7 Ultimate, or Windows Server 2008 R2
The installation media for Windows 7 Enterprise, Windows 7 Ultimate, or Windows Server 2008 R2
Note
If you have Windows 7 or Windows Server 2008 R2 in the .iso format, extract the .iso files as flat files or burn them to a DVD
- Media that contains the Windows AIK installation files (https://go.microsoft.com/fwlink/?LinkID=154426)
Step 1: Install the Windows AIK
Before you create a VHD file, you need to install the Windows AIK on the local computer. This kit is full of utilities for deploying and maintaining images (.wim files and .vhd files). To install the kit, use the following procedure.
To install the Windows AIK
Browse to the location where you stored the Windows AIK media and double-click Startcd.exe.
In the User Account Control dialog box, click Yes.
In the left pane of the Welcome to the Windows Automated Installation Kit page, click Windows AIK setup.
On the Windows Automated Installation Kit Setup Wizard page, click Next.
On the License Terms page, select I agree, and then click Next.
Select an appropriate installation folder or leave the default setting, and then click Next.
On the Confirm Installation page, click Next and wait for the installation to finish.
After the installation has finished, click Close to exit the Windows AIK setup.
When the installation is successful, you have installed all the tools that you will need. The primary tool you will use in this scenario is ImageX, which you will use to apply the image to the VHD. But before you can apply the image, you need to create the VHD as explained in the next step.
Step 2: Create the VHD
To store the VHDs that you will create, this example scenario uses a local folder, C:\VHD Files. However, you can use any name and location that you desire. Instead of storing VHDs in a subfolder, you could store them in the root of the drive. Use the following procedure to create a VHD by using the user interface.
To create a VHD by using Disk Management
On the start menu, right-click Computer, and then click Manage.
In the User Account Control dialog box, click Yes.
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 following settings, and then click OK:
Location: C:\VHD Files\WIN7.vhd
Virtual hard disk size: 50 GB
Virtual hard disk format: Dynamically expanding
You should create a dynamically expanding VHD only when you want to save on the amount of initial disk space that you use. With this option, only a small VHD is created initially, and it will grow dynamically as you add data to the VHD. However, using this type of file has an impact on performance because not all blocks are consistently written next to each other on the physical disk. For servers or workstations where performance is of concern, you should consider creating a fixed-size VHD.
Note
If this is the first time that you have created a VHD, an indicator appears in the notification area to inform you that a driver is being installed.
The next thing you need to do is initialize the disk. In Disk Management, right-click the 50 GB disk that you just created (notice that the VHD is distinguished with a light blue icon), and then select Initialize Disk.
On the Initialize Disk page, ensure that the VHD you just created is selected and that MBR is the selected partition style. Click OK.
After the disk is initialized, you can create a partition on it. Right-click the unallocated space of the disk, and then click New Simple Volume.
In the Welcome to the New Simple Volume Wizard, click Next.
On the Specify Volume Size page, leave the default values (you will use the entire size of the disk as the system volume), and then click Next.
In the Assign Drive Letter or Path list, choose drive letter V:, and then click Next.
Under Format this volume with the following settings, specify the following options, and then click Next:
File system: NTFS
Allocation unit size: Default
Volume label: system
To create the partition, on the Completing the New Simple Volume Wizard page, click Finish.
Wait a few second for the partition to be created. Do not close the Computer Management console yet because you will need it later in this scenario.
Step 3: Apply the Windows image to the VHD
One of the limitations of native VHD boot is that it is only available with Windows 7 Enterprise, Windows 7 Ultimate, or Windows Server 2008 R2 (all editions). Windows image (.wim) files often contain more than one edition of Windows, so you first need to determine the edition (and its “index number”) that you want to use. This is especially true for the Install.wim file that is available on the installation media. In Step 1, you installed the Windows AIK, which contains the tools to determine the index number. In the following procedure, you will search for the index number (in this example Windows 7 Enterprise), and then you will apply Windows 7 Enterprise to the VHD. The tool you will use is new to Windows 7; it is called Deployment Image Servicing and Management (DISM). To perform these steps, use the following procedure.
To apply a Windows image to the VHD
Click Start, point to All Programs, and then click Microsoft Windows AIK.
Right-click Deployment Tools Command Prompt, and then click Run as administrator.
In the User Account Control dialog box, click Yes.
Type the following DISM command to view information about the editions of Windows within the .wim file.
dism /Get-Wiminfo /Wimfile:”C:\Sources\Windows 7 Enterprise\Sources\install.wim”
You will see that there is only one edition of Windows 7 Enterprise available in the .wim file. Remember the index number because you will use it in the next step to apply the data to the VHD.
Note
If you want more information about a specific edition of Windows 7 in the .wim, type /Index:<Number>
at the end of the previous command.
Now that you have the index number, you can apply the data from the .wim file to the VHD. To do this, type the following ImageX command:
imagex /apply ”C:\Sources\Windows 7 Enterprise\Sources\install.wim” 1 v:
Wait for the command to finish. The whole process can take 10 minutes or longer depending on the performance of your computer.
Type
exit
in the Command Prompt window to close it.
Step 4: Change the boot configuration data
You have almost completed the steps that are required for booting to a VHD. The last task is to change the boot configuration data (BCD) store, which is essentially the successor to the Boot.ini file in previous versions of Windows. The default tool for editing the BCD store is the BCDEdit command-line tool.
Next, you will use BCDEdit to add a boot entry to the store. This will enable you to select the VHD when you start the computer. To do this, use the steps in the following procedure.
To change the BCD
Open an elevated Command Prompt window (click Start, right-click Command Prompt, and click Run as administrator).
In the User Account Control dialog box, click Yes.
To take a first look at the BCD store, you will use BCDEdit to view (enumerate) the current Windows Boot Loader entries. To do this, type
bcdedit /enum
. The output will look similar to Figure 2:Figure 2 Default BCD store
You could create a new entry manually, but it is easier to copy the settings from the current boot entry and use that as a starting point. To copy the current entry, type the following command:
bcdedit /copy {current} / d “Windows 7 VHD Boot”
The output will generate a GUID, which is associated with the new boot entry. Take note of this GUID because you will use it to change settings in the next step.
You need to change two crucial settings in the boot loader entry. These settings tell the Windows Boot Manager to look for the VHD during initialization. Type the following commands with the appropriate GUID to alter the device and osdevice settings of the new boot entry.
bcdedit /set {d89f3fa4-6416-11de-b070-b08b383b8f33} device vhd=”[locate]\VHD Files\WIN7.vhd” bcdedit /set {d89f3fa4-6416-11de-b070-b08b383b8f33} osdevice vhd=”[locate]\VHD Files\WIN7.vhd”
The setting [locate] instructs Windows Boot Manager to locate the VHD without requiring you to specify a drive letter.
Because you will be using an installation of Windows 7 in the VHD, you also need Windows Boot Manager to detect the hardware abstraction layer (HAL) during setup. The HAL is basically an interface between the software and hardware of the computer. To enable a setting to make this possible, type the following command:
bcdedit /set {d89f3fa4-6416-11de-b070-b08b383b8f33} detecthal Yes
Note
If you want to set the VHD boot loader entry as the default boot configuration, type the following command: Bcdedit /default {d89f3fa4-6416-11de-b070-b08b383b8f33}
If you run the
bcdedit /enum
command again, you will see the new entry in the output, similar to Figure 3.Figure 3 The new boot entry that enables native VHD boot
You have now created a boot entry for the VHD that you created earlier. Type
exit
in the Command Prompt window to close it.
Step 5: Detach the VHD
The final step is to detach the VHD. This prevents data corruption, which can occur if you restart the computer while the VHD is attached. If the VHD remains attached, files could remain open or locked, and the data on the VHD would eventually be damaged. Just like attaching a VHD, you can detach the VHD by using the Disk Management user interface. Assuming that the Computer Management console is still open, use the following procedure to detach the VHD.
To detach the VHD
In Disk Management, right-click the disk that represents the attached VHD, and then click Detach VHD. (Remember that the disk is displayed with a light blue icon.)
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.
You have now completed all the steps to create a VHD, apply an operating system to it, and configure the BCD store so that users can select the VHD when they start the computer. All that remains is to restart the computer and start the installation.