次の方法で共有


VHD Boot

With Windows 7 and Server 2008 R2 you get the opportunity to boot directly from a vhd file. The operating system in the vhd file will have direct access to the machine hardware. It will not run as a virtual machine with synthetic or emulated adapters, but as a “real machine”. VHD happens to be the format that is used to represent a disk to the o/s. The physical disk will contain a set of vhd files and still be visible as a disk to the o/s you boot. Thus, you won’t require a partition per o/s.

Assuming that you are running Windows 7 or 2008 R2, here’s how you can set it up:

1. Create a vhd file to contain your o/s.

I found that 15 GB are enough for Server 2008 R2 + Hyper-V role (you can enable any role on the o/s in that VHD). You can use diskpart from the command line or the disk management tool. Make sure to select a fixed disk size.

image

Mount that vhd file, e.g. to drive letter W:

2. Apply a WIM image to the VHD file you just created.

You can generate a WIM image of a pre-installed “golden” machine with the imagex tool, part of the Windows Automated Installation Kit (WAIK)

You can use the WIM image provided with the Windows installation media in sources\install.wim

If all you have is an iso file (e.g. a 2008 R2 evaluation version you’ve just downloaded), there are utilities like MagicISO which will let you mount it as a disk, so you can use the install.wim within the file.

The simplest way to apply the wim image is to use the Install-Windowsimage powershell script, which you’ll find on MSDN. The installation media contains several versions of Windows, so make sure you select the one you are licensed for.

In powershell, type:

.\Install-WindowsImage.ps1 -WIM D:\Sources\Install.wim

to obtain a list of the available images on your installation DVD (D:\). Note the index number of the image you are interested in.

Type

.\Install-WindowsImage.ps1 -WIM D:\Sources\Install.wim -Apply -Index 3 -Destination W:\

to apply the 3rd image on the VHD drive you mounted previously (W:\)

3. Make the VHD bootable

Open a command prompt and type:

W:\windows\system32\bcdboot w:\windows

Bcdboot creates the boot control data (bcd) block to boot Windows from the vhd file and sets it as default option.

4. Check the bcd entry and set your preferred default

At an administrator’s command prompt, type:

bcdedit /v

image

Note the identifier of the entry that you want to use as default boot option.

Type:

bcdedit /default {identifier}

to set the default.

That’s it – you can now boot from your vhd file.

You need not stop here, however: there is no need to start from a regular o/s installation: you can configure vhd boot from the installation media and have all your Windows o/s boot from vhd files. Keith Combs explains how on his blog.