Insufficient data from Andrew Fryer

The place where I page to when my brain is full up of stuff about the Microsoft platform

Boot from VHD – help is at hand

I have mentioned the process of booting to a VHD before and if you have tried it you’ll know it’s a bit fiddly and there is potential to cripple your machine if you’re not careful.  I was discussing this with one of the newer members of my division Software Architect Dave Bishop and he has adapted a PowerShell script from Devhawk which takes the guess work out of the process.

# Script name: Create-BCD-Entry.ps1
# Created on: 2010-03-09
# Author: David Bishop
# Extended version based on DevHawk posting

# Purpose: Creating a BCD Entry for a VHD
# Make sure to add the file extension to the VHD name when prompted

$local:windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$local:windowsPrincipal = new-object ‘System.Security.Principal.WindowsPrincipal’ $local:windowsIdentity
if ($local:windowsPrincipal.IsInRole("Administrators") -ne 1)
  throw "Create-BCD-Entry must be run from an administrator account"

Write-Host "Information needed to create BCD entries for the VHD Image"
$name = Read-Host "What do you want the image called at boot-up?"

$file = Read-Host "enter the path and name of the vhd (include the.vhd extension)?"

$a = new-object -comobject
$intAnswer = $a.popup("A BCD entry will be created called $name and pointing to $file. Do you want to continue?", `
0,"Create BCD Entry",4)
If ($intAnswer -eq 6) {

    $f= resolve-path $file
    $vhdvalue = "[$($f.Drive.Name):]$($f.Path.Substring(2))"

So now you can just run this from PowerShell and answer the two questions, what do you want to call the boot entry ( Boot to myVHD) and the VHD you want to boot to complete with the VHD extension. (e.g. c:\VHD\MyVM.VHD).

Now I just need to persuade someone to let my buy an SSD and some more RAM to get my laptop to run like a server and I’m all set.