Compartilhar via


How to Boot from VHD (VHD booting re-visited.)

Some while back I wrote about boot from VHD. To re-cap, in Windows 7 and Server 2008 R2 (including core, and Hyper-V Server R2) the boot loader is capable of mounting a VHD file and booting from it as though it were a physical disk. There is no virtualization going on, just the necessary smarts to use the same format. If you try use this to boot older operating systems the boot process will start, but the machine will crash quite early on when it finds the system/boot device(s) aren’t really disks (virtualization hides this fact).

So for it all to work first you need the BootMgr from Windows 7 / Server 2008-R2 (it lurks in the hidden System partition). Obviously you have this if the main OS on the machine is Windows 7 or Server 2008-R2, but if you want add a VHD as a second OS on a system running  Vista / Server 2008 you can just update BootMgr (the easiest place to get it is probably the install DVD) . It supports some new features but the Boot Configuration Database file (BCD) your system already has remains valid – it just doesn’t contain any of the new features so this should have no unwanted side effects.

Second you need a VHD image, into which you have installed an OS which understands boot from VHD. This is easy enough to build in Hyper-V but there are other ways. There are TWO preparation steps which I forgot: the first is that VHD needs to be sysprep’d (%windir%\system32\sysprep\sysprep.exe) otherwise you’ll create conflicting clones. This can be fixed once you have got the OS booting from VHD, but you won’t get it to boot unless you create a boot configuration database on the partition where the OS resides in the VHD. You should be able to do this when you’re building the VHD, or you can mount the VHD and do it after the fact, either way you are looking for  %windir%\system32\bcdboot.exe, you’ll find it on Windows 7 and Server 2008-R2 , but NOT on Hyper-V server and not on older OSes. Run it as bcdboot V:\Windows /s V:    where V: is the volume letter for a mounted Vhd , or the drive letter of of the boot drive if the OS is running in hyper-V. I omitted this step when updating my release candidate set-ups to final code last night and it throws an ugly error. That led to my second mistake: I thought the problem was with the BCD. 

Since I wasn’t thinking clearly (I thought ‘I just do this before I go to bed’ ! ) I went to edit the BCD. Now… after the explanation above you’d be able to work out that you need to edit the BCD with the latest tools (BCDEdit). If you’re working on Windows 7 / Server 2008-R2 you don’t need to worry. But if you’re adding a VHD-Booting OS to a machine running Windows Vista/Server 2008 (which I was) and try to manage boot from VHD with the tools those OSes provided you’ll be on path to frustration, and (in my case) insomnia. After much puzzlement, I ended up back at BCD which would only boot Windows Server 2008, with the right version of BCDEdit.
So I was ready for the third step. I had my files in C:\VHD\Win7.VHD so the 3 commands I needed were to clone the existing entry and modify it for boot from VHD, thus

bcdedit /copy {default} /d "Windows Server 2008-R2 From VHD"

/d specifies the description you’ll see in the boot menu, the command will copy the default entry and return a guid e.g. {cbd971bf-b7b8-4885-951a-fa03044f5d71}, copy the GUID you’ll need it in the next 2 commands. If there is no OS on the drive you can copy the boot folder from the windows setup disk and modify the {default} entry in the same way as you’d modify the copy, just use {default} in place of the guid.

bcdedit /set {cbd971bf-b7b8-4885-951a-fa03044f5d71} device “vhd=[locate]\vhd\win7.vhd”

bcdedit /set {cbd971bf-b7b8-4885-951a-fa03044f5d71} Osdevice “vhd=[locate]\vhd\win7.vhd”

(use your own guid, obviously)

You can check any of the other settings for booting the OS with bcdedit /enum. If they need changing it’s back to bcdedit /set but if it looks right, it’s time to reboot and see if it works. I put this last part into a video I have on TechNet edge which shows some of the other uses of VHD files, but I glossed over making the VHD and getting the right versions of the tools. 

Incidentally in my last post I mentioned the announcement Hyper-v Server now boots from flash provided you have made a bootable flash device the steps above will let you set this up. Be warned though, that to be properly supported the setup will need to be “blessed” by the hardware vendor.

Update. Mark left a comment with a link to a more throrough post than this, just a quick side note though, boot from should work in theory for any Windows7 family OS, including Server 2008 . However in practice there is some work done in HyperV server so that the USB device doesn't get lost for a short time during the boot process. This isn't a problem booting from a hard disk, but will crash the OS booting from USB. So boot from USB is Hyper-V server and Windows-PE only.

Comments

  • Anonymous
    August 17, 2009
    The comment has been removed