VHD Booting Windows Server 2008 R2 in Windows 7


There is a new article with particulars on my main machine. You can find it here.

I just found another thing to love about Windows 7. With Windows 7, you can boot from a Virtual Disk. I wish I had known this a few months ago when I opted to completely toast my machine to run Windows Server 2008 R2 so I could play with SharePoint and Team System.

Here are the steps outlined (I will likely edit this, as I am going to redo things tonight now that I have learned some things about this scenario). I am going to boot from the downloadable VHD with Visual Studio 2010 and Team Foundation Server installed.

NOTE: Items in italics and underlined that have brackets, {}, around them are placeholders. You will need to fill in your own information. Example {VHD file location} indicates you have to point to your VHD file. I would normally just use the brackets, but one of the command line tools uses brackets for one of the command parameters.

Pre-Requisites

There are many paths you can take, some of which have no requirements other than Windows 7 (or Windows Server 2008 R2, if you wish to use it as your “host” OS).

Creating the VHD

The tools you need really depend on how you are going to accomplish the install. There are three ways to go about setting up your VHD. The first step is creating a VHD:

  1. Create a Virtual Disk using VirtualPC
  2. Create a Virtual Disk using diskpart

Of the two options, diskpart is the quickest. Here are the steps

  1. Open a Command Prompt (Type Windows Key + R then type cmd and press Enter)
  2. At the command prompt type diskpart and then press Enter
  3. Type the following commands to create the disk and attach it
    1. create vdisk file={file location} type=fixed maximum={max size in MB}
    2. select vdisk file={file location}
    3. attach vdisk
    4. exit

I generally end up with a fairly large disk size, as I need Team Foundation Server, et al, added.

Setting up the VHD

The next step is to set up the disk, unless you are downloading a VHD to boot from or already have one created. Once you have the vdisk attached, you can use diskpart to set it up:

select vdisk file={VHD file location}
   select the disk you wish to work on
list disk
   find the VHD disk
sel {disk name}
   Once you find the disk, this selects it
create part primary
  creates the primary partition
sel part 1
   Selects the partition so you can work on it
active
    marks the partition as active
format fs=ntfs quick
    quick formatting as NTFS
assign
    assigns a drive letter

If you follow all of these steps, the partition is active, assigned and formatted.

NOTES:

  • You do not have to use a fixed type drive, but I recommend it for demoing, as it is something you have a bit more control over fragmentation
  • You have to format the disk before installing an image. If you are doing a full install from media, you can format then.

Loading Windows Server 2008 R2

This portion can be done a variety of ways as well.

Download Windows Server 2008

UPDATE: Does not work, as the VHD image is Windows Server 2008 and not Windows Server 2008 R2.

Install from Disk

The easy way to do this seems to be just installing to the disk from a Windows Server 2008 R2 disk, as it adds everything to the boot menu for you. It is also the most time consuming, as you are running a full install. Here are the steps:

  1. Insert install disk
  2. Choose VHD drive

Can’t get much simpler, but you will wait for the entire install to complete. if the VHD is not bootable, you will get a warning that it is not bootable. This does not seem to be a big deal,as the disk appears to be set active and the boot entries are added.

NOTE: If you have not attached the disk, you can install the OS with VirtualPC.

Install from .wim file

To do this quickly, you use ImageX, which is part of the Windows Automated Installation Kit (AIK). You will need the install.wim file from either Windows media or from an installation. If you need to create a custom .wim, you can use the this web page. It is necessary (best?) to have the drive attached and assigned to accomplish this.

In order to do this properly, you need to know the Index for the Image. If you already know this, you can use the number. If not, you can get it by running the following command:

imagex /info {.wim file}

The index is contained in the IMAGE tag (bolded below):

<WIM>
    <TOTALBYTES>{size here}</TOTALBYTES>
    <IMAGE INDEX="{index}">
        …

To install, you use the following:

imagex /apply {.wim file} /check {index} {assigned drive number}

This should take a few minutes. On my machine it is less than 10 minutes, but I would imagine it can take longer on a slower machine.

Adding Entries to Boot to VHD

If you have attached the disk image, you need to unattach it now from a command prompt.

c:>diskpart
DISKPART> sel vdisk {path to VHD}
DISKPART> detach vdisk
DISKPART> exit

If you downloaded an image or created one via another means, you are fine. The next steps work with any VHD with a correct OS on it (ie, Windows 7 or Windows Server 2008 R2 – or greater (future)). If you installed directly to VHD, you don’t have to follow these steps, as your boot is already configured.

Before doing anything, type in bcdedit and hit the enter key. This gives you a look at the boot loader entries. You shoul dhave one for Windows Boot Manager (not important to us in this exercise) and one for Windows Boot Loader.

First, let’s copy the boot load section for the current install of Windows 7. Type in the following:

bcdedit /copy {current} /d "{alias for VHD}"

NOTE: In the above command {current} is part of the command, not a placeholder for your information. The alias is something you have to configure, however.

Now type bcdedit again and you will now have two Windows Boot Loader entries in the file. Find the one with the alias you created in the last step. You will need the GUID (identifier) to do the next steps.

Run the following to set the file to boot from VHD instead of being another normal C drive entry:

bcdedit /set {GUID} device VHD={path to device}
bcdedit /set {GUID} osdevice VHD={path to device}
bcdedit /set {GUID} detecthal on

When you restart your machine, you should see both Windows 7 and your alias as boot choices.

Final Notes

I have used virtual machines for years to beta test. Unfortunately, running in VirtualPC can be very SLOOOWWWW! This option allows you to use a VHD as a bootable disk, which is quite a bit faster than running in VirtualPC. It is still not as fast as running the OS native.

There are a couple of things you should note with these options, as they may affect your demonstrations, if that is your reason for doing this:

  • Hibernate will not work in the VHD boot image. This means you have fewer power options
  • Bit locker does not work on the VHD boot image. This should not be an issue unless you are using this method to set up numerous boots and storing sensitive information. I keep that on my main OS personally. 🙂

I will follow up in this post once I have my image completely set up and running with the VHD for Visual Studio 2010.

Peace and Grace,
Greg

Twitter: @gbworld

Leave a comment