Creating and Registering Windows 7 Bootable VHDs

Here at InterKnowlogy we have the benefit of working on a lot of cutting edge technologies. A good deal of our first looks at different technologies involve installing alpha/beta bits that may or may not install or uninstall properly and may or may not play nice with existing technologies that we use in other projects. The simple way to keep from destabilizing your system is in creating a Virtual PC and running it with any number of applications (VMware, VirtualBox, Windows Virtual PC, etc…). Doing this keeps your existing system clean and free from any possibilities of errors occurring. However with most Virtual PCs they are utilizing virtual drivers and not running straight off the physical hardware so it doesn’t function as quickly as your main OS, and on top of that you have to share RAM between the two. If you need to switch back and forth continuously between the two then this is just something you have to deal with. However, if you are able to have everything on just the Virtual PC AND are running Windows 7 (for both your actual OS and VPC) then you have another option.

Windows Virtual PC utilizes a file with the extension .vhd for its virtual hard drive. It contains everything for the entire OS and instead of using the VHD through Windows Virtual PC, in Windows 7 you can register that VHD into the boot menu and, on startup, boot straight into it like it is an OS installed on your machine.

Create Bootable VHD

  1. Open Computer Management and switch to Disk Management View
  2. Select Create VHD from the Action menu
  3. Choose location, disk format (can be either Fixed or Dynamic), disk size (30GB Min Recommended), and finish. The creation process might take 5-10 min. There won’t be any extra dialog, just a progress bar at the bottom.
  4. Right-click on the new disk that shows up in Disk Management and initialize it with a MBR partition style.
  5. Right-click on the initialized partition and select New Simple Volume. Go through the wizard. The only thing that you will want to change is the Volume Label on the Format Partition screen. Make a note of the drive letter that is assigned on the 3rd screen in the dialog as you will use this later.

Install Windows 7

  1. Install the Windows Automated Installation Kit for Windows 7 to get access to the ImageX utility which is located at C:\Program Files\Windows AIK\Tools in either the x86 or amd64 folders.
  2. In Disk Management make sure that the VHD that was created and initialized is attached (Action->Attach VHD)
  3. Open a command prompt and change directory to either C:\Program Files\Windows AIK\Tools\x86 (if you are installing Windows 7 32bit) or C:\Program Files\Windows AIK\Tools\amd64 (if you are installing Windows 7 64bit).
  4. Then run the following command:
    imagex /apply d:\sources\install.wim 1 x:\
    
    1. d:\sources\install.wim is the location of the “install.wim” file in the Windows 7 media (mounted ISO file or DVD)
    2. 1 is the image index of the OS. 1 can be assumed, however to check what it is you can run the command: imagex /info d:\sources\install.wim and look at the Image Index
    3. x:\ is the drive letter for the attached VHD that you made note of earlier
  5. Once the ImageX utility has finished, run the following command to add this drive to the boot menu as the default boot OS:
    bcdboot x:\Windows
    
    1. Using this command will make this your default OS to boot into on the boot screen. The easiest way to change this is to get to Advanced system settings (via the computer properties screen), select Settings… in the Startup and Recovery section, and then change the value in the Default operating system dropdown.

Change the OS name in the boot loader

The next time you start up your machine, you’ll notice there is now an additional Windows 7. The big question is which one is your main OS and which is your new bootable VHD. So before you restart or shutdown your machine you’ll want to rename your bootable VHD description.

  1. Open a command prompt and run the following command to see all the boot loader entries:
    bcdedit
    

    Example Windows Boot Loader Entries
    The top Windows Boot Loader section is of a bootable VHD and the bottom one is for the main OS.

  2. Find the Windows Boot Loader entry that has its device value pointing to your vhd file. This will be the actual location (and while in your main OS will start with vhd)  ie. vhd=[C:]\VHDs\Win764bit.vhd
  3. Copy the identifier value (including the curly braces) for that entry ie. {5e6085cb-8f65-11de-8f7c-92487039f837}
  4. Enter the following command to change the description:
    bcdedit /set {5e6085cb-8f65-11de-8f7c-92487039f837} description “New Description”
    
    1. {5e6085cb-8f65-11de-8f7c-92487039f837} is the identifier you copied
    2. “New Description” is the value you want to have show up in the boot menu. Make sure to keep the quotation marks if you use spaces.

Now when the boot loader shows up you’ll be able to tell which OS is which.

Now you can have the “sandboxed” benefit of a Virtual PC with the performance of a non-virtual OS.

Resources

Scott Hanselman’s Computer Zen

Aviraj Ajgekar’s Blog

Virtual Varia

One thought on “Creating and Registering Windows 7 Bootable VHDs

  1. Pingback: Development Environment for Windows 8 | //InterKnowlogy/ Blogs

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>