RSS
 

Posts Tagged ‘CentOS’

VMware Free Server Copy VM script

10 Mar

This is a follow-up post to VMware/CentOS build where I showed how I built my CentOS/VMWare server step by step.  You’ll find that you will want to copy virtual machines to duplicate them.  However, the VMware Server Console does not have a way for you to copy them.  You have to do it with the CLI and root access to the server.  In order to do this quickly, without having to remember what to do, I wrote a script.

This script will copy the VM  and change the names in the config file and the harddisk images.  I think there are probably more things that this could do and maybe more efficiently.  However, I find this script to work for me.  Maybe it will for you too.

++++
Begin Script
++++

#/bin/sh
#
# Script used to copy VMs for use
# with VMWare.
#
# Usage:
# copyvm VMTOCLONE NEWVMNAME
#
# Created 20090309
#
# Setup Variables
# Set “VMROOT” to VM directory where VMs reside
#
VMROOT=”/var/lib/vmware/Virtual Machines”
OLDVM=$1
NEWVM=$2
#
# Change to VM Root directory
#
cd “$VMROOT”
clear
echo
echo
echo Copying the VM called $OLDVM to new VM named $NEWVM.
echo This could take awhile…go get some coffee!
echo
echo
#
# Copy Contents of Original VM to New Directory
#
cp -ax $OLDVM $NEWVM
echo Done copying…
echo Fixing Image and file names
echo
echo
#
# Change to new VM’s Directory
#
cd $NEWVM
#
# Use VMWare diskmanager to rename VM’s Disk Image and fix file names
#
/usr/bin/vmware-vdiskmanager -n $OLDVM.vmdk $NEWVM.vmdk
#
# Change vmx file then edit the config
#
mv $OLDVM.vmx $NEWVM.vmx
sed -i “s/$OLDVM.vmdk/$NEWVM.vmdk/” $NEWVM.vmx
# Set Display name if old display name matched Old vmname
sed -i “s/$OLDVM/$NEWVM/” $NEWVM.vmx
echo All done,  Enjoy!
echo
echo

++++
End Script
++++

 
 

VMware/CentOS build

25 Feb

At work, I found it helpful to have test machines that are quick to blow up and get back to a base install. In my opinion, the best way to do this is to virtualize a box.

This is my quick software build for installing VMware (Free Server) on a CentOS 5 box.

Here are my install steps:

First Install CentOS 5 with a minimal installation (uncheck everything). After the first boot, I log in as root and go:

1 useradd somebody
2 passwd somebody
3 vi /etc/ssh/sshd_config
Here I am just verifying that ssh doesn’t allow root log in.

4 service sshd restart
5 cd /home/somebody
6 vi securemachine
Here I am pasting a script I received from a dear friend in Baltimore that uninstalls unneeded stuff.  I prefer to install anything I need as I need it.  This machine will only be a VMware box so I don’t need anything else.  Remember to set a static IP address.  This script will kill the DHCP client.

7 chmod 755 securemachine
8 ./securemachine
9 ./securemachine
10 ./securemachine
11 ./securemachine
12 ./securemachine
13 ./securemachine
14 ./securemachine
15 ./securemachine
The trick here is to keep running the script until it no longer removes packages.  The number that displays at the end will stop decreasing.

16 shutdown -r now
Sometimes, you’ll need to turn off iptables here instead of at the end.  See steps 27 and 28.

17 yum update
18 yum install glibc libxpm perl gcc kernel-devel libX11 libXtst libXext libXt libICE libSM libXrender libz libc inetd
19 shutdown -r now
20 cd /home/somebody
21 wget http://download3.vmware.com/software/vmserver/VMware-server-1.0.3-44356.tar.gz
22 cp VMware-server-1.0.3-44356.tar.gz /tmp
23 cd /tmp

24 tar zxf VMware-server-1.0.3-44356.tar.gz
25 cd vmware-server-distrib
26 ./vmware-install.pl
Answer the questions and follow the instructions.

27 service iptables stop
28 chkconfig iptables off
My machine will be on my private network and I am not worried about it.  However, you may want to set up iptables to protect your machine if you have different requirements.

30 shutdown -r now
When the machine comes back up, it will be working like a charm.  You’ll need to install the VMware Server Console to access the VM.

Good Luck!

 
1 Comment

Posted in Uncategorized