Cloning a VM without vCenter in ESXi 5.1 free edition

Check out my new vm cloning article here.

VMware vSphere is the most robust virtualization solution today. Cloning a Virtual Machine (VM) in ESxi 5.1 is a feature of vCenter server. Out of the box vSphere free edition hypervisor does not support cloning. But there is an alternative way to clone a VM.

vSphere client version

vSphere client version

In this example we will use version 5.1.0.

vSphere client connection

vSphere client connection

First connect to the VSphere using the vSphere client and power off the source VM.

vSphere client User Interface

vSphere client User Interface

Select the Configuration tab and Storage settings on the left menu. The Datastores list will come up on the right pane.

vSphere Datastores

vSphere Datastores

Right click on the datastore of the source VM and select Browse.

Datastore

Datastore

Right click on the root folder on the left tree and create a new folder. e.g Application

Copying the files

Copying the files

Select the source folder of the VM to be cloned (2008R2 Machine in this example) and select the configuration file (.vmx) and the virtual disk file (.vmdk). Right click and copy them to clipboard. Now select the destination folder and paste the two files. Finally, right click the copied .vmx file and select Add to Inventory.

Add to Inventory wizard

Add to Inventory wizard

Enter the name of the cloned VM and finish the wizard. Now the VM has been created to the vSphere hypervisor.

In case of  using a VM as a template you should make sure that the template is unique everytime. So you must use sysprep utility to generalize the VM. In case of windows 2008R2 sysprep is included in the windows installation, under the folder c:\windows\System32\sysprep. This utility exists for other Windows versions as well.

Sysprep utility

Sysprep utility

Run sysprep and select Enter System Out-of-Box Experience, check the Generalize box and select Shutdown.

Make a generic VM template

Make a generic VM template

Now everytime you power on the template VM, a mini setup will come up to configure your new VM.

Post Remarks

Check out my new vm cloning article here.

As Frank noted in the comments, it is possible to clone the vm and specify the filenames by command. SSH to your ESXi and use the vmkfstools -i command. Use -d option to specify the thin/thick disk format. Be careful if you need to consolidate delta disks/snapshots. You can find more detailed information in this VMware’s article.

Advertisements

39 thoughts on “Cloning a VM without vCenter in ESXi 5.1 free edition

    • No, it doesn’t matter, same files at different directories. That’s the trade off you have to pay, but everything works smoothly.

      • Thanks man, it worked like a gem. My manager was not giving me access to vCenter. You trick worked. Thanks

  1. If you’d like different vmdk file names, you can connect to the host via SSH and use the “vmkfstools” command, with the parameter “-i” to clone a vmdk (description file, flat file, and auto-adjusts the filename). The syntax is “vmkfstools -i /vmfs/volumes/DATASTORE-NAME/SOURCE-DIR/SOURCE-DISK /vmfs/volumes/DATASTORE-NAME/DEST-DIR/DEST-DISK”.

    • I have verified, that this does work even with the free license. I have just used this tool to clone a disk on esxi 5.1 with the free license installed. For those that need a bit more explanation on step-by-step, here it goes.

      1) Enable SSH on the esxi host. To to the configuration tab of the server, then under the Software group, click Security Profile. On the right, click on properties for Services (not Firewall). Then click on SSH, and then click Options. Click Start, then OK twice.

      2) Connect to the server via SSH (i use PuTTY). Log-in as root.

      Create a new folder for the new VM:
      cd /vmfs/volumes/YOURDATASTORE
      mkdir NEWSERVERNAME

      Then use the command / syntax provided by Frank:
      vmkfstools -i SourceServer/SourceServer.vmdk NewServer/NewServer.vmdk

      You will see something like this:
      Destination disk format: VMFS zeroedthick
      Cloning disk ‘../fs1/fs1.vmdk’…
      Clone: 100% done.

      Cheers.

  2. I’ve followed the process twice but I get the same result: the cloned machine won’t find any Boot code off the new disk? I originally created this machine using a VMware client; would this make a difference? If so how do I overcome it please?
    Thanks
    Andy.

      • Andrew, give me some more info… The template vm is new or an existing one? Is it one vmdk or more? Did you upgrade an existing ESXi? If yes, did you upgrade the vmware tools as well? Thanks!

      • The history is:
        Please pardon my ignorance of certain terms: I’m a 30+ Network Engineer but my server skills are minimal.
        I built a VMware server on an established Windows XP PC I had lying around just to see if I could, (this is now discarded). I then bought an HP Proliant N54L Microserver and built it using ESXi 5.1 using the download and directions from the website. Once it was built, in my ignorance, I mistakenly used the existing VMware client to administer it. I realise now I should have downloaded and installed the ESXi client from the newly built server. Anyway after realising this I installed and now only use the ESXi client.
        I’ve only built a couple of virtual servers on the HP server. One, the Windows XP, is fully patched, etc. and this is the one I’m trying to clone using the directions above.
        Aside from this it’s an all virgin/plain vanilla install; I haven’t changed anything. Not messed with Templates, or upgraded anything from the original ESXi 5.1 intall.

      • Andrew, did you install vmware tools? On vsphere client select the vm on the left pane and goto inventory, virtual machine, guest, install/upgrade vmware tools.

  3. Nikos, thanks for your clear instructions. If I have several snapshots, how would I just the cloned the latest one as a final image?

    • Hi Ronald, do you want to keep the snapshots? Whenever you take a snapshot a new delta disk is created, so if you need the latest disk state you will need to keep all the delta disks. Why don’t you delete the old snapshots and consolidate the disk file?

    • Eric, you should not rename the files. Right click the .vmx file to add it to the inventory, not the .vmdk.

  4. Is it supposed to take a long time for the ‘cloned’ VMs to boot up for the first time?
    I cloned the VM 3 times & they’re all stuck at 95% on ‘Power on VM’

  5. Thank you!

    Using these instructions, I have a resident (and removed from Inventory) image called ‘Template32Win7’ that I can now ‘clone’ using the following script:

    [clone32Win7]
    —–
    #!/bin/sh
    mkdir /vmfs/volumes/datastore1/$1
    vmkfstools -i /vmfs/volumes/datastore1/Template32Win7/Template32Win7.vmdk /vmfs/volumes/datastore1/$1/$1.vmdk -d thin
    cp /vmfs/volumes/datastore1/Template32Win7/Template32Win7.vmx /vmfs/volumes/datastore1/$1/$1.vmx
    sed -ie “s/Template32Win7/$1/g” /vmfs/volumes/datastore1/$1/$1.vmx
    vim-cmd solo/registervm /vmfs/volumes/datastore1/$1/$1.vmx
    —–

    As you can see, this script handles pretty much everything from the shell. It takes the new workstation name as an argument. E.g.
    —–
    clone32Win7 Workstation4
    —–

    This has been tested on ESXi 5.1 as of 02/17/14.

    Enjoy!

    • Hi, in 5,5 it gives this output:

      Clone: 100% done.
      sed: unsupported command ▒

      Is there a difference between 5.1 and 5.5 for doing this?

      • Looks like the sed command didn’t like ” so I swapped it with ‘ and now the VM gets created. Great.

        But it’s call $1 as there is a reference to this in the vmx. I suspect sed isn’t doing its job fully.

        I’ll continue testing.

        This is what’s in the script now:

  6. #!/bin/sh
    mkdir /vmfs/volumes/SSD\ RAID5/$1
    vmkfstools -i /vmfs/volumes/SSD\ RAID5/Template2012/Template2012.vmdk /vmfs/volumes/SSD\ RAID5/$1/$1.vmdk -d thin
    cp /vmfs/volumes/SSD\ RAID5/Template2012/Template2012.vmx /vmfs/volumes/SSD\ RAID5/$1/$1.vmx
    sed -ie ‘s/Template2012/$1/g’ /vmfs/volumes/SSD\ RAID5/$1/$1.vmx
    vim-cmd solo/registervm /vmfs/volumes/SSD\ RAID5/$1/$1.vmx

    • If you use single quotes the shell won’t do variable substitution and you will end up with a $1 and not the value of the first parameter. Use double quotes, but make sure (if you copy and paste) that you have simple “double quotes” and not smart quotes that angle \\ and // around the quoted word…

  7. $1 is the first variable input after the script runs: ./create_clone.sh VMNAME
    You can assign variables in shell scripts this way $2, $3…. and they would be added after the script is called on the command line.

  8. Hi,

    I have ESX 5.1 free version and vSphere client. We do not have vCenter Server in my environment. I tried your copy/paste method to clone VM from vSphere client and it was successful. I was able to configure new VM. now both old and new VMs are working fine,
    However, after configuring new VM I still see same file names fpr both VM on ESX server.
    Here are the files under datastore2 which is my cloned VM which I named as NNM_IPMC_9.20_With_Config. The original VM is under datastore3 with name NNM_IPMC_9.20_RH_6.5_Base. But I see same file names under both datastore2 & 3 which can be misleading going forward.

    Can you please let me know how can I change file names under datastore2 which is my cloned new VM.

    /vmfs/volumes # ll datastore2/NNM_IPMC_9.20_With_Config
    -rw——- 1 root root 12884901888 Aug 12 20:23 NNM_IPMC_9.20_RH_6.5_Base-d674fab8.vswp
    -rw——- 1 root root 40802189312 Aug 18 13:41 NNM_IPMC_9.20_RH_6.5_Base-flat.vmdk
    -rw——- 1 root root 8684 Aug 17 14:45 NNM_IPMC_9.20_RH_6.5_Base.nvram
    -rw——- 1 root root 535 Aug 12 20:23 NNM_IPMC_9.20_RH_6.5_Base.vmdk
    -rw——- 1 root root 0 Aug 12 20:16 NNM_IPMC_9.20_RH_6.5_Base.vmsd
    -rw——- 1 root root 3220 Aug 12 20:23 NNM_IPMC_9.20_RH_6.5_Base.vmx
    -rw——- 1 root root 0 Aug 12 20:19 NNM_IPMC_9.20_RH_6.5_Base.vmx.lck
    -rw——- 1 root root 280 Aug 12 20:16 NNM_IPMC_9.20_RH_6.5_Base.vmxf
    -rw——- 1 root root 3220 Aug 12 20:23 NNM_IPMC_9.20_RH_6.5_Base.vmx~
    -rw——- 1 root root 34359738368 Aug 18 13:41 NNM_IPMC_9.20_RH_6.5_Base_1-flat.vmdk
    -rw——- 1 root root 537 Aug 12 20:23 NNM_IPMC_9.20_RH_6.5_Base_1.vmdk
    -rw-r–r– 1 root root 270513 Aug 17 14:45 vmware.log
    -rw——- 1 root root 113246208 Aug 12 20:19 vmx-NNM_IPMC_9.20_RH_6.5_Base-3597990584-1.vswp
    /vmfs/volumes # ll datastore3/NNM_IPMC_9.20_RH_6.5_Base/
    -rw——- 1 root root 40802189312 Aug 12 20:38 NNM_IPMC_9.20_RH_6.5_Base-flat.vmdk
    -rw——- 1 root root 8684 Aug 12 20:38 NNM_IPMC_9.20_RH_6.5_Base.nvram
    -rw——- 1 root root 512 Aug 12 20:37 NNM_IPMC_9.20_RH_6.5_Base.vmdk
    -rw-r–r– 1 root root 0 Aug 12 14:47 NNM_IPMC_9.20_RH_6.5_Base.vmsd
    -rwxr-xr-x 1 root root 3219 Aug 12 20:38 NNM_IPMC_9.20_RH_6.5_Base.vmx
    -rw-r–r– 1 root root 280 Aug 12 18:59 NNM_IPMC_9.20_RH_6.5_Base.vmxf
    -rw——- 1 root root 34359738368 Aug 12 20:38 NNM_IPMC_9.20_RH_6.5_Base_1-flat.vmdk
    -rw——- 1 root root 514 Aug 12 20:37 NNM_IPMC_9.20_RH_6.5_Base_1.vmdk
    -rw-r–r– 1 root root 208389 Aug 12 15:06 vmware-3.log
    -rw-r–r– 1 root root 243489 Aug 12 15:10 vmware-4.log
    -rw-r–r– 1 root root 208405 Aug 12 15:12 vmware-5.log
    -rw-r–r– 1 root root 346814 Aug 12 18:08 vmware-6.log
    -rw-r–r– 1 root root 123650 Aug 12 20:13 vmware-7.log
    -rw-r–r– 1 root root 119742 Aug 12 20:35 vmware-8.log
    -rw-r–r– 1 root root 119101 Aug 12 20:38 vmware.log
    /vmfs/volumes #

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s