Windows 7 – VHD Boot – Setup Guideline / to be continued

 

A couple of months ago Max Knor created a great guidance with the above title, telling people the way they could go while creating bootable images for Windows 7. Due to the reason windows 7 RTM-ed and is also available right now via msdn subscriptions, perhaps it is worth to clarify some confusion around windows 7 virtual images, bootable vhds and the stuff around it. Furthermore I’m also going to show you how to create differencing vhd files and how to avoid blue screens of death while doing so.

First of all let me clarify: while working with virtual images on windows 7 you have exactly 2 options to go. They are not exchangeable with each other, so it has to be decided at the very beginning, which virtualization practice is best for you. Perhaps both, however in that case you will need at least two separate vhd images:

  1. Virtualization using the classic Windows Virtual PC.
    • At the writing of this article the RC of the Windows Virtual PC is available for download.
    • Yes, it is correct assuming, Windows Virtual PC is not part of the installed OS, therefore it ahs to be deployed additionally.
    • This works similarly to the well known Virtual PC 2007.
    • However unlike to the Virtual PC or Virtual Server 2005, Windows 7 compatible Windows Virtual PC is tightly integrated with Windows Explorer and you will not find any specific or dedicated client application in order to manage your virtual images. Instead windows explorer will provide the menus attached within windows explorer. Launching “Start/All Programs/Windows Virtual PC/Windows Virtual PC”  you will see a similar picture below.
    •  
  2. Booting physically into the virtual image
    • This virtualization option is out-of-the box available within windows 7 (and Windows Server 2008 R2)
    • In order to avoid confusion, virtual images created via Virtual PC (see above) are not appropriate for this reason. They have to be prepared using sysprep or the imagex utilities. You can read details in this regard here at Aviraj Ajgekar’s blog.
    • If despite the warning you would anyway try using unprepared virtual PC (or Hyper-V) images to boot-in physically, blue screen of death is unavoidable.
    • The rest of this article will focus on developers rather unfamiliar with the mentioned above system-utilities and hence showing an alternative way to create bootable vhd images from the scratch.

Here the scenario which is perhaps typical. You have a laptop/desktop computer and a large enough physical disk which could be partitioned as follows:

  1. Volume C: for the real Windows 7 OS (perhaps x64)
  2. Volume V: for all Virtual Images (see picture)
  3. IMPORTANT! if you do have already BitLocker activated, please suspend it, as we are going to change the system’s boot-entries which is guarded by BitLocker. This could lead to the unfortunate case, where you will have to provide the 48 digit recovery key manually. 

On volume V: we would like to create a read-only physically bootable Windows 7 parent virtual image, and one ore more differencing images based on that parent-image. The benefit of such scenario is obvious; we create the parent image including all commonly used stabilized components and using differencing images e.g. for beta products.

To be more precise there is some kind of risk installing Visual Studio 2010 Beta 1 on a regular OS (on C:) as we learned in the past, that betas could later negatively impact RTM products. So the more appropriate way in order to experiment with .NET 4.0 Beta 1 is to install in a virtual image. However let me remind you, that physically booted virtual vhd OS has to be activated as well and we would like to minimize or completely avoid later troubles. So the perfect scenario is rather to create a differencing vhd image and installing Beta bits on that differencing vhd. The parent vhd image is set to read-only and is not impacted by betas at all. Later-on as the RC (RTM) products arrive, you can simply delete the differencing image (with installed beta) and create a new differencing image based on the still intact parent image. Let’s follow exactly this pattern.

Assume hence our virtual images should be placed on V: (see picture above)

  1. Boot your system with a setup DVD or USB stick and follow the steps like Max Knor describes. Arriving to Max’s step 4. you will experience your first confusion, therefore let me just repeat briefly all the steps and stop at 4. discussing it.
  2. At the setup screen don’t choose “install Now” but rather press “Shift+F10” which will create and display a command-line prompt
  3. Enter diskpart to start the partitioning utility
  4. Max suggests create new vhd file by entering (which is absolutely correct)
    • create vdisk file=”D:\pathToVhd.vhd” type=expandable maximum=maxsizeInMegabyte
    • And yes here the troubles start, due to the reason we do not have a strong imagination about whether in our particular scenario the D: drive is appropriate or rather wrong? And what about the maxsizeInMegabyte?
    • So while booting the system with a setup DVD (or USB) the temporary system will enumerate all system volumes alphabetically. A: and B: are forever reserved for floppies, and hence the C: is the first  100MB volume from the left hand side (see drives’ picture above). This volume is automatically created while setting up Windows 7. The large (181.78 GB) C: drive (see picture) actually at this stage will become the D: drive. So knowing this, the diskpart command above addresses the system drive and pathToVhd.vhd would be created in the root of C:. However in our scenario we just want to place the vhd file on the V: volume (se volumes’ picture). In order to do that, at this stage this volume is identified as E: which is alphabetically the next letter after D. The altered diskpart command looks like follows:
    • create vdisk file=”E:\BaseW7.vhd” type=expandable maximum=80000
    • This command above will create BaseW7.vhd file with a maximum size of 80GB on the V: drive (confused? – I hope not).
    • Please note another important rule regarding the maximum parameter. Booting physically a vhd image, the system will try to expand the image to that declared “maximum” size using the available free space on that volume. So, this rule states, that having 80GB maximum vhd, the V: drive must have 80GB free disk space, otherwise you could experience a blue screen of death. My 116.21GB V: volume and 80GB vhd maximum seems to be well fit into this limitation.
    • Please note every vhd file does have this limit set. Open-up e.g. the Windows Virtual PC like stated at the very beginning of this article, which will show you your .vmcx files (if any already created). Right mouse button and selecting “settings” will open this dialog box below. Note the Total disk size parameter corresponding to diskpart’s “maximum” parameter. You could also conclude, that this particular vhd image would be completely inappropriate to run on my  smaller sized volume V: volume.
  5. Proceeding according to Max Knor’s steps type
    • select vdisk file=”E:\BaseW7.vhd”
    • attach vdisk
  6. Start the setup and make sure Windows 7 is installed on the just created and attached vhd volume/file
  7. Completing the installation your computer will provide two boot-entries (Windows Boor Loader entries) both named “Win 7”. According to my experience the first in the list points to the lately installed virtual image. Boot into that new image and complete the setup/deployment including all drivers, updates, settings and software you think is appropriate as common base for the upcoming differencing images. Do not forget to activate this base image as well – all differencing images will be genuine as well. 

So at this stage I assume the volume V: contains at least one vhd base image prepared to serve as read-only parent for all differencing images. Next we have to create our first working differencing virtual volume (vhd). For this reason just boot into the physical Win 7 OS (which at this time is the second “Win 7” entry in the list of existing boot-entries). Follow these steps:

  1. Open-up an administrative command-line prompt, and type-in diskpart in order to start the partitioning utility
  2. We are going to create a differencing vhd file typing:
    • create vdisk file=”V:\DifferencingW7.vhd” parent=”V:\BaseW7.vhd”
    • Please note the “parent” parameter pointing to the base image!
    • Please also note this time we are addressing the V: volume directly as booted into the physical OS!
    • Make sure the new DifferencingW7.vhd file was created and appears next to the parent BaseW7.vhd file
  3. Just to test this virtual volume, type-in and execute these diskpart commands (optionally)
    • select vdisk file=”V:\DifferencingW7.vhd”
    • attach vdisk
    • The last command will provide a new attached volume and windows explorer will pop-up displaying that volume using the next available drive letter.
    • detach vdisk
    • exit
  4. Next we have to create a boot-entry (the third one) for the current system. This will be done using the bcdedit utility (well known starting Windows Vista)
    • Type in an administrative command-line: bcdedit – this simply will list all your boot-entries in the command-line windows. At this stage of work the list will contain first the Windows Boot Manager entry having two references to the particular Windows Boot Loaders identified each via it’s own unique GUID.
    • The list therefore will also contain at least two Windows Boot Loader entries, one pointing to the physical Windows 7 OS, and the second pointing to the virtual vhd based Windows 7 installation.
  5. In order to create a new Windows Boot Loader entry (remember this is needed for the new differencing vhd), we have to ask bcdedit for a new GUID and let him know the name of that new Windows Boot Loader entry. So you could type this:
    • bcdedit /copy {current} /d W7_Differencing
    • The {current} above means we are asking to create a new current GUID, and W7_Differencing is the name of the entry we will see while reading the available Boot Loader entries
    • As response bcdedit will show you in the command line the newly identified/current GUID. In all subsequent operations you have to use exactly that GUID
  6. Let say the current GUID is {88468bd4-7c77-11de-8059-d17e50a7e7e7}, so follow the steps below:
    • bcdedit /set {88468bd4-7c77-11de-8059-d17e50a7e7e7} device vhd=[V:]\DifferencingW7f.vhd
    • bcdedit /set {88468bd4-7c77-11de-8059-d17e50a7e7e7} osdevice vhd=[V:]\DifferencingW7.vhd
    • bcdedit /set {88468bd4-7c77-11de-8059-d17e50a7e7e7} detecthal on
    • Please note the V: drive is in square brackets, which at this point we know is due to the reason, that at boot-time this V: drive will become the E: drive (see above), and so [V:] indicates the appropriate volume meaning “OK, this time it is V: but you know what I mean”.
  7. Right know we are nearly complete. Type-in again bcdedit, and you will note the response containing on Windows Boot manager entry referencing three Windows Boor Loader entries. As the base vhd image has to be read-only, we should prevent manipulation. Therefore we have to delete that Windows Boot Loader entry referencing the base vhd image. Type in:
    • bcdedit /delete {88468bce-7c77-11de-8059-d17e50a7e7e7} /cleanup
    • Please note, the GUID above is a different one, and references to the Windows Boot Loader entry which points to the base vhd image
    • Type again bcdedit and scrutinize the output. This we should have only two Windows Boot Loader entries.
  8. Complete! Boot into your differencing image and install VS 2010 Beta 1. Have fun!
  9. Some links for more detail:
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

4 Responses to Windows 7 – VHD Boot – Setup Guideline / to be continued

  1. Amira Areizaga says:

    If you are required reinstalling the Windows 7 edition of Microsoft but unable to trace windows key then you can easily trace it on the backside of your PC or underside, in the case of laptop. Windows 7 key is generally sited on a yellow decal. Sometimes, the decal will be sited within the CD coat of the software product, or you can also trace it in the manual of particular software. If you find yourself unable to trace the product key, it means you have lost the license of the valuable Windows 7 software. One may also mislay a great contract of time annoying to track the product key down, or probing various PC mediums for a way out.`

    Freshest short article on our personal homepage
    <'http://www.caramoantourpackage.com

  2. Michael says:

    Hello. What about the following scenario:
    – there is a read-only master vhd and 10 incremental
    – Microsoft releases a lot of critical windows updates

    Can I apply all updates to a master vhd, instead of applying them 10 times?

  3. There is another way. install win 7 to blank HD (diskpart clean) create partition primary (if no size is specified, full capacity is consumed by single partition), make active. exit diskpart.

    congrats! you have a partition. Now md a VHD folder. then diskpart: create vdisk file=c:\vhd\vhdname.vhd. type=expandable. select and attach, exit diskpart and cmd prompt, proceed to windows install INSIDE attached virtual volume (disk, VHD!)

    NWO: how to copy this vhd?! i’ve robocopied it, but the partitions are screw (ie, unallocated space). Will a copy in binary mode fix?

    Thanks detectives, viva native virtualisation.
    THERE IS A WILL

  4. OK, re the above, here’s the thing: If you copy a VHD, the volume is cloned!!
    When trying to attach the (VHD) copy, whilst running the native VM, the ID conflict will result in the attached copy showing as unallocated space… you can initialise it… This made me think the copy was broken.

    By doing ANOTHER clean install (to a newly created and attached VHD), and booting into this, I found that –

    the copied VHD could be mounted, and the partition is good, full of data, a backup!!

    if you mount the original, whilst the copy is mounted, you’ll get the ‘unallocated space’ status on the original

    Is there a way of changing this HardWare ID?

    Now I’m editing a bcd /copy, to boot to the copied VHD… then maybe I can resize it!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s