Clone an existing VM (ESXi 6.5)

Written by Super User. Posted in just going through the motions

Project: Clone an existing VM and register the clone as a new VM. Using both WinSCP and Putty. You need to enable and start SSH on the host to be able to do this.

Source: Existing VM called ‘197-2012r2’. Source directory is: ‘/vmfs/volumes/datasstore0/197-2012r2/’ and source file is ‘197-2012r2.vmdk’
Clone is ‘196-2012r2’ and use a directory called: ‘/vmfs/volumes/datasstore0/196-2012r2/’

1. Get path and name of the relevant source vmdk file. The simpel way to do this, is by using WinSCP. WinSCP (Filename -> Copy to clipbord (including Patch Ctrl + Alt + C). Should get you something like this:

/vmfs/volumes/544be746-b630c8ec-e0e0-bc305be94cea/197-2012r2/197-2012r2.vmdk

Notice: It is not the actual image file you are looking at here. Just the configuration file - mush smaller.

2. Create a directory for the new clone from putty (You can use the datastore name). Like:

mkdir /vmfs/volumes/datastore0/196-2012r2

3. Clone the vm using the vmkfstools -i command with or without the optional thin option. By default, the vmkfstools -i command will create a thick provisioned disk. If you want the destination disk to be thin provisioned, add -d thin.

vmkfstools -i [source] [target] -d thin

Thick:

vmkfstools -i /vmfs/volumes/datastore0/197-2012r2/197-2012r2.vmdk /vmfs/volumes/datastore0/196-2012r2/196-2012r2.vmdk

Thin:

vmkfstools -i /vmfs/volumes/datastore0/197-2012r2/197-2012r2.vmdk /vmfs/volumes/datastore0/196-2012r2/196-2012r2.vmdk -d thin

Would be nice, if the job was shown in the console - but you will not see this clone job in the vSphere client task list. So it goes. After the process has completed, two new .vmdk file have been created:

[root@BISHOP:~] ls -hl /vmfs/volumes/datastore0/196-2012r2/
total 52430856
-rw------- 1 root root 50.0G Apr 24 14:25 196-2012r2-flat.vmdk
-rw------- 1 root root 549 Apr 24 14:05 196-2012r2.vmdk


You cannot register these files from the vSphere Client – these files are just the hard disk. The configuration information is still missing. Instead you must create a new VM from the client, and attach the file/disk you have just cloned.

Can easily turn in to a bit of a mix-up, with file/directory names. Cloned file and directory before doing anything in the vSphere Client. I.e. the source for the new VM: /vmfs/volumes/datastore0/196-2012r2/196-2012r2.vmdk. Therefore I like this VM to be: 196-2012r2. Make sense.

Therefore we need to create a new VM from the vSphere Client. Not 100% sure this is necessary, but as this is a clone of a running VM, I assume CPU configuration need to be identical with the original VM. Not sure. Source VM had 4 CPU's, so the clone is also getting 4 CPU's. Likewise choosing identical controller of the source VM.

Name and guest OS: Choose a silly name for the new VM. I will use '196-2012r2'. For the 'Compatibility', 'Guest OS family' and 'Guest OS version' I will choose settings from the original source VM. 'vmkfstools' do not remove VMware tools from the clone.
Select storage: Must be the datastore where the clone was saved. In my case: datastore0.
Customize settings: Delete the default created disk (Hard disk 1) and use 'Add hard disk' (add existing disk) Choose the created clone. In my case: 196-2012r2.vmdk.

Your clone is now created and registered in the vSphere Client. The VM target directory should now include two more files:

[root@BISHOP:~] ls /vmfs/volumes/datastore0/196-2012r2/
196-2012r2-flat.vmdk 196-2012r2.vmdk 196-2012r2.vmsd 196-2012r2.vmx

Turn the new VM on, and make sure it can start without issues.

Source https://kb.vmware.com/kb/1027876

Add comment


Security code
Refresh