VM Template Setup Fedora

From ConShell
Jump to navigation Jump to search

Introduction

This page describes what I do to setup a "gold master" template of Linux virtual machine (VM) running on VMware Server. The example is based on Fedora 7 but is mostly applicable to other Linux distributions.

Procedure

Create a new VM called fedora of

  • Type Linux 2.6
  • Use a 8-12GB disk (do not preallocate or split)
  • Use an LSI Logic SCSI controller
  • 1024MB RAM(1)


(1) Since this will affect the size of the swap partition, so you may want to adjust that upwards for future clones.

Install operating system.

I typically use the "boot" ISO which means just enough to get the box on the network and finish the package installation using HTTP/FTP or whatever.

Next, reboot and update all the software.

yum update

Install some other bits

yum install sudo sysstat gcc gcc-c++ kernel-devel

Add any base users you want to exist in future clones. I use Justin Case (justincase) but this could just be a real person too.

adduser justincase
password justincase

Now, add the user(s) to the wheel group in /etc/group and uncomment this line in /etc/sudoers

%wheel ALL=(ALL) NOPASSWD: ALL

Adjust grub timeout (in /etc/grub.conf or /boot/grub/menu.lst) to 12s

Adjust kernel options...

  • add clock=pit or clocksource=acpi_pm divider=10
  • add noacpi

Now reboot especially if a newer kernel was installed above.

We're going to load the vmware-tools now. To do this needs a virtual CDROM Right-click on the VM and choose "Install VMware Tools" from the menu

On fedora, CDROM appears under /misc/cd but only with autofs running

/etc/init.d/autofs start
ls /misc/cd
rpm -ivh /misc/cd/VMwareTools-1.0.4-56528.i386.rpm
vmware-config-tools.pl

This should result in vmxnet and other drivers being compiled and/or loaded. Reboot and verify vmxnet is loaded (and not pcnet32)

lsmod | egrep 'vmxnet|pcnet32'

Disable unnecessary services Fedora

for s in atd auditd avahi-daemon bluetooth cpuspeed cups firstboot gpm hplip ip6tables iptables isdn kudzu mcstrans pcscd sendmail setroubleshoot smartd xfs yum-updatesd; do
/sbin/chkconfig ${s} off
/etc/init.d/${s} stop
done

Optional stuff

Remove sendmail, install postfix

rpm -e --nodeps sendmail
yum install postfix

Disable selinux

vim /etc/selinux/config
( set SELINUX=disabled )

Remove older kernels

rpm -e kernel-2.6.21-1.3194.fc7

Final Steps: cleanup & storage

rm -f /etc/ssh/*host*
rm -f /var/lib/dhcp*/*leases*
yum clean all
/sbin/shutdown -h now


Right-click the VM template name and choose Remove from Inventory

Then I tar up the VM into a compressed tarball for future cloning.

cd /opt/vm/
mkdir -p templates
cd vmname
tar cjvf ../templates/vmname.tbz2 *vmx *vmdk
cd ..
rm -rf vmname
chmod a-w templates/vmname.tbz2

Resuscitation

It can be cloned/deployed like so

cd /opt/vm
mkdir newvm
cd newvm
tar xjvf ../templates/vmname.tbz2

Then use vmware-server-console application to "Open" the corresponding vmx file.

Notes

Removing/disabling the boot-time software above saves 50M off the memory footprint (180M -> 130M) on Fedora.

Compressing the template reduces disk usage from 3.4G to 1.2G on Fedora.