Home » Configs » Clone a Virtual Machine from the Command Line Using ESXi

Clone a Virtual Machine from the Command Line Using ESXi

Clone a Virtual Machine from the Command Line Using ESXiNeed to Clone a Virtual Machine from the Command Line Using ESXi because you don’t have VCenter? This post will show you how.

Clone a Virtual Machine from the Command Line Using ESXi

It’s far simpler and quicker to duplicate or clone an existing VM, than it is to build one from scratch.

In this example you are cloning Host1 and calling it Host2

Note: Your datastore name may not be “datastore1”, so please modify these commands accordingly.

SSH into your ESXi host and create a directory to hold your new clone

BASH
#mkdir /vmfs/volumes/datastore1/Host2

This is the command line to clone (copy) your Host1 VM to Host2

BASH
#vmkfstools -i /vmfs/volumes/datastore1/Host1/Host1.vmdk /vmfs/volumes/datastore1/Host2/Host2.vmdk -d thin

Remember to use “-d thin” if you want to use thin provisioning for your virtual hard disks!

Register the Virtual Machine in ESXi

Creating a clone, from the command line, does NOT add it to your ESXi server’s inventory.

  1. Log in as root to the ESXi host with an SSH client.
  2. Run the command:
BASH
# vim-cmd solo/registervm /vmfs/volumes/datastore1/Host2/Host2.vmdk

Note: Your datastore name may not be “datastore1”, so please modify this command accordingly.

I’ve had mixed results using this command to register the cloned VM. Sometimes it’s easier to run the New Virtual Machine wizard, select Custom, layout all the VM settings, then when its time to setup a Hard disk, select the option to use an existing hard disk and browse to the newly cloned vmdk file in the datastore.

This should be all you need to know to Clone a Virtual Machine from the Command Line Using ESXi.

 


unixsamurai.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com. Read our Privacy Policy for more info.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.