Linux scripts to clone and rename VMware Server VMs
If you run the free VMware Server on a Linux host then VMTN Communities user phxrider has created a couple of scripts that can make your life a little easier. Phxrider’s clone and rename scripts automate the process of two administrative tasks that are frankly a burden to do manually. Both VMware Server 1.x or 2.0 do not offer any template or cloning abilities from their respective GUI interfaces, so these scripts are an essential tool to have if you want to duplicate VMs or change the VM’s files to match a renamed directory.
Check out either http://communities.vmware.com/docs/DOC-8050 or the VMTN Forum thread at http://communities.vmware.com/thread/168266 to download the scripts. Here’s some brief info from these links:
“The clone script does a straight clone of a VM. It copies the directory, renames the files and tweaks all the text inside the files by using sed to replace the old name with the new one, then sets all the permissions to what they would be if you created a new VM.
The rename script basically does all but copy it. This is handy for if you tried to rename a directory manually or attempted a manual copy and then found it still shows up under the old name in the web console. Remember this one assumes you have already renamed the directory to the new name and it MUST be the same as what you intend for the new name to be.
Both work the same way… scriptname <old name> <new name>”
I am not aware of equivalent scripts for VMware Server hosted on Windows, but if they exist please leave a comment with a link for VM /ETC readers.
The rest of this post is my example of using the clone_vm.sh script to make a template for future VMware Server 2.0 VM cloning.
Using the clone_vm.sh script to create a templatefor future cloning
In this example I have a Windows 2003 Server VM that I want to create a template from for future VM clones. I want to keep the current VM as is, but clone it to a new VM and then clean it up and sysprep it so it can become a template to be cloned for future VMware Server VMs. For this example here are some things you need to know:
- VMware Server 2.0 is running on Ubuntu Server 8.0.4
- The VM directory on host server is /home/hcrestadmin
- Source VM is named winS01
- Source VM directory is /home/hcrestadmin/winS01
- New VM will be named winT2003
- New VM directory will be /home/winT2003
- I used winSCP to transfer the script files to my Ubuntu Server
- I used Putty to log on remotely to run the script
After downloading and transferring the clone_vm.sh script to the /home/hcrestadmin directory it was time to run the script. Since I was logged as in my hcrestadmin account I had to use super user privileges by entering “#su –” and my password. Then I was ready to start the script.
root@vmwS01:/home/hcrestadmin# sh clone_vm.sh winS01 winT2003
The following screen shot shows the script in progress.

Once the script finished I was able to use the VMware Server web interface to add the new VM as an existing Virtual Machine. From the main Summary Tab select “Add Virtual Machine to Inventory” from the Commands section and you can browse to the new folder and .vmx file created by the script

Then I could power on the VM, clean it up by removing services and programs, and then use Sysprep to reseal the OS and power it off. Once finished, I was ready to deploy clones from this VM folder by repeating the vm_clone.sh process on this sysprep-ed template.
For help building an Ubuntu 8.0.4 Server and installing VMware Server 2.0 use the following links as references:
- https://help.ubuntu.com/community/VMware/Server
- https://help.ubuntu.com/8.04/serverguide/C/installation.html
- http://www.howtoforge.com/perfect-server-ubuntu8.04-lts
- http://ubuntuforums.org/showthread.php?t=779934
- http://www.howtoforge.com/how-to-install-vmware-server-2-on-an-ubuntu-8.04-desktop
I am keeping copies (as of this post’s publish date) of the scripts here on VM /ETC for posterity, but be sure to check phxrider’s links for any current versions.
Related Posts
-
Statte
-
rbrambley
-
Tony
-
Tony
-
sippo
-
rbrambley











