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,
Lost VMs or Containers? Too Many Consoles? Too Slow GUI? Time to learn how to "Google" and manage your VMware and clouds in a fast and secure HTML5 App.
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 # ./vmware-install.pl -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.
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.
- VMware Tools
- Applications and Packages
- Clean up
- Conversion to Template
- Read DoubleCloud.org
Should you have any tips and tricks, please feel free to share.