This blog entry describes how we create the VHDs and configure them in Virtual PC.
Layer Overview
Our VHD tree is built based on a set of defined layers. Layer 1 is comprised of single root VHD for each version of Windows, such as WinXP SP3. Layer 2 is built from differencing VHDs that use the root VHD as the parent. This means that the root VHD needs to be configured as far as possible, without requiring lower layer VHDs have to "undo" any configuration. Here is the VHD structure we use:1. Root VHD - Contains base Windows install and common configurations
2. Configuration specific VHD - Includes apps, service packs, etc. that are different from the root. This is where configuration-dependent changes are done.
3. Working VHD - Includes temporary changes that are used over the course of several tests.
4. Undo file.
Layers are defined by how often they are changed, because when a layer changes, everything underneath it is invalidated. Layer 1 changes every six to eighteen months, usually when the number of security updates becomes overwhelming. Layer 2 changes every few months. Layer 3 is only used when a customized configuration needs to be tested for several days (or when you hit the wrong button and say "commit change.) Layer 4 changes on a minute to minute basis. It is discarded whenever a user selects "Discard changes" when a VPC is closed.
Roadblocks
Creating the VHD hierarchy is tricky. There are several problems we've seen that must be solved by making the changes in the correct order in the correct order. Some of these problems include:- Duplicate Ethernet MAC addresses.
- Duplicate computer names.
- Domain disconnects.
- Accidental overwriting of a parent vhd file.
- Windows Update automatically overwriting desired configurations.
Many people are also concerned about "SID duplication" and want to use something like NewSID or SysPrep. Recent reports indicate that this is no longer a concern. Please see NewSID Retirement and the Machine SID Duplication Myth.
Create the Layer 1 Root VPC
The first task in creating the hierarchy is to create the Layer 1 VHD, which contains the OS install and will be common to all dependent virtual machines.- Create the .vhd file using the Disk Wizard. Set to dynamic size, 20 to 32GB is usually a good size.
- Create the Virtual PC .vmc using the New Virtual Machine Wizard under the File menu. Make sure you give it enough RAM, the defaults are almost always too small.
- Install Windows. Install a version of Windows that includes the desired service pack. Set the system name to be something like RootWinXp so you know when you've forgotten to change it. Do not join a domain during installation.
- Log in as an Administrator and activate Windows, if necessary. Don't do this in a child virtual machine or you'll need an additional activation key for every child.
- Shut down Windows and make a backup of the VHD. Name it "Level 1 - Clean" This is a "clean machine" that's been activated. Use this VHD to create completely new configuration hierarchies.
Configure the Layer 1 Root VPC
- Boot the virtual machine.
- Install the Virtual PC Additions.
- Set the vpc to be part of workgroup, if it's not already. Do NOT join the root vhd to a domain! That must be done in a lower layer.
- Install desired Windows service pack, if any.
- For Windows XP, go to Windows Update in Internet Explorer and enable Microsoft Update.
- Install latest security updates through Windows Update. Pay attention to the following:
- For Windows XP, go to Windows Update in Internet Explorer and check High Priority and Optional updates. The task bar "Update" icon does not show these updates.
- Under Optional, I recommend you install Update for Root Certificates.
- Also under Optional, install Microsoft .NET Framework, if needed.
- Windows Update may automatically upgrade Internet Explorer if you don't do a "Custom" update and uncheck Internet Explorer. OTOH, IE8 for Windows XP is under Optional.
- After each reboot, go back to Windows Update and check again. You'll probably need to run through Windows Update several times to get all updates.
- In Control Panel, set Automatic Updates to "Notify me", not to automatically download or to automatically install. Otherwise you end up fighting Windows Update every time you boot a configuration.
- Disable the requirement for Ctrl-Alt-Del. This can save a lot of mousing around when running the virtual PC in a window. For Windows XP, this can be found under Control Panel / User Accounts / Advanced (or use Group Policy.)
- Create any desired local users (as opposed to domain users.) Make sure you set them as Admin or Limited, appropriately. At a minimum, I recommend creating a "Limited" user for testing.
- Disable the Internet Connection Wizard if you have Windows XP virtual machines. In Group Policy, it's under User Configuration\Administrative Templates\Windows Components\Internet Explorer\Internet Settings\Advanced Settings\Internet Connection Wizard\
- Set firewall exceptions in Control Panel | Windows Firewall | Exceptions:
- File and Printer Sharing must be enabled to allow access the system by name on the network.
- Remote Desktop must be enabled to access the system remotely.
- If desired, enable Remote Desktop under My Computer | Properties | Remote. Note that Remote Desktop is not supported in any of the "Home" versions of Windows. Local Administrators will automatically have rights to access the system via Remote Desktop.
- If you use Remote Debugging in Visual Studio, start up MSVCMON.EXE and tell it unblock the firewall for your subnet. You will discover that this adds numerous exceptions to the firewall. MSVCMON.EXE can be found in:
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Remote Debugger\x86\msvsmon.exe
- Modify options in My Computer | Tools | Folder Options | View, such as "Display the contents of system folders", "Show hidden files and folders", "Hide extensions", and Hide protected operating system files". This can also be done in the domain logon script with:
reg add hkcu\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v Hidden /t REG_DWORD /d 1 /f
reg add hkcu\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v HideFileExt /t REG_DWORD /d 0 /f
reg add hkcu\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v WebViewBarricade /t REG_DWORD /d 1 /f - Share any desired folders.
- Shut down the root vpc using the "Shutdown" from the Start menu.
- Commit all changes if you are using Undo disks.
- Set the VHD to be read-only.
- Create a backup of the file. Name it "Level 1 - Common".
- Optionally, go to the Virtual PC Console and remove this virtual machine so you don't accidently try to use it. If you don't delete it, make sure you enable Undo disks so you don't accidentally change it (Virtual PC will helpfully remove the read-only attribute.)
Create a Layer 2 VPC
- Use disk wizard to create a differencing hard disk to the root.
- Make a backup of this vhd file. Name it "Level 2 - Empty".
- Create the Virtual PC .vmc using the menus. Again, make sure you give it enough RAM. Turn off Undo for now.
- Boot the new virtual PC.
- Log in as an adminstrator.
- Change the system name.
- Join a domain, if desired. This can be done from the command line with the NetDom command, which is available in the Windows XP Support Tools. (This should all be on one line.)
netdom join myvpc /domain:test.com
/userd:Administrator
/passwordd:<domain admin password> - Give any desired domain users or groups permission to login via Remote Desktop.
- Log in as any domain users you plan to use frequently. This does the one-time configuration of the VPC for that user. Change Folder Options again for these users.
- Install any configuration-dependent software.
- Install updates and service packs for the software you just installed.
- Map network shares with a domain logon script. If a computer on a domain must map a drive on a non-domain computer, make sure the non-domain computer has an account with the same name and password as the domain computer. Alternatively, you use this command to save the username/password on the domain computer, then say "net use x: \\acme\share" in the domain logon script.
net use x: \\acme\share
/savecred /persistent:yes - Check Windows Update one more time. On Vista and Windows 7, make sure you explicitly tell it to check again.
- Once everything is configured to your satisfaction, shut down Windows from the Start menu so it shuts down cleanly.
- Set the VHD to be read-only.
- Create a backup of the file. Name it "Level 2 - Configured".
Create a Layer 3 VPC
- Create a third vhd, differencing, whose parent is the vhd you just set to be read-only. I normally name it the same as the parent with the word "Child" appended. This is what I called the "Working VHD" earlier in this document. You will use this when you need to reuse a configuration a few times, then discard the configuration. Normally this vhd is empty.
- Change the settings in Virtual PC for your virtual machine to point to this working file.
- Enable Undo for this vhd.
- Backup this third VHD. Label it "Level 3 - Empty". You'll need the backup whenever you discard your current working configuration.
- Level 1 - Clean root VHD, with a clean Windows install.
- Level 1 - Configured root VHD, with a mostly configured Windows install.
- Level 2 - Empty configuration VHD, which is an empty differencing disk whose parent is the Level 1 vhd.
- Level 2 - Configured VHD, which is your fully configured test environment.
- Level 3 - Empty VHD.
Create Remaining Configurations
- Copy your Level 2 - Empty vhd to a new file that will be the new configuration. Under Windows 7, you can create all of them at once using the DISKPART utility. For example: (DiskPart requires elevated privileges and so must be run from a command prompt started with Run As Administrator.)
DISKPART < Parts.txt
And Parts.txt is one or more lines similar to this:
create vdisk file="c:\vpc\ParentDisks\WinXP Office 2007.vhd" parent="c:\vpc\ParentDisks\WinXP SP3 Root.vhd"
- Go to Step 3 under Configure a Layer 2 VPC and continue through Configure a Layer 3 VPCs.