Creating virtual machine clones and templates without vCenter Server

Even if you don't have vCenter Server's virtual machine (VM) cloning feature, you can create VM templates with tools such as vConverter, vmkfstools and VMware Infrastructure Client – and a little technological prowess.

VCenter Server enables you to quickly create virtual machines by using templates and the clone feature. You can,

however, accomplish the same thing with vCenter Converter, the vmkfstools command line interface utility or the VMware Infrastructure Client's browser. Using vCenter Converter is fairly straightforward process. Although equally useful, the other two methods both require some technical prowess, which we'll delve into in this tip.

To begin, simply create some virtual machines (VMs) that you want to use as templates. It's a good idea not to create virtual disks that are too large for your template VMs, as you can always increase the size of the disks of the VMs that you create later on but reducing the size can be more difficult. You can use some of the methods described in another article I wrote, Increasing virtual disk file partition size with DISKPART or GPartED, to increase the size of a VM's disk. You may also consider creating some identical template VMs of varying disk sizes, for example a Windows 2003 Server with a 10 GB virtual disk and another with a 20 GB virtual disk. That way, when you create a new VM, you can choose a template that has an appropriately sized disk for what you need. Once you have your source template VMs setup and configured you are ready to clone them and create new VMs.

Creating templates with vCenter Converter
The first method to do this is to use vCenter Converter to clone an existing VM. With the free starter version you must install it on the VM to be converted, as remote conversions are only supported with the enterprise version that is included with vCenter Server. Once you install it you can load the Converter Manager application, convert a physical computer and then select the local computer as the source. Next, you would select an ESX host as your destination. Optionally, you could choose to resize the virtual disks from the source VM. This can be handy if you want to create new VMs that have different sized virtual disks then your source VM. Once the conversion process completes you will have a new VM that you can power-on and customize.

There are two additional methods are similar in nature. Both consist of creating a new VM without a hard disk and then making a copy of an existing VM disk file for the new VM to use. The main difference between these two methods is that one uses the vmkfstools command line (CLI) utility that exists in the ESX service console (ESXi uses the Remote CLI interface), and the other uses the datastore browser in the VMware Infrastructure Client (VI Client). VMware enhanced the datastore browser in ESX 3.5 to allow for copying files so if you are running ESX 3.0.x you will have to use the vmkfstools method instead.

The first step for both of these methods is to create a new VM without a hard disk. If you are running ESX 3.5 this is an option if you choose the Custom wizard type when creating the VM as shown below. In these examples we will be creating a new VM called green and creating a copy of the virtual disk from a VM called orange to be used with the new green VM.


Click to enlarge.

Earlier versions of ESX (3.0.x) required you to create a hard disk for your VM. Now, you can simply create a VM with a small hard disk and then go back and edit the settings and delete the hard disk after you create the VM.

Now that you have a new VM (green) without a hard disk you are ready to create a copy of an existing VM's disk (orange) to use with it. First you should power-off the VM that you want to copy so its disk lock is released. Alternately, you can create a snapshot of the VM which will allow you to copy the disk while the VM is powered on.

Creating templates using vmkfstools
To use the vmkfstools method follow the below steps:

  1. Log in to the service console. You will be using the vmkfstools command with the –i parameter which will make a copy of the virtual disk file using the following format: vmkfstools –i . Note that a virtual disk consists of two different virtual disk files, a small descriptor vmdk file and a large data vmdk file. Both files are automatically copied by vmkfstools. To find the name of the source disk file name you can edit the settings of the VM and select the virtual disk and it will be displayed as shown below.


    Click to enlarge.

     

  2. Run the vmkfstools command with the appropriate source and destination virtual disk file names (watch your case as it is case sensitive). The source should include the full path to the source VM disk and the destination should include the full path to the VM that you created in step 1. For example: vmkfstools –i
    /vmfs/volumes/storage1/orange/orange.vmdk
    /vmfs/volumes/storage1/green/green.vmdk

    This will create a copy of the orange VM's virtual disk into the directory for the new green VM. Once the copy operation completes you can log out of the service console.


    Click to enlarge.

Creating templates with the VMware Infrastructure Client
To use the VMware Infrastructure Client's datastore browser method (ESX 3.5.x only) follow the below steps:

  1. In the VI Client, select your host server. On the Summary tab, select the datastore that your source VM (orange) is located on. Right-click it. Select the Browse Datastore option.


    Click to enlarge.

     

  2. When the datastore browser window appears, select your source VM directory in the left pane. This action will display all of the files for the VM in the right pane. Right-click on the virtual disk file for the VM (type will be Virtual Disk) and select the Copy option.


    Click to enlarge.

     

  3. In the left pane select the VM that you created earlier, and then right-click in the right pane and select Paste.


    Click to enlarge.

     

  4. Once the copy operation completes the newly copied virtual disk file will have the same filename as the source VM (i.e. orange.vmdk). This will not cause a problem because it is in a separate directory as the source VM, but it is a good idea to rename it so it is the same as the new VM you created to avoid confusion. Unfortunately, while you can rename other file types with the datastore browser, you cannot rename virtual disk files with it and the only way to do it is with vmkfstools using the –E option (i.e. vmkfstools –E as shown below.


    Click to enlarge.

You can now add the copied disk to the new VM by editing its settings and adding a new virtual disk. Instead of creating a new hard disk, just select the option to use an existing hard disk and browse to the new disk file that was created in your VMs directory. Once you add the hard disk and save the VM settings, you can power-on your VM and customize it if needed. Just don't forget to delete the snapshot on your source VM if you created one.

As you can see these methods provide the added benefit of using templates and cloning for those that do not have a vCenter Server. Once you build some virtual machines to use as templates you will find that you can create new virtual machines with these methods almost as quickly as you can if you have a vCenter Server.

ABOUT THE AUTHOR: Eric Siebert is a 25-year IT veteran with experience in programming, networking, telecom and systems administration. He is a guru-status moderator on the VMware community VMTN forums and maintains VMware-land.com, a VI3 information site.
 

This was first published in January 2009

Dig deeper on VMware how-tos

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchServerVirtualization

SearchVirtualDesktop

SearchDataCenter

SearchCloudComputing

Close