Creating a Bootable VHD That Can Also Be Run from a Virtual Machine

Background

I was preparing for a convention where Tallan was going to demonstrate two web-based systems in an exhibit hall. To do this, I needed to setup Virtual Hard Disks (VHDs) running Windows Server 2008 R2. I wanted to be able to run the VHDs in a Virtual Machine (VM) so that I could setup the demo operating systems and accompanying software in the background while still doing my “day job” on my primary operating system, Windows 7. I also wanted to be able to natively boot off of the VHD in order to utilize all machine resources and optimize performance when doing the actual demos at the convention.

Being new to the VHD world, I thought that this would be simple and straight-forward. While not a technical feat by any stretch of the imagination, it did take me a few tries to get this right. Below are the steps that I took.

Create Blank VHD

1. Open a Command Prompt, running as Administrator

2. Enter DISKPART

diskpart

DISKPART Screen Capture

3. Create an expandable VHD that can grow to a certain maximum size. The example below will create an expandable VHD that can grow to 100GB (the maximum parameter is measured in MB) in the root directory. NOTE: if you do put the VHD in the root directory, this will force you to run VirtualBox in Administrator mode; if you don’t want to run VirtualBox as Administrator, choose a non-protected directory.

create vdisk file=c:\win2k8r2_VMandNativeBoot.vhd maximum=100000

4. Select the new VHD:

select vdisk file=c:\win2k8r2_VMandNativeBoot.vhd

5. Attach VHD:

attach vdisk

6. Create primary partition:

create partition primary

7. Format partition:

format fs=ntfs quick label=”Win2k8r2_VMandNativeBoot”

8. (Optional step) Review volumes, checking to make sure new VHD is listed (note that only the first 11 characters of the volume label will appear):

list vol

DISKPART Volume List Screen Capture

9. Detach VHD:

detach vdisk

10. Exit DISKPART:

exit

Install Windows Server 2008 R2 on the VHD through VirtualBox

1. Install VirtualBox (VB). Download from:

http://www.virtualbox.org/wiki/Downloads

2. Start VB as Administrator. Note, you only have to do this because we created the VHD in the root directory. If you put it somewhere else, VB can access the VHD without Administrator privileges.

3. Create a new Virtual Machine (VM) by clicking on the New button:

VirtualBox New Virtual Machine Button

4. Name the VM and set the OS Version:

VB Virtual Machine Name and OS Type Screen Capture

5. Feel free to tweak the memory setting or keep the default.

6. Choose the blank VHD that you created:

VB Virtual Machine VHD Selection Screen Capture

7. “Insert” your Windows Server 2008 R2 media into a storage drive by editing the Storage options and either selecting an image file or by attaching your DVD drive; below, I have attached an ISO image file:

VB Storage Settings Button

VirtualBox Storage Settings Screen Capture

8. Click on the VM and hit Start:

VirtualBox VM Start Button

9. The standard Windows Server 2008 R2 install process should start. On the storage selection screen, you should see the blank VHD you created. Perform a normal installation and configure as desired.

Adding VHD to Boot Menu

1. Open a Command Prompt, running as Administrator.

2. Use BCDEDIT command to copy the default boot option:

bcdedit /copy {default} /d “Windows Server 2008 R2 VHD”

3. The results of the previous command will return a GUID. Copy the GUID (including the braces) to the clipboard for the following steps.

BCDEDIT Screen Capture

4. Use BCDEDIT to set the DEVICE and OSDEVICE options for the VHD boot entry. Use the GUID you copied in the previous step for the {YOUR GUID} references below. Also note: the [locate] parameter below will allow the VHD to be loaded from multiple locations (in theory, I haven’t tested this). They should be used as literal text and copied exactly as shown:

bcdedit /set {YOUR GUID} device vhd=[locate]\win2k8r2_VMandNativeBoot.vhd
bcdedit /set
{YOUR GUID} osdevice vhd=[locate]\win2k8r2_VMandNativeBoot.vhd

5. (Optional step) Use BCDEDIT to review your boot options, checking to make sure your new boot entry for the VHD appears.

6. Reboot your machine and choose the Windows Server 2008 R2 VHD boot option. Note: Windows will expand the VHD to its maximum size when it boots. So make sure that your physical hard disk has enough space for this.

You should be all set!

References

This entry was posted in 0-Uncategorized and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Trackback

  1. […] did something similar to this a few years ago, creating a Windows Server 2008 R2 VHD that could run as a VM and could be native booted into. I followed most of the same process here. One other thing to note is that I was able to […]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*