Quantcast
Channel: VMware Communities : Popular Discussions - VMware Server Archives
Viewing all articles
Browse latest Browse all 69891

QnD VM Clone Bash Script

$
0
0

All,

 

Below is my quick and dirty script to clone virtual machines that I use with VMware Server Beta/RC running on a Linux host.  I KNOW it can be improved (by leaps and bounds), but "it works for me" as something quick when I need to clone a machine.

 

The way I use it is to create a core load of a machine/OS the way I want it and then (for Windows VMs) I put newsid (http://www.sysinternals.com/Utilities/NewSid.html) in the image.  Then I use my script to clone it.

 

IMPORTANT:  Your source machine SHOULD BE POWERED DOWN for the script to work properly. 

 

After you have made a clone of a Windows machine you'll have to use newsid to change the Windows name of the machine so that you won't have duplicate names on your network.

 

To use the script change the VMROOT variable to the path in which your VMs reside and then run as follows

 

clonevm mygoldimage mynewclone

 

The script will look for the first argument to the as the source VM, copy all the files to the new destination VM, and then edit the appropriate files so that the machine will start.  In the above example you will end up with a cloned VM in your $VMROOT called mynewclone.  You can then import the machine into the VMware Server console and start it. 

 

VMware Server will ask you about the machine GUID.  I usually create a new one because I'm going to create a whole new machine.  Answer the question as is appropriate for your situation.

 

Feel free to use and improve it.  Please post any improvements so that we can all benefit

 

Enjoy,

Flux.

 

\----


#!/bin/sh

 

VMROOT=/var/lib/vmware/vm

ROOT=$1

CLONE=$2

 

cd $VMROOT

 

cp -av $ROOT $CLONE

 

cd $CLONE

 

\# Loop through all named VM files and rename them

\# to the new clone name

#

ls -1 | grep $ROOT | while read VMFILE;

do

    NEWFILE=`echo $VMFILE | sed -e s/$ROOT/$CLONE/`

    mv $VMFILE $NEWFILE

done

 

\# Fix the vmx and vmdk files with the new clone name

#

cp $CLONE.vmx $CLONE.vmx.bak

cp $CLONE.vmdk $CLONE.vmdk.bak

sed -e s/$ROOT/$CLONE/g $CLONE.vmx > cloned.vmx

sed -e s/$ROOT/$CLONE/g $CLONE.vmdk > cloned.vmdk

cp -f cloned.vmx $CLONE.vmx

cp -f cloned.vmdk $CLONE.vmdk


Viewing all articles
Browse latest Browse all 69891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>