Recently had a situation arise where a stand-alone ESXi 5 host that was not managed by vCenter (it’s standalone, get it?) needed one of its VMs cloned, but the source VM was important and could not be powered off for a cold-clone to be performed.
Thanks to VMETC.COM’s Cloning a running Virtual Machine using the Service Console, (who gives credit to Eric Siebert), the process is pretty simple, and really just uses vmkfstools to make a copy of the source VM’s disk after a snapshot has been created. This frees up the source VM’s disk(s) for reading by vmkfstools to make a copy.
- Create a new VM with identical settings as the source VM
- Disk (SCSI controller, etc)
- Set the NIC to not connect at startup, and change the portgroup assigned to a vSwitch with no other guest VMs or physical uplinks, in order to isolate it so it does not interfere with the source VM.
- Using the vSphere client connected to the host, take a snapshot of the source VM – do not include guest memory. Name the snapshot whatever you’d like.
- Now that a snapshot has been taken, the source VM is writing to its delta disk and not its main disk (still reads from it though) so it can be cloned using the command line.
- SSH to the ESXi host (or get on the ESXi host console) and navigate to the new VM’s directory and delete the vmdk files: rm *.vmdk
- This clears the way for the disk copy to be succcessful, but keeps the disk registration in the new VM’s vmx configuration file.
- Navigate to the source VM directory and use vmkfstools to clone the disk: vmkfstools -i sourceVM.vmdk -d thin /vmfs/volumes/datastore01/newVM/newVM.vmdk
- This will create a thin-provisioned (-d thin) copy (-i) of sourceVM.vmdk from the source VM’s directory to the newVM’s directory (/vmfs/volumes/datastore01/newVM).
- Clone any other disks
- When the clone is finished, power it on (making sure it’s on an isolated portgroup with its NIC disconnected)
- The OS will act like it was hard-powered-off so it may do some disk checks at boot in order to mark the filesystem as clean.
- Open up the console of the VM and change its IP address and hostname and anything else that would conflict with the source VM.
- Once done, connect it back to the appropriate portgroup and you should be all set!
- Don’t forget to remove the snapshot on the source VM!
The process is incredibly simple and much faster than spinning up a win2k8 instance with a demo instance of vCenter, just to make a clone of a VM. It’s also easier than using VMware Converter to do a V2V conversion.
If using this method to clone a Windows guest, there may be some extra work involved (such as re-joining to the domain, etc).