Megosztás a következőn keresztül:


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

  • Using Hyper-V

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

Note

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 (https://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.

Note

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

  1. 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:

    Diskpart
    
  2. 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.

    create vdisk file=C:\VHD\test.vhd maximum=25000 type=expandable
         select vdisk file=C:\VHD\test.vhd
         attach vdisk
         create partition primary
         assign letter=v
         format quick FS=NTFS label=VHD
    exit
    

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 (https://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

1

Windows 7 Enterprise

4

Windows 7 Ultimate

1

Windows Server 2008 R2 Standard (Full Installation)

2

Windows Server 2008 R2 Standard (Server Core Installation)

3

Windows Server 2008 R2 Enterprise (Full Installation)

4

Windows Server 2008 R2 Enterprise (Server Core Installation)

5

Windows Server 2008 R2 Datacenter (Full Installation)

6

Windows Server 2008 R2 Datacenter (Server Core Installation)

7

Windows Web Server 2008 R2 (Full Installation)

8

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 (https://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 (https://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

  1. Click Start, click Microsoft Windows AIK, right-click Deployment Tools Command Prompt, and click Run as administrator.

  2. To view information about the versions of Windows in the .wim image, type the following command:

    imagex /info <path to .wim>

    The output lists the metadata for all the images in the .wim file. View the <DESCRIPTION> element for each of the images in the output, and note the index of the image that you want to apply to the VHD.

  3. Use the following syntax to apply the Windows image from the install.wim to the VHD volume, using the applicable index.

    imagex /apply <path to .wim> <image_index> <path to VHD>
    

    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).

    imagex /apply F:\sources\install.wim 5 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](gg318056\(v=ws.10\).md).

To apply a Windows image to a VHD by using the Install-WindowsImage.ps1 script

  1. Click Start, and type PowerShell in the Start text box.

  2. In the results pane, right-click Windows PowerShell, and then click Run as Administrator.

  3. To list the images and index numbers in a .wim, use the following syntax:

    C:\Vhd\Install-WindowsImage.ps1 -WIM <path to .wim>
    
  4. To view the Help for this script, type:

    help .\Install-WindowsImage.ps1 –detailed
    
  5. To apply an image from a .wim to a VHD, use the following syntax:

    C:\Vhd\Install-WindowsImage.ps1 –WIM  <String> -Apply –Index  <Int32> -Destination <Drive>
    

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:



PS C:\vhd> .\Install-WindowsImage.ps1 -WIM D:\sources\install.wim


Index   Image Name
[1]     Windows Server 2008 R2 Standard (Full Installation) 
[2]     Windows Server 2008 R2 Standard (Server Core Installation) 
[3]     Windows Server 2008 R2 Enterprise (Full Installation) 
[4]     Windows Server 2008 R2 Enterprise (Server Core Installation) 
[5]     Windows Server 2008 R2 Datacenter (Full Installation) 
[6]     Windows Server 2008 R2 Datacenter (Server Core Installation) 
[7]     Windows Web Server 2008 R2 (Full Installation) 
[8]     Windows Web Server 2008 R2 (Server Core Installation) 


Done. 

PS C:\vhd> .\Install-WindowsImage.ps1 -WIM D:\sources\install.wim -Apply -Index 5 -Destination V:  

Applying "Windows Server 2008 R2 Datacenter" to V:... 
WARNING: This may take up to 15 minutes... 

Elapsed Time: 00:10:57.6302827
Done.

Using Hyper-V

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

  1. Start Hyper-V Manager (click Start, click Administrator Tools, and click Hyper-V Manager).

  2. Click Action, click New, and then click Virtual Machine.

  3. Specify a Name and Location for the new virtual machine, and then click Next.

  4. Specify the amount of memory to allocate.

  5. Click Next on the Configure Networking screen.

  6. Select Create a virtual hard disk, specify the storage location and maximum size for the VHD, and then click Next.

  7. Select Install an operating system from a boot CD/DVD-ROM, and then select the physical CD/DVD drive or the .iso file.

  8. 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

  1. Right-click the new virtual machine.

  2. To add a DVD or a virtual DVD to a virtual machine, click Settings.

  3. Under IDE Controller, select DVD Drive.

  4. Specify one of the following, and then click Apply:

    1. If installing from a physical DVD, select Physical CD\DVD drive, and then specify the drive letter.

    2. 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.

  5. Select the virtual machine from the Virtual Machines pane, and then in the Actions pane, click Connect.

  6. Click Actions, and then click Start.

  7. 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.