In two previous articles on Windows Networking, we looked at how to use Microsoft Virtual PC as a testing and learning platform and how to get the best performance when using Virtual PC. This article discusses how you can use Sysprep to build up a library of virtual machine (VM) images that can make testing/learning even easier.
Sysprep (System Preparation tool) is a Microsoft Windows tool used for preparing reference systems for image-based deployment to target systems. Sysprep is found in the Deploy.cab file in the \Support\Tools folder on your Windows product CD, and the latest version of Sysprep for each Windows platform can also be obtained from the Microsoft Download Center by searching for “deployment tools”.
While the primary use for Sysprep is preparing systems for deployment using disk imaging (you also need a third-party disk imaging tool like Ghost to do this however), another use for Sysprep is simplifying the creation of new VMs for testing and learning purposes using Virtual PC. To see how this works, let’s walk through the process of “sysprepping” a VM running Windows XP and then using it to create additional XP VMs with minimal extra work.
Step 1: Install and Configure your Base System
We’ll begin by installing Windows XP Professional with Service Pack 2 on a new VM. After it’s installed, we’ll configure XP the way we like it and then this VM will serve as our base (or reference) VM from which other cloned VMs will be created. Start Virtual PC and click to begin the New Virtual Machine (Figure 1):
Figure 1: The New Virtual Machine Wizard
Click Next and choose the option to create a new virtual machine (Figure 2):
Figure 2: Create a new VM
Click Next and type a descriptive name for your new VM (Figure 3). This will create a new .vmc (virtual machine configuration) file in My Documents\My Virtual Machines\subfolder where subfolder has the descriptive name of your new VM.
Figure 3: Give your base VM a descriptive name
The next few screens in the wizard let you specify the operating system you are going to install (select Windows XP) and the amount of RAM you want the VM to use (you can leave at the default 128 MB unless you are installing additional applications like Microsoft Office on your base VM). Then comes a screen that lets you create your new VM using either an existing virtual hard disk (.vhd) file or a new one—choose the new disk option as shown in Figure 4:
Figure 4: Your base VM needs a new .vhd
Clicking Next prompts you to specify where the new .vhd should be created. By default this will be the same folder as where your .vmc file resides, but on my test system I store all .vhd files on a separate SATA RAID 0 array for best performance (see my previous article on Virtual PC performance for discussion of this setup) so I’ll save the .vhd in a folder named XP on drive D: (see Figure 5):
Figure 5: Creating a .vhd file for my base XP image
Finishing the wizard creates my new VM but there’s no operating system installed on it. So I pop my Windows XP Service Pack 2 CD from my MSDN Universal subscription (something absolutely essential and well worth the money for any company that needs to frequently test Microsoft platforms and products) into my test machine and then click Start in the Virtual PC console to start my newly created VM. Note that when you start your VM you may need to select Use Physical Drive from the CD menu option to have your VM recognize the Windows product CD in your CD-ROM drive. Windows Setup will then proceed to run in the usual way, starting with the text-mode blue screen until you’ve completed installing Windows XP onto your new VM. One important thing when running Setup however—leave your Administrator password blank. You’ll need that so Sysprep will work properly afterwards. Also, I typically let Setup automatically generate a name for my base VM and use Typical networking settings (DHCP or APIPA) as well.
Once Setup is finished and you’ve logged on for the first time, configure your desktop, install applications, and do whatever you need to do to configure your base system. Remember, your cloned VMs will be duplicates of your base VM, so doing as much configuring as you can ahead of time will save you work later on. And go ahead and activate your XP VM as well. Finally, don’t forget to install Virtual Machine Additions on your VM also.
Setup 2: Sysprepping your Base VM
Sysprepping your base VM is a straightforward procedure. Start Virtual PC and then start your XP VM and log on as local Administrator (remember you’ve left the password blank for this account). Create a folder such as C:\Deploy and extract the contents of the Deploy.cab file in \Support\Tools on your XP product CD to this new folder). Then click Start, Run, type C:\Deploy\Setupmgr.exe and click OK to start Setup Manager, a tool that you will now use to create an answer file to automate the installation of your cloned VMs later on. I described in detail how to use Setup Manager in a previous article on WindowsNetworking, so I’ll be really brief here. Just remember that everything is happening within the base VM you created, not your physical (host) machine.
Once Setup Manager is running, start walking through the wizard making the following selections:
- Create a new answer file for Sysprep setup (see Figure 6).
- Fully automate the installation.
- Automatically generate a computer name.
- Specify an administrator password as desired.
- Use Typical network settings.
- Everything else can be left at the defaults or configured as desired.
Figure 6: Create a new answer file for Sysprep setup
When the wizard finishes, save the new answer file (sysprep.inf) in a subfolder of the C:\Deploy folder and not the Deploy folder itself. For example, create a subfolder named C:\Deploy\Sysprep and save sysprep.inf in the Sysprep folder (Figure 7):
Figure 7: Saving a copy of your sysprep.inf file
In addition to saving your answer file sysprep.inf in C:\Deploy\Sysprep, the wizard also creates a C:\Sysprep folder and saves a copy of your sysprep.inf file in there also. Copy the files Sysprep.exe and Setupcl.exe from your C:\Deploy folder to C:\Sysprep so that your C:\Sysprep folder looks like Figure 8:
Figure 8: What your C:\Sysprep folder should contain
Now you’re reading to sysprep your base VM. Close any running applications or windows in the VM and click Start, Run, type C:\Sysprep\sysprep.exe and click OK to begin sysprepping. Click OK to accept the dialog box that appears (Figure 9):
Figure 9: Click OK to start sysprepping your base VM
When the Sysprep properties screen appears, make sure your selections are exactly like those shown in Figure 10 below:
Figure 10: Use these settings for Sysprep
Now click the Reseal button, click OK when asked whether you want to regenerate SIDs, and your VM will be sysprepped and will automatically be shut down. Since our base VM will now no longer itself be used as a VM within Virtual PC, you need to disassociate the .vhd file for this VM from its .vmc file. To do this, select your base VM in the Virtual PC console and click the Remove button (Figure 11):
Figure 11: Select your base VM and click Remove
When you click Remove a dialog box will appear (Figure 12):
Figure 12: Click Yes when this dialog appears
After clicking Yes, open Windows Explorer on your host computer and browse to find the .vhd file for your base VM. Use CTRL+C and CTRL+V to make as many copies of this .vhd as you need (i.e. as many new XP VMs you want to create for using with Virtual PC) and rename these copied .vhds as desired. I’ve created two new .vhds this way as shown in Figure 13:
Figure 13: Base VM and two copies of its sysprepped .vhd file
Once you’ve made your copies, set the Read Only attribute on the properties of the Base VM’s .vhd file so it can’t be accidentally deleted or used by Virtual PC.
Step 3: Create Cloned VMs.
Now you’re ready to create your new, cloned Windows XP virtual machines in Virtual PC. Return to the Virtual PC console and click the New button to create a new VM as in Step 1 previously, but this time choose the option to use an existing virtual hard disk instead of creating a new one (Figure 14):
Figure 14: Create a new VM using an existing .vhd file
Attach one of the cloned (copied) VMs you created at the end of Step 2 above to your new VM, and select the Undo Disk option if you plan on using undo disks (they’re great if you’ll be constantly reconfiguring your Virtual PC networks) as in Figure 15:
Figure 15: Attaching an existing .vhd file to a new VM named XP Box 1
Once you finish the wizard, you’ll see your new VM in the Virtual PC console (Figure 16):
Figure 16: Cloned copy of XP in a new VM
Click Start to boot your cloned copy of XP in the new VM, and the Sysprep process will generate new SIDs for your new XP machine. Once XP starts up you’ll be presented with a few quick prompts for information specific to your new computer, and then the Welcome screen will appear followed by your desktop. Repeat this procedure with each new XP VM you want to create (and repeat everything above with Windows Server 2003) and then use your new VMs in your Virtual PC environment. Pretty soon you’ll have a whole library of saved base VM images for different operating systems, server roles, client roles, and so on. A library of sysprepped images like this makes Virtual PC a terrific tool for testing and learning purposes.