How To Build An Effective Virtual Machine Template
How To Build An Effective Virtual Machine Template
By Mark Gabryjelski
published: Thursday, March 23 2006





By Mark Gabryjelski of Expert Server Group

Summary
Many people have been asking for some tips on how to build a VMware Workstation Virtual Machine. The following guide has been written with the assumption that this will be the first Virtual Machine you will be configuring, and that you will be creating this as a ‘template’ Virtual Machine.

A ‘template Virtual Machine, will be a Virtual Machine, configured by you, which will be prepared for rapid deployment of additional Virtual Machines. ‘Rapid Deployment’ means being able to deploy a new pre-configured virtual machine in 10 to 15 minutes.

An assumption will be made that you have the current version of VMware Workstation (as of this writing, version 5.5.1 build 19175) installed on your workstation. It will also be assumed that you understand how to install and configure Windows XP Professional, as this will be the operating system configured as the ‘template.’

You will step through the process of:
  • Creating the first Virtual Machine
  • Making changes to the configuration file relating to that Virtual Machine
  • Installation of the operating system
  • Installation of VMware Tools
  • Patching the operating system
  • Cleanup of the Virtual Machine’s hard drive
  • Use of the Microsoft Sysprep Utility
  • Additional cleanup of the Virtual Machine’s configuration
  • Cleanup of the directory where the Virtual Machine’s files exist
  • Creating an archive/zip file of the Virtual Machine
  • Creating a Virtual Machine from the archive

Pardon the length of the document. Screenshots make up the bulk of this document, just so that there are no questions about the steps detailed here.

The tutorial is split into three sections:
Initial Virtual Machine Configuration | Making Changes to the VMX file | Install the Operating System

Initial Virtual Machine Configuration


Start by using the pull down menu, and go to ‘File > New’
Click ‘Next’ to continue.




Select ‘Custom’ as it provides you with more choices for the installation.
Click ‘Next’ to continue.




The first choice, ‘New –Workstation 5’ is a configuration of the most up to date VMware Workstation Virtual Machine.
Click ‘Next’ to continue.




For your first Virtual Machine, you will be creating a Microsoft Windows XP Professional Virtual Machine. Make the appropriate selection.
Click ‘Next’ to continue.




Here, change the default names. The template Virtual Machine will have a generic computer name of ‘winxpprosp2’. Note that you’ll use this name in a few places. Make the change for the ‘Virtual Machine Name’ and the entry in the ‘Location’ (which will actually be a directory holding all files relating to this Virtual Machine.
Click ‘Next’ to continue.




Here you allow the Virtual Machine to use 1 of the physical processors that exists in the physical workstation. Remember, when building a ‘template’, less is more! Choose ‘One’.
Click ‘Next’ to continue.




Here you allocate RAM to the Virtual Machine. Remember, when building a ‘template’, less is more! I use 256 MB but you can allocate more or less depending on your host system.
Click ‘Next’ to continue.




Next, determine the Virtual Machine’s network connectivity. For the ‘template’, let’s keep it simple. Choose ‘Use Bridged Networking’.
Click ‘Next’ to continue.




Here you can choose the type of ‘Virtual SCSI I/O Adapter’ for our Virtual Machine. Windows XP works with the ‘BusLogic’ SCSI adapter.
Click ‘Next’ to continue.




Now you must create a ‘Virtual Hard Disk’ for the Virtual Machine. Choose ‘Create A New Virtual Disk’.
Click ‘Next’ to continue.




Since you are putting effort into your ‘template’, let’s give the Virtual Machine a SCSI drive.
Click ‘Next’ to continue.




How big should you make the drive? Should you allocate all the disk space now? Should you split it into files less that 2-GB in size? All good questions, although there are no correct answers.

NOTE: What works well for me (when building a template for VMware Workstation, NOT VMware ESX Server), is some over-allocation (25-GB), but I do NOT allocate the space right away, nor do I split this into files less than 2-GB in size.
Click ‘Next’ to continue.




Now you must name the file that will be the Virtual Machine’s SCSI hard disk.
Use the SAME name as before:
‘winxpprosp2’.

This is for consistency (good stuff once you have many Virtual Machines going, and need to make sense of your directory structures and files).
Click ‘Finish’ to continue.




You are now provided with a summary of your Virtual Machine.
No…you’re not done. You’ll make some changes to the Virtual Machine’s configuration prior to installing an operating system.
Note the location of the ‘Configuration File’. You’ll be going into that directory and viewing the files contained, and editing the VMX file in the next section.


Next you will need to Boot the Virtual Machine by pressing the “play button”. This will create the initial entries in the VMX file. Ignore SCSI errors and wait for it to display a error message about not being able to find an OS. At this point press the “stop button” to power down the Virtual Machine.

Continue to: Making Changes to the VMX file

Making Changes to the VMX file

While the changes in this section are not required, they will help you identify things to change, and optimize when deploying the ‘template’ afterwards.




Now that you’ve navigated to the configuration file’s directory, delete all the files except for the following two files:
  • VMDK (Virtual Hard Disk)
  • VMX (Configuration File)

The configuration file has a generic name:
‘Windows XP Professional.vmx’




Change the name of the configuration file to:
‘winxpprosp2.vmx’
(notice the consistency thing again, here?)

Let’s open up the file, ‘winxpprosp2.vmx’ with notepad.




NOTE: I rearranged the items here myself prior to the screenshot, so that similar items are next to each other.
I’ve made a few edits, and I’ve made some additions. These work well for me. The only addition here that you may not want is
uuid.action = “keep”
. If you need each VM to have a unique UUID (say for testing R.I.S.), change this to ‘create’ instead of keep.
You do not need to add all these lines manually. You do not need to reorder the lines in the file (I do so for organization). For consistency I have also renamed the nvram line to read:
nvram = “winxpprosp2.nvram”





When you open your Virtual Machine, Click ‘Edit Virtual Machine Settings’ to bring up this window.
NOTE: I’ve made the Virtual Machine’s CD-ROM drive use an ISO image as CD-ROM media (this helps speed up the installation of the operating system.




Next, change the default behavior of USB devices to the Virtual Machine by clearing the checkbox shown to the right.




For Windows XP (you don’t need to do this for Windows NT, 2000, or 2003), add a Floppy Drive to the Virtual Machine.

NOTE: I point to an FLP file (this is the equivalent of and ISO to a CD-ROM). You can download the correct FLP file from VMware’s website
http://www.vmware.com/download/ws/#drivers




You can see some of the options we’ve already tuned in the VMX file here in the GUI interface.




If you look into the example VMX file a couple of pages back, you will see the line:
powerType.powerOff = "soft"

This is the option relative to the screenshot on the right.




Shared folders can be useful, but NOT when you are building a template.




Shapshots are VERY useful, just NOT when building your template.




You can disable these features here to the right, but not when building a template.




More options here. Again, keep it simple when building your template.




Now the Virtual Machine is ready to load an operating system on it that you can use and prepare as a template Virtual Machine.

Continue to: Install the Operating System

Install the Operating System



When the VMware BIOS screen flashes, hit ‘F2’ to enter Setup.




Enter the “Boot” menu page and then use the “+” and “-“ keys to re-order your boot priority to the following:
Hard Drive
CD-ROM Drive
Removable Devices
Network boot from AMD Am79C970A


Press F10 to Save and Exit




When the VMware BIOS screen flashes once again press “ESCAPE” in order to display a Boot Menu.

Choose the ‘CD-ROM Drive’.




When prompted, hit ‘F6’ so that you can add a 3rd Party SCSI Driver.




You will be prompted to hit ‘S’ so that you can add a 3rd Party SCSI Driver.




Remember the FLP floppy image? This is why you went and got it earlier…the VMware SCSI Controller Driver!




That is the only SCSI driver you need.
Clicking ‘Enter’ will prompt you to continue.




Press C to create a NTFS partition using all available space. Follow on-screen instructions to begin installation.




During the installation of Windows, you may or may not see this screen. Remember the VMware SCSI Driver?
That is what it recognizes.
Works fine, so you can say yes.




Here it states that the VMware SCSI Controller is not ‘digitally signed…’
Yes you DO want to use this driver.




One more time with ‘consistency’.
Make the computer name…
‘winxpprosp2’.
Now the hostname, config file, NVRAM file, Virtual Disk File, ALL have the same name. Now if there is a problem with this host, VERY easy to find all the files that relate to this Virtual Machine.


Now finish up the operating system installation. Once logged in, there are a few things left to do to get your template ready.


Install VMware Tools.
On the toolbar, under the VM pull down list is ‘Install VMware Tools’.
Choosing this presents the correct ISO file to the Virtual Machine, and autoplay (if enabled in the Virtual Machine’s operating system) initiates the installation.


Go into the Control Panel.
Under User Accounts, click ‘Change The Way Users Log On Or Off’
Disable ‘Use Fast User Switching’ and ‘Use Welcome Screen’

Go into the Control Panel.
Under ‘Add/Remove Programs’, make any changes you need to remove unnecessary software (less is more when building a template).

Open Windows Explorer
Change the ‘View’ menu to suite your needs
Under Tools, Options, make any changes to the General and View tabs, and then verify that Offline Files are disabled.


Perform any necessary patching/updating to the operating system (Windows Update or Microsoft Update works fine for Windows XP).




Get the Microsoft Sysprep utility from the Microsoft website, or from the Windows XP CD-ROM. I got mine from the XP CD-ROM.

From the Virtual Machine’s point of view, attach the Windows XP CD-ROM, and find the following file,
D:\Support\Tools\Deploy.cab

When you double click this file, it opens up like a folder. Copy all these files, and make the necessary directory, to:
C:\sysprep





Another thing to do is create a file called ‘C:\sysprep\sysprep.inf’
This file will have some things to help you when you deploy your template, as far as making the process easier, and faster.


Replace the ‘xxxxx-xxxxx-xxxxx-xxxx’ with your license key so you don’t have to enter it EVERY time you boot the ‘template’.


Once updating, patching, and other base requirements are completed, let’s clean up the template. (Remember… the less you put into the initial template, the cleaner your base template is. You can always make more ‘templates’ from this later on).


Run ‘Microsoft Disk Cleanup’, and choose every option, EXCEPT for compression of older files. Get rid of all your Internet cookies, cache, and history. You don’t need it.

NOTE: I also put a file on my desktop called ‘My Customization.reg’. This is my registry hack, which I like to put on some of my machines. I did not import the file, just put it on the desktop, so as I deploy Virtual Machines from this template, I have the hacks readily available. You can do the same with any “common” setup file, config file, etc to make your deployment quicker.




Now for some steps specific to VMware.
Open VMware Tools (from either the Control Panel, or double-clicking the icon in your system tray). Go to the ‘Shrink’ tab.

Click ‘Prepare to Shrink’. (This may take up to 5 minutes to complete).




When asked if you want to ‘Shrink your disks now?’, click ‘Yes’.

The ACTUAL shrinking process may take up to 10-20 minutes. This made your VMDK file about 600 MB smaller in size.

This completes the cleanup of the Virtual Machine, and you’re ready to make a template out of this Virtual Machine.




Now for some steps specific to Microsoft.
Run
C:\sysprep\sysprep.exe

This starts the Sysprep process (which remove unique information such as hostname, TCP/IP address, SID, etc).
This means you will run a ‘Mini-Setup’ next time you power on this Virtual Machine, or a copy of it.
Click ‘OK’ to continue




Place a check in ‘Mini-Setup’.
Click ‘Reseal’ to finish creating the template. The Virtual Machine will power down when it completes the operation.




Once the Virtual Machine finishes powering off, you can clean up a couple of things to make life easier when you use the template.
Remove the Virtual Machine’s Floppy Drive (who uses floppies except for SCSI drivers anymore?).
Change the CD-ROM settings. Set it back to the Physical CD-ROM, and make sure the checkbox for ‘Connected At Power On’ is clear (not everyone will have the ISO file we used, and rather than get a warning when you power up the Virtual Machine….)
I added some notes regarding the build of this Virtual machine.
Close VMware Workstation (so that no files are locked for the next steps).




NOTE: Let’s look at the files that are in the directory for our Virtual Machine. Lots of stuff…
You can get rid of (delete) the LOG, NVRAM, and VMSD files (they’ll get recreated next time you power on the Virtual Machine).




Back up the Virtual Machine (I used Winzip, as shown here).
NOTE: I ‘zipped’ the directory, which made up the Virtual Machine. This way, when I extract the files, a directory will be created, and contain the VMX and VMDK files.
I got good compression by changing the default settings in Winzip.

The file ‘winxpprosp2.zip’ is now a backup of the template Virtual Machine.




When you deploy from this zip file, a couple of changes SHOULD be made.
Let’s assume we’ll be building a host named ‘web01’.
Edit the VMX file replacing ‘winxpprosp2’ three times in the VMX file.
IMPORTANT: (Do NOT change the 4th line down,
guestOS = ‘winxppro’
as that would break the Virtual Machine). Close and save the changes to the VMX file.



Change the name of the folder, VMX file, and VMDK file so they are all called ‘web01’.
Again, all the files and directories now are called ‘web01’, and you can easily find and identify the files that make up your Virtual machine.


The only thing left to do to keep the consistency in naming, is when you fire up the Virtual Machine, make sure you make the Computer Name ‘web01’.
Your Virtual Machine should be up and running now in about 5-10 minutes.
That’s worth all the effort we just gave.

###


Mark Gabryjelski is a Senior Engineer at Expert Server Group specializing in virtualization technologies. Mark holds certifications from Microsoft, HP, Novell, Sun and VMware.

Expert Server Group is one of the most experienced providers of enterprise-level virtual server and storage solutions in the Northeast. ESG works with clients of all size, including many Fortune 500 companies, to implement virtual technologies for Server Consolidation, Infrastructure Simplification, and Disaster Recovery and more. ESG is a founding member of VMware's elite VAC partner program and one of the few VMware Premier Enterprise Partners in the world.
www.expertserver.com