Prepping a new hard drive for “Native Boot from VHD”

ws2008 r2 blog logoWhen was the last time you manually partitioned a hard drive? If you are using a modern operating system installation routine the answer is like to be a long time ago.  Nearly all of the setup processing for modern operating systems give you one click convenience. Taking a raw hard drive and partitioning it properly has become easy.  Windows 7 and Windows Server 2008 R2 are no exception and streamline the process quite nicely.

But what happens when you’ve been running a “Native Boot from VHD” environment for a period of time and decide to upgrade the drive?  It’s not like you need to reinstall the OS from scratch. What are the core requirements to run Windows 7 and Windows Server R2?

Disk Partitions and Volumes

If you look at the default installation characteristics for Windows 7, you’ll notice the setup routine creates two partitions or volumes.  One is the system partition and the other is the boot partition.  This isn’t required if you have no plans to use BitLocker.  You can create a single partition that is both the system and boot partition but there’s really no need to and it’s a hassle doing this manually anyway.

image In the screenshot above I assigned the drive letter S: to the system volume.  The drive we are looking at here is a 160GB Intel SSD.  Windows 7 is installed into C:\windows and is not using native boot from VHD.  I can change this pretty easily using the Physical to Virtual capturing utilities.

image 

If we look at the contents of S:, we’ll see the Boot Configuration Database (BCD).  How does that get there and how would we create it from scratch?  It’s really simple. If the BCD doesn’t exist and you use BCDBOOT to create a BCD entry, a template from C:\Windows\System32\config is used as the source.  BCDBOOT will only work if there’s an active system partition.  That’s the key prerequisite. 

Putting It All Together

The first thing you’ll want to do is make a copy of the data and VHD files you are moving to the new drive.  I typically use an external eSATA or USB drive for copies like this.  If you are converting a physical install of Windows into a “native boot from VHD” environment, see my blog post on that subject.  Install the new drive.  Boot from the Windows 7 DVD and run the following commands.  We are creating a 100MB active system partition, and another boot partition sized at the remainder of the drive.  The commands are abbreviated because DISKPART only needs enough characters to resolve ambiguity in it’s command set.

  1. Once the Windows 7 setup environment is running and waiting for you to click the Install Now button, press SHIFT+F10 to start an elevated cmd console.
  2. Enter DISKPART to run this utility.
  3. Enter CRE PART PRI SIZE=100 ID=07
  4. Enter SEL PART 1
  5. Enter ACTIVE
  6. Enter CRE PART PRI
  7. FORMAT QUICK each of the partitions
  8. Select the boot partition and ASSIGN LETTER=C if it hasn’t been done for you already

The partitions are now ready for your data.  We haven’t yet created the BCD store and entry, but we are getting ready to do that now.  If you haven’t already, you’ll need to attach the drive containing the VHD you want to boot.  In my case, I’ll setup two different operating systems.

  1. Create C:\R2
  2. Create C:\WIN7
  3. Copy the Windows Server 2008 R2 VHD to the directory created in step one.
  4. Copy the Windows 7 VHD to the directory created in step two.
  5. Run DISKPART again if you aren’t doing so already.
  6. Enter SELECT VDISK FILE=c:\r2\r2sp1w510.vhd
  7. Enter ATTACH VDISK
  8. exit DISKPART
  9. Enter BCDBOOT e:\windows.  This assumes the drive letter E: was used on the attach in step seven.  This creates the BCD store from the template inside the windows instance, generates a unique GUID, and adds the entry to the BCD.  Since this is the first entry, it’s also the default entry.
  10. Run DISKPART again.
  11. Enter SELECT VDISK FILE=c:\win7\win7sp1w510.vhd
  12. Enter ATTACH VDISK
  13. Exit DISKPART
  14. Enter BCDBOOT e:\windows.  Once again this assumes the attach assigned E:.  This creates a unique GUID and adds a BCD store entry.  In addition, the Windows 7 VHD is now the default and will be loaded automatically after 30 seconds at boot.  I usually knock this timeframe down to 10 seconds.  BCDEDIT can be used to change the display order for the boot prompt, descriptions, timing, and other parameters.

Congratulations.  You have manually partitioned a physical disk, moved the data and native boot from VHD files to the disk partition, added BCD entries, etc.