Creating Bootable Virtual Hard Disks
Creating Bootable Virtual Hard Disks
Applies To: Windows 7, Windows Server 2008 R2
In addition to attaching VHDs (see Creating Virtual Hard Disks), you can create VHDs that are bootable. Bootable VHDs are VHDs that contain a Windows image. You can create bootable VHDs by using either of the following methods:
Using the Disk Management Tools
This section describes how to create a bootable VHD by using the Disk Management tools. You create a VHD and then apply a Windows image from a .wim file to a partition in the VHD. After you complete the steps in this section, you can configure the VHD for native boot or configure it to boot in a virtual machine by following the instructions in Preparing Virtual Hard Disks for Boot.
Before you continue, ensure that you have the following prerequisites:
- A computer that is running Windows 7 or Windows Server 2008 R2
- Access to media that contains the Windows 7 or Windows Server 2008 R2 installation files
|You can use the Windows Image to Virtual Hard Disk (WIM2VHD) command-line tool to automate many of the steps in this section such as creating .vhd files and applying a .wim file to the .vhd. To download WIM2VHD, see the MSDN Code Gallery (http://go.microsoft.com/fwlink/?LinkId=155155). To use WIM2VHD, your computer must be running Windows 7, Windows Server 2008 R2, or Windows Server 2008 with Hyper-V enabled. WIM2VHD also requires that you have installed the Windows AIK to use ImageX.|
- Step 1: Create and attach a VHD
- Step 2: Locate the install.wim image to apply to the VHD
- Step 3: Apply a Windows image to the VHD
Step 1: Create and attach a VHD
If you do not already have a VHD that you want to use, use the following procedure to create a VHD.
|If you prefer, you can use the Disk Management MMC snap-in to perform these steps. For instructions, see Creating Virtual Hard Disks.|
To create and attach a VHD
- To start the DiskPart command interpreter, open an elevated Command Prompt window (click Start, right-click Command Prompt, and click Run as administrator), and then type:
- Create and attach a VHD by using Diskpart. The following example creates a dynamically expanding VHD that has 25 GB maximum size and saves the VHD file in the folder, C:\vhd.
Step 2: Locate the install.wim image to apply to the VHD
The next step is to locate an image of the Windows 7 or Windows Server 2008 R2 operating system (.wim) to apply to the volume in the VHD. You can find a .wim image at the following locations:
- The product DVD. The installation image is located at \sources\install.wim.
- A Windows installation that you have captured to a .wim by using ImageX.exe or the Image Capture Wizard for Windows Deployment Services.
- An .iso image. An .iso image combines all the installation files into a single uncompressed file. These images are available to MSDN and TechNet subscribers, and they are also available from the Windows Products Home page (http://go.microsoft.com/fwlink/?LinkId=155370). You must mount .iso images or burn them to physical media to access the .wim files within the .iso file.
Note The Windows Preinstallation Environment (Windows PE) image in Boot.wim does not support native VHD boot.
The Install.wim (on the Windows product DVD) contains multiple images for different versions of the operating system, and each image has an index. The following table shows the index values for the supported editions of Windows.
|Index||Operating System Edition|
Windows 7 Enterprise
Windows 7 Ultimate
Windows Server 2008 R2 Standard (Full Installation)
Windows Server 2008 R2 Standard (Server Core Installation)
Windows Server 2008 R2 Enterprise (Full Installation)
Windows Server 2008 R2 Enterprise (Server Core Installation)
Windows Server 2008 R2 Datacenter (Full Installation)
Windows Server 2008 R2 Datacenter (Server Core Installation)
Windows Web Server 2008 R2 (Full Installation)
Windows Web Server 2008 R2 (Server Core Installation)
Step 3: Apply a Windows image to the VHD
There are two ways that you can apply a Windows image to a VHD.
- Use the ImageX command-line tool. If you have the Windows AIK installed on your computer, you can use ImageX to apply a .wim to a VHD. If you do not have the Windows AIK, you can download it at Windows Automated Installation Kit for Windows 7. The Windows AIK download is an .iso image that you burn to a DVD and then install on your computer. After installing the Windows AIK, ImageX is located in the Windows AIK\PE Tools directory. Use the following procedure titled “To apply a Windows image to a VHD by using ImageX”.
- Use the Install-WindowsImage.ps1 Windows PowerShell script. Windows PowerShell is included in Windows 7 and Windows Server 2008 R2. The Install-WindowsImage.ps1 script has fewer options than ImageX, and it does not require you to download the Windows AIK. However, using this method will require you to learn how to use Windows PowerShell if you are not currently familiar with it. If you have never used Windows PowerShell, see Getting Started With Windows PowerShell(http://go.microsoft.com/fwlink/?LinkID=204238).
This script can perform two tasks: display a list of images in a .wim and apply a .wim to a partition in a VHD. To use this method, first download this script at Install-WindowsImage PowerShell Script (http://go.microsoft.com/fwlink/?LinkId=204240). Then use the following procedure titled “To apply a Windows image to a VHD by using the Install-WindowsImage.ps1 script”.
To apply a Windows image to a VHD by using ImageX
- Click Start, click Microsoft Windows AIK, right-click Deployment Tools Command Prompt, and click Run as administrator.
- To view information about the versions of Windows in the .wim image, type the following command:
imagex /infoThe output lists the metadata for all the images in the .wim file. View the
element for each of the images in the output, and note the index of the image that you want to apply to the VHD.
- Use the following syntax to apply the Windows image from the install.wim to the VHD volume, using the applicable index.For example, the following command applies the Datacenter version of Windows (index number 5) from the install.wim (from DVD media in drive F) to the VHD partition (drive V).
Note It takes approximately 10-15 minutes to apply the image. If you are applying a .wim from a network file share instead of from local media, use a wired network connection for a faster network connection speed.
Now that you have created a VHD file and applied a Windows image to it, you can configure it for native boot or configure it to boot in a virtual machine by following the instructions in Preparing Virtual Hard Disks for Boot.
To apply a Windows image to a VHD by using the Install-WindowsImage.ps1 script
- Click Start, and type PowerShell in the Start text box.
- In the results pane, right-click Windows PowerShell, and then click Run as Administrator.
- To list the images and index numbers in a .wim, use the following syntax:
- To view the Help for this script, type:
- To apply an image from a .wim to a VHD, use the following syntax:
Note The first time you run Windows PowerShell, an error message may appear that tells you that unsigned scripts cannot be loaded because scripts are disabled on the computer. If you receive this error message, you need to set the Windows PowerShell execution policy to allow unsigned local scripts, but still require signed scripts from remote locations. To configure this, run set-ExecutionPolicy RemoteSigned at the Windows PowerShell command prompt.
In the following example, drive D is the DVD drive with the Windows product DVD, and drive V is the VHD that you created in Step 1:
You can use Hyper-V Manager to create bootable VHDs. You may prefer this method because there is a user interface that leads you through the process. VHDs that you create by using Hyper-V Manager are configured for virtual machine boot by default. To configure the VHD for native boot, follow the instructions in the “Prepare a VHD image for native boot” section of Preparing Virtual Hard Disks for Boot.
To create a bootable VHD by using Hyper-V Manager
- Start Hyper-V Manager (click Start, click Administrator Tools, and click Hyper-V Manager).
- Click Action, click New, and then click Virtual Machine.
- Specify a Name and Location for the new virtual machine, and then click Next.
- Specify the amount of memory to allocate.
- Click Next on the Configure Networking screen.
- Select Create a virtual hard disk, specify the storage location and maximum size for the VHD, and then click Next.
- Select Install an operating system from a boot CD/DVD-ROM, and then select the physical CD/DVD drive or the .iso file.
- Click Next, and then click Finish. A new virtual machine will be created in the Off state.
Use the following procedure to start the new virtual machine and install the operating system.
To start the virtual machine
- Right-click the new virtual machine.
- To add a DVD or a virtual DVD to a virtual machine, click Settings.
- Under IDE Controller, select DVD Drive.
- Specify one of the following, and then click Apply:
- If installing from a physical DVD, select Physical CD\DVD drive, and then specify the drive letter.
- If installing from a bootable .iso file, browse to the path under Specify the media to use with your virtual CD\DVD drive, click Image file.
- Select the virtual machine from the Virtual Machines pane, and then in the Actions pane, click Connect.
- Click Actions, and then click Start.
- When you are prompted to Press any key to boot from CD\DVD, press a key and proceed with the installation.
Now that you have created a VHD, you can configure it for native boot by following the instructions in Preparing Virtual Hard Disks for Boot.