Creating a bootable VHD the easy way…continued

You might have read and tried the scripts from my first blog about creating a bootable vhd here, and in this blog post I’ll continue where I left with some information about my usage of difference discs and bootable vhd’s.

First of all I started by creating a bootable vhd with my script with the following options:

Name Type Size
Base2k8r2.vhd Expandable 80 000 Mb (Remember that you need this much free space on your disc even if the vhd doesn’t have the size from start)

This left me with a vhd-file that took about 7Gb on my internal disc. I restarted my machine to make sure that my bootable vhd was working correctly.

After the health-check and some customizations like folder options in explorer I opened up a command prompt and entered shutdown /r /f, this way I don’t have to enter a reason to restart my Windows Server 2008 R2 OS Blinkar

Back in Windows 7 I took these steps to create a difference disc to keep my base disc clean:

  1. Start a command prompt as Administrator
  2. Write BCDEDIT /v and hit enter
  3. You will see the boot entries and their GUIDs
  4. Write BCDEDIT /delete {guid to the entry with a the path to your bootable vhd}
    WARNING this will delete a boot entry, make sure you enter the GUID to the entry where the device/osdevice points the path of your bootable vhd. Entering the wrong guid could make your computer UNBOOTABLE.
  5. Write DiskPart and hit enter
  6. Enter CREATE VDISK FILE="<Path to difference vhd>" PARENT="<Path to parent vhd>"
    You must specify a valid folder name or you’ll get an error.
  7. Write SELECT VDISK FILE=”<Path to difference vhd>” and hit enter
  8. Write ATTACH VDISK and hit enter
  9. Write Exit and hit enter
  10. Write BCDBOOT <your assigned drive letter>:\Windows and hit enter
  11. If you write BCDEDIT /v and hit enter you should see a new boot entry that points to your new difference disc.
  12. Restart your machine and make sure that your bootable difference disc starts correctly.

When I get some time I’ll try to automate these steps into a handy batch-file or application. I hope you found this post interesting.

Cheers!

Hugo

Creating a bootable VHD the easy way

2010-11-15 Script file updated

This blog post has been updated after feedback from my colleagues Markus Ahlstrand and Johan Leino, thanks you guys! The original blog post contained 1 error and needed 2 clarifications and 1 refinement, all updated content is highlighted below.
I’ve worked a lot with SharePoint development during the last 3 years and before SharePoint 2010 you could use Virtual PC to create your development environment. But as you might know a SharePoint 2010 development environment has to be on an x64-bit environment as described in this article “Setting up the Development Environment for SharePoint 2010…

So this left me with some alternatives:

  • Install the bits on your own x64-machine.
  • Use another virtualization platform such as Hyper-V, VMWare or VirtualBox that have support for x64 on my own x64-machine.
  • Create a bootable VHD from Windows 7.

I chose the bootable VHD option because I love the feel of Windows 7 and the rich features that Windows 7 gives the end user. On the other side I need the flexibility to start my SharePoint 2010 box when I need that with (almost) no performance loss.

There’s a lot of blogs out there that describe how to create a bootable VHD and so I will not list them here but I will give you a nice automated head start (without MB’s of download).

In the linked CreateBootableVHD_v2.zip you will find two files:

 

Requirements:

  • A machine running Windows 7 or Windows Server 2008 R2.
  • Windows 7 or Windows Server 2008 R2 installation media or a Windows 7 or Windows Server 2008 R2 .wim image captured from a reference machine.

The following steps are provided with a “works on my box” guarantee.

  • Download the linked zip-package.
  • Select Properties on the zip-package and click on the Unblock button.
  • Extract the zip-package to a folder of your choice.
  • For each extracted file select Properties and click on the Unblock button.
  • Mount your installation media from an iso file or DVD.
  • Look for the file “install.wim” on your installation media (see number 3 above) and remember the path, in my case F:\sources\install.wim.
  • Open a PowerShell command prompt with the run as Administrator option. You need to run the attached bat-file from a PowerShell console as an Administrator and not from the usual command prompt. (thanks Johan for pointing out this clarification!)
  • Change directory to the directory where you extracted the zip-package.
  • Before I show you how to use the CreateBootableVHD.bat file there is 2 important concepts that you need to know:
    • The third parameter in CreateBootableVHD.bat expects you to enter the type of VHD that you want to create. If you choose DYNAMIC EXPANDABLE (thanks Markus for pointing out this error!) you will need to make sure that you have the specified amount of GB left for the VHD even though the VHD will be small at first.
    • CreateBootableVHD.bat will assign your bootable VHD a drive letter, it’s very important to use a FREE drive letter.
    • When you enter a drive letter make sure you don’t enter a colon after the letter i.e. X and never X:. (thanks Markus for pointing out this clarification!)
  • Now you’re ready to use the CreateBootableVHD.bat-file like this:
    CreateBootableVHD_v2.bat <path where you like to store the VHD, doesn’t work on external drives> <size in MB> <type FIXED|DYNAMICEXPANDABLE> <drive letter assigned to the VHD> <path to the wim-file, see number 4 above>.

Ex: .\CreateBootableVHD_v2.bat C:\VHD\W2k8.vhd 40000 FIXED X F:\sources\install.wim

To show an actual example here is a snapshot from my latest run:

image

After 30-60 minutes depending on the size of the VHD and your hardware you’ll have a new boot option.

Hope you enjoy the script.

Hugo