VMware

Linked Clones script for ESXi

VERSION 2 Published

Created on: Dec 17, 2008 10:47 AM by lamw - Last Modified:  Dec 23, 2008 7:42 AM by lamw

This script allows users to create linked cloned virtual machine(s) from a master (or golden) virtual machine. Clones may be stored on any type of datastore (LOCAL, SAN, NFS) that is presented to the ESXi host. The script is very capable in deploying a large VDI environment in a relatively short amount of time.

Compatiable with:
VMware ESXi 3.5 Installable Update 3
VMware ESXi 3.5 Installable Update 2
VMware ESXi 3.5 Installable Update 1
VMware ESXi 3.5 Installable

Note: This linked clones script is virtual machine OS independent (i.e. it is not restricted to just Windows OS’s for VDI environment). For example, one can utilize this script to their advantage in development environments where new VMs need to be (mass) cloned quickly for testing.

The only supported case is the "Default case" in ghetto-esx-linked-clones.sh.

~ # ./ghetto-esxi-linked-clones.sh
######################################################
#
# UCSB ResNet Linked Clones Tool for ESXi
# Author: william2003[at]gmail[dot]com
#         duonglt[at]engr[dot]ucsb[dot]edu
# Created: 09/30/2008
#
######################################################

Usage: ghetto-esxi-linked-clones.sh [FULL_PATH_TO_MASTER_VMX_FILE] [VM_NAME] [START_#] [END_#]
        i.e.
                ./ghetto-esxi-linked-clones.sh /vmfs/volumes/4857f047-4e4ec6bf-a8b8-001b78361a3c/LabMaster/LabMaster.vmx LabClient- 1 200
        Output:
                LabClient-{1-200}
~ #
Attachments:
Average User Rating
(0 ratings)




Dec 19, 2008 8:59 AM lamw  says:

Forgot to mention, you can also find more scripts/resources located at:

http://engineering.ucsb.edu/~duonglt/vmware/

Feb 18, 2009 12:41 AM b.yucel  says:

Thanks for sharing this script I tested it and its worked great job!

but after creating a snapshot or more of linked clone it's not possible to delete the snapshot.
I got this error message:

an attempt was made to write to a read-only file

actually I checked the snapshot file properties and change it to 0755 but keep the same error.

can you help me please?

Feb 18, 2009 8:34 AM lamw  says: in response to: b.yucel

What issues are you having? Once you've created your pristine image and generated the Linked Clones off of that base image, you can use the following documentation for further configurations to make each LC unique: http://communities.vmware.com/docs/DOC-9201 , this is the implementation that my colleague Tuan and I have deployed into production at UCSB.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 18, 2009 11:03 AM b.yucel  says: in response to: lamw

this is the situation

I have created 10 Linked clones of a golden image, I can start all of them and it's working, also I can take 1 or more snapshots from each linked clones but i can not remove the snapshots.

I got this error message:
an attempt was made to write to a read-only file.

Feb 18, 2009 12:16 PM lamw  says: in response to: b.yucel

Are you creating the new snapshots using the VI Client or through the console? What version of ESXi are you running? In either case, we've not heard or run into this issue before, if I get some time will try to test but I'll be pretty busy with some new projects.


=========================================================================
--William
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/

Feb 18, 2009 12:38 PM b.yucel  says: in response to: lamw

yes through VI Client , I don't no how through console.

I'm using ESXi 3i, 3.5.0, 123629
also we have ESX server 3.5 same problem.

May 15, 2009 4:42 PM hashATsage  says:

I had the same problem and it turned out that the clone was in a template mode.
http://hash-depot.blogspot.com/2009/05/vmwares-esxi-snapshot-removal-problem.html
Check advanced settings for templateVM and if its set to "true" change it to "false". Worked for me.

Jun 22, 2009 9:17 AM mgn  says:

This is really good stuff. Thought I'd share a wee gotcha. If you dowhload the script using the obvious wget from the esxi commandline it turns up with ^M at the end of each line and the shell script falls over. Took me a while to work out what was going on.

Mike

Aug 21, 2009 2:06 AM Timothy@Coris…  says: in response to: mgn

just changed the script a bit, thought i might share back :)

vmdks_count=`grep ^scsi "${GOLDEN_VM}" | grep fileName | awk -F "\"" '{print $2}' | wc -l`
vmdks=`grep ^scsi "${GOLDEN_VM}" | grep fileName | awk -F "\"" '{print $2}'`

what changed : I changed the grep scsi to ^scsi
why : I had a floppy mounted vmscsi*.flp that contains the drivers to install xp. This blocked me from doing linked clones even after i detached the floppy, because it was still in the config. Grepping on ^scsi makes more sense because this is the pattern you are looking for

macfile() {
#grab mac addresses of newly created VMs (file to populate dhcp static config)
if -f ${LC_CREATED_VMS} ; then
for i in `cat ${LC_CREATED_VMS}`;
do
TMP_LIST=${LC_EXECUTION_DIR}/vm_list.$$
VM_P=`echo ${i##*/}`
VM_NAME=`echo ${VM_P%.vmx*}`
VM_MAC=`grep ethernet0.generatedAddress "${i}" | awk '{print $3}' | sed 's/\"//g' | head -1 | sed 's/://g'`
while
do
sleep 1
VM_MAC=`grep ethernet0.generatedAddress "${i}" | awk '{print $3}' | sed 's/\"//g' | head -1 | sed 's/://g'`
echo $(grep ethernet $i)
done
echo "${VM_NAME} ${VM_MAC}" >> ${TMP_LIST}
done
LCS_OUTPUT="lcs_created_on-`date +%F-%H%M%S`"
echo -e "Linked clones VM MAC addresses stored at:"
cat ${TMP_LIST} | sed 's/[:digit:]/ &/1' | sort -k2n | sed 's/ //1' > "${LCS_OUTPUT}"
echo -e "\t${LCS_OUTPUT}"
fi
}
#mac generation is done after the vm powers up. if you want to generate this file you will need to power on the vms first
#macfile()

what changed : Made a function to generate the file with static macs
why : Here in my version the mac addresses where only generated after the machine was powered on. This meant that the script kept looking and waiting for the mac address to be written to the vmx file. Since I don't need these mac addresses i just disabled it.

Hope it helps :)

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities