Partager via


Using VHD Native Boot with UEFI Firmware - bcdedit vs bcdboot

Recently my team switched to a new internal tool that allows us to reimage our computers from daily Windows builds in the WIM format. Previously we were largely responsible for our own reimaging and given a broad latitude in how we switched between OS installs - some people use Hyper-V VMs, some use dedicated bootable physical disks for each installation, and some like me use Windows' VHD Native Boot feature, where VHD files present on your HDD can be mounted by Windows' bootloader and run from just like a physical disk.

Windows comes with two flavours of bootloader: one for BIOS systems, and a different loader for UEFI systems. The two bootloaders look alike, but can be told-apart because the UEFI bootloader presents "Boot from Device" as one of the root menu options.

Previously, everyone on my team using VHD Native Boot were using Windows' BIOS-based bootloader. This was simple enough to get working, you simply need to boot into your main Windows installation and run these commands from an elevated command-prompt:

 bcdedit /copy {default} /d "Boot from VHD Foobar.vhd"
bcdedit /set {guid} device vhd=[D:]\VHDs\Foobar.vhd
bcdedit /set {guid} osdevice vhd=[D:]\VHDs\Foobar.vhd

(where {guid} is the new GUID returned after running the bcdedit /copy command and D:\VHDs\Foobar.vhd is the path to the VHD file you want to boot from)

The above commands will edit the boot configuration file which is stored on the hidden partition on the physical disk.

Our internal tool that I mentioned at the beginning of this posting converted our computers from the BIOS bootloader to the UEFI bootloader. Ordinarily this isn't a problem, in fact it's a benefit as it enables features like Secure Boot and faster boot times. The problem, however, is that the boot configuration entries added by the bcdedit commands above didn't work!

...more precisely, the bcdedit /copy... commands did add entries to the bootloader configuration, whenever a VHD option was selected from the bootmenu the system would reboot, attempt to mount the VHD, then fail - no error messages were displayed on screen or logged to disk, the system would simply restart and display the Windows 8.x bootmenu again.

After some digging around both the public web and our internal websites I discovered an alternative approach to adding a VHD Native Boot option, but curiously the pages that mention it didn't make references to UEFI booting. The technique is such:

  1. First, remove any existing VHD Native Boot entries from the bootloader that you might have added with bcdedit by running bcdedit /delete {guid} (where {guid} is the GUID of the VHD entry. Run bcdedit /enum ALL to get a complete list.
  2. Mount the VHD or VHDX file by double-clicking on it in Explorer or through Disk Management in Computer Management. The drive letter that the disk is assigned doesn't matter. Let's assume it's K:
  3. In an elevated command prompt, run bcdboot K:\Windows (where \Windows is where Windows is installed on the VHD)
  4. That's it! - Reboot to the bootloader menu by holding down the Shift key while clicking Restart on the Shutdown menu and the VHD should now appear in the "Another OS" submenu.

Comments

  • Anonymous
    April 10, 2014
    Looking at the bcdboot documentation but I am not finding an answer to this question: how do I remove the VHD from the boot-up menu?
  • Anonymous
    April 10, 2014
    @AndyB: I haven't tried that yet, but I think booting into your physical partition's OS and running bcdedit /delete will let you remove the entry that way.
  • Anonymous
    August 01, 2014
    How would you prevent the mounted/ attached .VHD from disappearing everytime you rebooted?PS: For a Win 7 Ultimate SP1 (BIOS machine) VHD made via Disk2VHD and transferred to new Win8.1 Pro host (UEFI) machine, what else do I need to do? Some BIOS to UEFI or MBR/ GPT conversion? Do I need to sysprep it?