Building Linux Virtual Machine Templates: Tips and Checklist

While preparing for my home lab, I have created several virtual machine templates. Here are a few tips I found useful to smoothen the process and make your virtual machine templates easy to be deployed than otherwise.

Install VMware Tools
As you may have known, VMware Tools brings many features to the table, for example,

Significantly faster graphics performance and Windows Aero on operating systems that support Aero
Copying and pasting text, graphics, and files between the virtual machine and the host or client desktop
Improved mouse performance
Synchronization of the clock in the virtual machine with the clock on the host or client desktop
Scripting that helps automate guest operating system operations

Wait, it does not even mention APIs. For Guest APIs in vSphere 5.0 and later to work, you must have VMware Tools installed in your virtual machines.

With these benefits in mind, it’s highly recommended to install VMware Tools in your virtual machine template so that you don’t need to install one by one with the deployed virtual machines. Depending on the number of virtual machine to deploy, the saving could be huge.

To manually install VMware Tools, just righ click on the virtual machine in vSphere Client and then pick Guest – Install/Upgrade VMware Tools. You would have the VMware Tools CD mounted on your OS. On my CentOS virtual machine, it’s mounted at /media. The following are the commands to install the VMware Tools. Note that, you’d have to, as expected, have root privilege for the installation.

$ cd /media
$ cp VMwareTools-* /tmp
$ cd /tmp
$ tar -xzvf VMwareTools-*
$ cd vmware-tools-distrib
$ su
# ./ -d
# rm /tmp/VMwareTools-*

Fix NIC Renaming Issue
As a known issue, a Linux virtual machine may rename its network cards after being cloned. For example, if you have eth0 and eth1 card in the orginal virtual machine, the new virtual machine may show eth2 and eth3. The cloned virtual machine has new MAC addresses, but the cached file still holds the old NICs with old MAC addresses. When the new virtual machine boots up, it reads in the cache and thinks two slots are still there therefore assign new slots for the two cards with new MAC.

The solution is quite simple – delete the cache file as shown below on CentOS/RHEL before turning it to template.

# rm -f /etc/udev/rules.d/70-persistent-net.rules

More often than not, you need to convert a virtual machine template back to a virtual machine in order to modify it. Once you power it on, the 70-persistent-net.rules file gets created again. Be sure to delete it before it powering it off. Because the attention is on something else, for example, adding new packages, it’s very easily forgotten.

Clean up

After you are done with the virtual template, you want to clean up the templates. That includes deleting files no longer needed later on, for example installer; cleaning up the history of your shell commands, and logs; Removing application specific data, for example, the browsing history of your browser.

$ rm VMwareTools-*
$ rm -r vmware-tools-distrib
$ history -c && history -w
or delete .bash_history file


Here is a quick check list for you to prepare the virtual machine templates. Note that I don’t know what software to install on your template and you have to fill some part of it. Last step is optional but highly recommended. :)

  1. VMware Tools
  2. Applications and Packages
  3. Clean up
  4. Conversion to Template
  5. Read

Should you have any tips and tricks, please feel free to share.

This entry was posted in Cloud Computing, Virtualization and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. Posted November 19, 2013 at 9:02 am | Permalink

    You should also definitely delete the SSH host key from the template prior to the sealing shutdown. Otherwise all you deployed VMs will end up with the same SSH keys.

    I also apply VMX-file parameters from security hardening guide to all my templates.

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


    My consulting helps clients with virtualization and cloud computing, including VMware infrastructure automation and orchestration, vSphere management APIs, and deep product integration with hypervisors. Current training offerings include vSphere APIs training, vCenter Orchestrator training, and etc. Should you, or someone you know, need these consulting services or training, please feel free to contact me: steve __AT__

    Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.