Clone a VMware’s VM without vCenter in ESXi 5.x by commands (The official way)

I will show the procedure by cloning a snapshot of a vm since this is a little more tricky than cloning just a single vm.

First let’s make a snapshot of my Xp3 vm. Right click the vm and make a snapshot, let’s call it “mySnapshot”. Of course you don’t need to do this if you just want to clone a single vm. After that, shutdown the vm otherwise the files will be locked.

vm snapshot

Now enable the ssh service on your ESXi by going to the configuration tab and the security policy option. Just start it for the moment, you don’t need to set it to start automatically. Use a ssh client like putty and connect to the hypervisor. Browse the folder under /vmfs/volumes path. It should look like this

datastores

so type

cd /vmfs/volumes
ls -la

in my case I have two datastores and my Xp3 vm is in datastore2, so let’s get into it.

Xp3 vm and snapshot

cd datastore2
ls -la

As you can see now, there are more than one vmdk disk files, the flat vmdk, the delta vmdk and the vmdk descriptor file (the Xp3-000001.vmdk file in our example), along with the memory snapshot and various control and log files. What we should use here as a source file is the descriptor file that points to our snapshot. If you didn’t have a snapshot, the source file would be the vmdk descriptor file of your vm, Xp3.vmdk.

Now, what I need to do is clone my Xp3 snapshot to a new Xp4 vm. First create the destination folder in datastore2 folder and type in the following commands

mkdir Xp4

and clone the disk file

vmkfstools -i /vmfs/volumes/datastore2/Xp3/Xp3-000001.vmdk /vmfs/volumes/datastore2/Xp4/Xp4.vmdk -d thin

if it was a single vm without a snapshot, you should run

vmkfstools -i /vmfs/volumes/datastore2/Xp3/Xp3.vmdk /vmfs/volumes/datastore2/Xp4/Xp4.vmdk -d thin

if you list the files in the destination folder you will see the new flat file and the descriptor file.

cloned disk files

The actual syntax of vmkfstools command is

vmkfstools -i source_path destination_path -d disk_format -a adapter_type

type man vmkfstools for more on this command

Finally create a new vm and force the use of an existing disk file.

create new vm

use existing virtual disk

select the cloned vmdk

You are ready to power it on.

power on

if you list the folder of the cloned vm you will see something like that

cloned vm files

Don’t forget to use sysprep command in windows to generalize your new virtual machine.

Reference: VMWare’s website article

Advertisements

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