About Windows Installer, the .NET Framework, and Visual Studio.
Testing software can be fun and rewarding. You get to see new, upcoming features and provide valuable feedback to the developer. But as with most pre-release software, we recommend that you don’t install it on production machines. You could dedicate extra machines for testing, or even test in a virtual machine. Virtual machines are great for testing operating systems and applications, and maximizing system resource usage. You can even take snapshots of the system disk and memory states and roll back to previous states.
Besides requiring additional memory and processor time, another problem with virtual machines is that they run under a standard configuration of a basic display driver and no sound driver in Hyper-V. All your other devices attached to your machine are not always accessible, including your graphics card that provides a nice Aero glass experience in Windows Vista and Windows 7.
But by installing Windows to a virtual hard disk (VHD) – the same format used by virtual machines – and creating a differencing disk on top of that you can test multiple configurations on the same base platform. You can choose with physical or virtual hard disk to boot and also take advantage of all the system devices your machine has to offer.
If you already have installed Windows Vista or Windows 7 and have plenty of free space on your system partition or in another partition – almost twice the amount of the virtual partitions you want to create – you may proceed to step 2. This step is useful if you want to install only to VHD files on your machine.
You’ll need to create a partition to store the boot configuration data (BCD) as well as the virtual hard disk (VHD) files. These can exist in the same partition, but Windows will typically create separate partitions as you see in the screenshot below. This also allow you to encrypt the system partition with BitLocker drive encryption (BDE) while maintaining a boot-readable partition.
You’ll create a base virtual hard disk (VHD) in a partition with enough space available to hold the base installation and the differencing disk. This should be roughly twice the amount of space you pass to the “maximum” argument in the steps below. The number you pass to the “maximum” argument is in MB. A typical Windows 7 (x86) installation with a half-dozen or so driver updates and Microsoft ForeFront took a little over 6GB before being compressed.
You’ll create an expandable VHD as the base since it won’t be modified when booting to a differencing VHD. The installation will take a little longer since the VHD will be expanded as necessary, but this will result in a small base VHD instead of wasting unused space for a fixed VHD.
For the following steps, if you’re already logged into Windows Vista or Windows 7 you’ll need to open an elevated command prompt. If you’ve completed step 1, you continue in the command prompt you already opened.
diskpart create vdisk file=C:\Win7-base.vhd maximum=65536 type=expandable select vdisk file=C:\Win7-base.vhd attach vdisk exit
After the installation has finished and you have logged in, you may want to update or install additional drivers for your hardware. You might also consider installing a minimal amount of software like a virus scanner. This will yield a smaller differencing disk.
For example, with virus software there are program files that need to be installed. Incremental updates may be provided for virus definitions. By installing the virus software first before creating the differencing disk, only definition updates will be contained within the differencing disk.
If you have installed the same Windows version that was already installed on another partition (if any) you may also have duplicate boot entry descriptions. You can rename the VHD boot entry to be unique.
bcdedit /v
bcdedit /set {guid} description “Windows 7 (VHD)”
Finally, you may wish to run Windows Update one last time before attempting to reduce the VHD file size. Be sure to reboot so that any changes made to disk after the reboot are contained within the base VHD.
If you wish to reduce the amount of physical disk space consumed by the base VHD, you can attempt to reduce space within the VHD and then compress it from another Windows installation. It’s interesting to note that if you are viewing the VHD file on a separate partition while booted into the VHD file, the file size will appear to be the maximum size of the VHD. If you created an expandable disk as described in these instructions that is not accurate. You will see the correct file size when booted into a different partition.
You might also wish to relocate the paging file to the physical hard disk to reduce space consumed in the base VHD and reduce changes in the differencing VHD.
If you have formatted the VHD as NTFS (default for Windows Vista and Windows 7) you do not need to run the Virtual Disk Precompactor that ships with Virtual Server and Virtual PC. This may help for FAT-formatted partitions, though.
After you have defragmented, reboot into a different partition. You may boot into Windows and open an elevated command prompt, or start Windows installation and open a command prompt as described in step 1. Type the following commands.
diskpart select vdisk file=C:\Win7-base.vhd compact vdisk
This may take some time to complete, but you should notice a decrease in file size of C:\Win7-base.vhd.
Next you’ll create a differencing VHD that will store all the differences between what you write to the disk and the base VHD. When you install software, it’s all contained within the differencing VHD and the base VHD is not modified. You can even create multiple differencing VHDs and boot to each of them separately, or create a chain of differencing VHDs.
In the following example you’ll create a differencing VHD for installing Visual Studio 2010 Beta 2, but you could use any file name and path or install any software you like instead.
You cannot be booted into the base VHD when creating the differencing VHD. If you have rebooted into another partition with Windows Vista or Windows 7, or into a Windows installation, do so now. Open an elevated command prompt as described in previous steps.
diskpart create vdisk file=C:\Dev10-Beta2.vhd parent=C:\Win7-base.vhd exit
bcdedit /v bcdedit /copy {guid} /d “Dev10”
bcdedit /set {guid} device vhd=[locate]\Dev10-Beta2.vhd bcdedit /set {guid} osdevice vhd=[locate]\Dev10-Beta2.vhd bcdedit /default {guid}
After you have rebooted the machine into the new differencing VHD you can begin installing software. In this example you’ll install Visual Studio 2010. Download and run the web installer or insert your installation media and run setup.exe.
Follow the installation wizard choosing either the default installation or a custom installation. After the install is completed explore the new features of Visual Studio 2010 and enjoy.
Virtual hard disks are an integral part of virtual machines, but if you want to test on real hardware booting to a VHD is a good alternative. Microsoft TechNet has a lot of details about preparing, deploying, and booting to VHDs; and the Microsoft Virtualization team blog has more great information.
Hi,
Thanks a lot !
But I use this system for traineeship and when traineeship is finished I want to delete the data that user have changed on the differencing vdisk how it's possible ?
@Thibault, this solution will work fine for that. Just make sure that before training starts the trainee is working on a diff disk. Was there something specific?
Same question as Thibault...imagine the scenario where you are natively booting Win7 to a differencing disk. You have completed whatever testing and want to clear the contents of the differencing disk to start over. How is this accomplished? Do you need to boot to a different VHD and format it? It isn't clear to people you haven't the time to load it all up and test. Thanks...
@Eric, boot into WinPE again, delete the VHD you created in step 5, then recreate it with the same name and location to start over. No need to reconfigure BCD since you'd simply replace the differencing VHD.
Any way of automating the clearing of the differencing disk when rebooting so the installation reverts to a clean state? Basically same functionality as SteadyState or Deepfreeze do when the system is rebooted - back to the clean locked state.
@Et, nothing built-in that I'm aware of or have read about. Perhaps you could write an app to run on shutdown (handle WM_ENDSESSION - should be fast enough (~5secs)) and create a new dynamic vdisk and add that to BCD (or modify the existing entry), then schedule the path to the old/current vdisk to remove on reboot (using host drive's path; via MoveFileEx, for example). Just an idea.