How to Boot from a VHD
This topic is a how to. Please keep it as clear and simple as possible. Avoid speculative discussions as well as a deep dive into underlying mechanisms or related technologies. |
Since Windows 7 and Server 2008 R2, it is possible to boot from a [[VHD (Virtual Hard Disk)]] file.
Note that you can only boot a VHD which has been created using Windows 7 or 2008 R2 or later, and you must configure the boot loader from an active installation of Win7 or 2008 R2. You can't use Virtual PC VHDs, only Hyper-V or raw VHDs . Don't try to reuse an existing VHD, start a new one for boot use.
Boot from an existing VHD
You need to edit the bootloader from within Windows, using the [[bcdedit]] command-line tool. To do this follow the steps below:
- Launch a Command Prompt as an administrator
- Type: bcdedit /copy {current} /d "VHD_Boot"
- Copy the long {CLSID} number given in the output, and use it in the following commands
- Note that {curly braces} are required
- You can change the drive letter and path of your VHD, but the square brackets on the drive letter are required
- Type: bcdedit /set {CLSID} device vhd=[C:]\disk1.vhd
- Type: bcdedit /set {CLSID} osdevice vhd=[C:]\disk1.vhd
- Type: bcdedit /set {CLSID} detecthal on
- To check the settings, type: bcdedit
- When you reboot, you will have the option to "VHD_Boot" as if it were a local installation.
Boot with other inbox or vendor drivers
If the VHD was used to boot a Hyper-V VM, then the Operating System (OS) installed inside the VHD is configured to boot using default inbox IDE drivers (“IntelIDE”). This might not be the case for the physical system that you're going to boot. Your physical hardware may require a different driver (either inbox or vendor-supplied) to boot an OS. This is particularly true in case of SATA and/or RAID controllers..
- Mount the VHD under existing and running OS.
- Launch Registry Editor ("%SystemRoot%\RegEdit.exe").
- Load System Registry Hive from the OS installed into VHD ("<Your mounted VHD>\Windows\System32\Config\System").
- Locate the Current Control Set key using the value named “Current” under "<Your loaded hive>\SYSTEM\Select" key.
- For example, if “Current” value has Data equal 0x00000001 then Current Control Set key is "<Your loaded hive>\SYSTEM\ControlSet001".
- Under Current Control Set key locate the driver in question at "<Your loaded hive>\SYSTEM\ControlSet001\Services".
- For example, for popular series of Intel ICH RAID controllers built into many desktop PCs the key is "<Your loaded hive>\SYSTEM\ControlSet001\Services\iaStorV".
- Locate “Start” value for the above-mentioned key. If the driver was not used, then the current value would probably be 4. Change it to 0 (zero).
- For SATA drive configured as AHCI you need find the key "<Your loaded hive>\SYSTEM\CurrentControlSet\Services\Msahci" and repeat the 6th step.
- Unload the hive you loaded in step 3.
- Quit Registry Editor.
- Unmount the VHD.
Add a new driver to existing OS installed inside the VHD file
If your hardware requires a custom mass storage driver provided by third-party vendor to boot an OS you need to inject that driver into the OS installed inside the VHD to make it bootable on your hardware.
- Locate the driver package on hardware manufacturer's website, download and unpack or extract it. You need to obtain the “essential” driver package consisting of one or more instances of all the following three file types (no archives or executive installers allowed!).
- Installation information (a file with “.inf” extension).
- Driver's binary (a file with “.sys” extension).
- Digital signature catalog (a file with “.cat” extension).
- Mount the VHD under existing and running OS. The driver injection method described here assumes you're running Windows 7 or Windows Server 2008 R2 environment.
- Execute the following command:
"%SystemRoot%\System32\DISM.exe" /Image:"<Path to your mounted VHD>" /Add-Driver /Driver:"<Path to the driver's installation information file>"
Note: you need to provide the path to the file obtained on step 1 that has “.inf” extension.For example, assuming that
- your VHD is mounted under “C:\Offline” folder;
- your need to add the 64-bit driver for AMD AHCI RAID controller and
- the driver files are located at “C:\Driver”,
you should run:
"%SystemRoot%\System32\DISM.exe" /Image:"C:\Offline" /Add-Driver /Driver:"C:\Driver\ahcix64s.inf"
- Unmount the VHD.
Remove an entry from the bootloader
If you need to undo the operation described above and revert to single-boot configuration.
- Launch a Command Prompt as an administrator
- Type: bcdedit
- Copy the {GUID} for the relevant boot option
- Type: bcdedit /delete {GUID} /cleanup
See Also
If you need to perform an opposite convertion operation see [[articles:How To: Convert a VHD-Bootable Image into Hyper-V VM]].