I primarily use XenServer from Citrix, as it's fast, efficient, easy to install, less hardware-specific, and a darn sight cheaper than VMWare.
I also do large amount of toolsmithing... and realised, this little script here could save many people a large volume of time, this is the current iteration of the VM configure script I run.
The way I use it is simple:-
- Install a base VM (I normally call this "template")
- Configure the VM with any necessary VM guest tools (Xen Guest, VMWare Guest, etc)
- Install any necessary packages that should be on all guest VM's (eg. screen, vim, puppet, or whatever)
- Copy in this script, and make it executable by root
- Power this VM down and convert it to a template, or store as a copyable VM
- Create all new machines from the template, and run the script giving the necessary options
You will note, this script is currently only directly usable for Debian-based systems (tested with Debian and Ubuntu primarily), or systems that use a Debian-style file system layout. This is because I almost never get asked for RPM-based distro's, and so when I need to install those, they are one-offs in most cases. The script could be fairly easily adjusted to run with those, and if I installed enough of them, I'd modify the script to handle both distro styles.
#!/bin/bash
# configure-vm.sh
# Copyright (c) 2008-2012, Cassandra Brockett
# Authorised for use by all, though I must approve inclusion in a commercial solution.
HOSTNAME=$1
IP=`echo $2 | sed 's/\(.*\)/\U\1/'`
# Change this for the domain of the host!
DOMAIN="example.com"
# Check if I am running as root, if not, error and exit
if [ $UID -ne 0 ]
then
printf "ERROR: This script MUST be run as root!\n\n"
exit 100
fi
# Check if given the hostname of the host, if not, error and exit.
if [ -z "$HOSTNAME" ]
then
printf "ERROR: No hostname given!\n\n"
exit 10
fi
# Check if given the IP Address of the host, if not, error and exit.
if [ -z "$IP" ]
then
TESTIP=`host oph-slvdns01 | sed 's/.* has address //'`
if [ -z "TESTIP" ]
then
printf "ERROR: No IP address given!\n\n"
exit 10
fi
IP=$TESTIP
fi
NETMASK=`ifconfig eth0 | grep -i "inet addr:" | sed 's/.*Mask://'`
GATEWAY=`route | grep -i "default" | sed 's/default //' | sed 's/ .*//'`
# Make sure vm is fully updated...
apt-get update
apt-get -y dist-upgrade
apt-get -y dist-upgrade
# Create hostname file
printf "$HOSTNAME\n" > /etc/hostname
# Create hostname file
printf "$HOSTNAME.$DOMAIN\n" > /etc/mailname
# Create hosts file
printf "127.0.0.1\tlocalhost\n" > /etc/hosts
printf "127.0.1.1\t$HOSTNAME\n" >> /etc/hosts
printf "\n" >> /etc/hosts
printf "# The following lines are desirable for IPv6 capable hosts\n" >> /etc/hosts
printf "::1 localhost ip6-localhost ip6-loopback\n" >> /etc/hosts
printf "fe00::0 ip6-localnet\n" >> /etc/hosts
printf "ff00::0 ip6-mcastprefix\n" >> /etc/hosts
printf "ff02::1 ip6-allnodes\n" >> /etc/hosts
printf "ff02::2 ip6-allrouters\n" >> /etc/hosts
# Create interfaces file
printf "# This file describes the network interfaces available on your system\n" > /etc/network/interfaces
printf "# and how to activate them. For more information, see interfaces(5).\n" >> /etc/network/interfaces
printf "\n" >> /etc/network/interfaces
printf "# The loopback network interface\n" >> /etc/network/interfaces
printf "auto lo\n" >> /etc/network/interfaces
printf "iface lo inet loopback\n" >> /etc/network/interfaces
printf "\n" >> /etc/network/interfaces
if [ "$IP" = "DHCP" ]
then
printf "# The primary network interface\n" >> /etc/network/interfaces
printf "auto eth0\n" >> /etc/network/interfaces
printf "iface eth0 inet dhcp\n" >> /etc/network/interfaces
else
printf "# The primary network interface\n" >> /etc/network/interfaces
printf "auto eth0\n" >> /etc/network/interfaces
printf "iface eth0 inet static\n" >> /etc/network/interfaces
printf "\taddress\t\t$IP\n" >> /etc/network/interfaces
printf "\tnetmask\t\t$NETMASK\n" >> /etc/network/interfaces
printf "\tgateway\t\t$GATEWAY\n" >> /etc/network/interfaces
fi
# Below here, do anything special you wish to do for each system.