Tuesday, October 26, 2010

How to clone a running virtual machine in vSphere

  • First you have to login to service console using a ssh client like putty. You can also do the same on a ESXi server if you have enabled the Remote Tech Support Mode.
  • Then you have to take a snapshot of the running virtual machine using vi client.
  • After that you have to create a new virtual machine using the vi client.
  • From the service console delete the virtual hard disk of the newly created virtual machine:
# cd /vmfs/volumes/datastore1/newvm
# rm *.vmdk
  • Then copy the virtual hard disk from the original virtual machine to the new virtual machine:
# vmkfstools -i /vmfs/volumes/datastore1/oldvm/oldvm.vmdk /vmfs/volumes/datastore1/newvm/newvm.vmdk
  • If you want to create a thin virtual hard disk use this syntax:
# vmkfstools -i /vmfs/volumes/datastore1/oldvm/oldvm.vmdk -d thin /vmfs/volumes/datastore1/newvm/newvm.vmdk
  • Delete the snapshot from the running original virtual machine using vi client.
For more info read this post.