vsphere_static_160x300
Free Business and Tech Magazines and eBooks
Badges

vexpert_logo_100x57

gestaltitbadge

follow-me-twitter

Subscribe to me on FriendFeed

Comments / DISQUS
Feedjit.com

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:

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.

Download phxrider_vmwareserver_scripts.zip

Related Posts

  • Statte
    Works fine on Vmware Workstation 6.5 running on Opensuse 11.0

    Great work !

    Thanks
  • Statte,

    Good to know the scripts work for VMware Workstation VMs on Linux hosts. The "great work" compliment goes to phxrider! (linked above)
  • Tony
    Hi Rich, I am running Ubuntu 8.04 with vmware. I have created a Windows 2003 server to use as a template and have used the clone_vm.sh script to create a clone which it has done. When I go to start it it says that the Hard dive is not valid. I have gone back and compared the files and all are of the same size except the vmx and vmxf files which are only different by the clone's name as you would expect. The vmdk files is the same to the byte. I have blown the clone away a couple of time but have had the same results. Do you have any ideas? I am real newbie (know my way around Windows & DOS) but am out of my depth here. Would be grateful for any help .. thanks
  • Tony
    I have found the answer and thought it may help others. In the clone.vmdk file under the comment 'Extent description' you may find the referenced file is still the original vm name just rename it to the clone. In my case the line now reads: RW 41943040 FLAT "clone-flat.vmdk" 0. May I say that phxrider has done a top job and it will be of great value to me and I sure others in the future.
  • sippo
    Almost worked in SLES 10SP2, I did the following change into both
    scripts:

    Original - skips all *.vmdk, also <name>.vmdk that is a textfile
    containing disknames.

    echo "\nReplacing \"$SOURCE\" with \"$DEST\" in text files:"
    ls "$DEST" | grep -v "\(\.nvram$\|\.vmdk$\|\.log$\)" | while read FILE
    do

    My modification, now renames also <name>.vmdk, but not
    touch <name>00n.vmdk files

    echo "\nReplacing \"$SOURCE\" with \"$DEST\" in text files:"
    ls "$DEST" | grep -v "\(\.nvram$\|[0-9]\.vmdk$\|\.log$\)" | while read FILE
    do

    Enjoy!

    regards, Sippo
  • Sippo,

    Thanks for the providing the work around to get the clone and rename scripts to work for VMware Server on SLES 10!
blog comments powered by Disqus
Hyper9 Cowabunga
Support VM /ETC
Support VMETC.com

Support VMETC.com

@rbrambley tweets
Advertisements
VMTN Roundtable Podcasts
Subscribe



Add to Google Reader or Homepage
Subscribe in NewsGator Online
Add to netvibes
Add to Plusmo