Virtual machine cloning is a feature exclusive to vCenter Server but there is a workaround to this restriction . In this post, I will explain how to clone VMs on ESXi without vCenter Server using a vSphere client and shell commands.
Steps are very simple
First create a target VM with identical hardware and resources as assigned to the one you’re cloning ,source VM.
Copy the source VMDK files (disks) to the target VM’s folder.
Finally, attach the copied VMDKs to the target VM and verify that the clone boots up and works properly.
Note: If the VM being cloned includes snapshots, you must delete them first before using the cloning procedure here covered. Alternatively, try using vmksftools as per this KB.
Enable SSH on ESXi
Shell access is enabled from DCUI. Alternatively, you can start the TSM-SSH service using the embedded host client for recent releases of ESXi such as 6.5 or via the legacy vSphere client for older versions. PowerCLI is one more tool to Manage ESXi services .
Determine the datastore, folder and VMDK names
Obtaining this information should be easy, since a standalone ESXi, more often than not, comes with a single local datastore. Regardless, you can get the details using a vSphere client or PowerCLI.
Using the host client, pull the settings for the VM and expand Hard Disk taking note of the Disk File value as you do. The bit enclosed by the square brackets corresponds to the datastore where the VM files reside. The bit immediately following the datastore name, is the VM folder name; it could be the case that the VM has multiple disks residing on different datastores and folders as per the example listed below. Finally, take note of all the VMDK filenames.
The same details can also be obtained from the Hardware Configuration pane while the VM is selected.
If you wish to use PowerCLI, you can execute either of the one-liner statements next listed. Both will return a list all the datastores associated with a given VM. In the example given, I’ve targeted a VM called Windows 7 which has three VMDKs (disks) spread across two datastores.
>(get-vm ‘TEST-VM-01’).ExtensionData.config.datastoreURL |Format-List
At this point, you should have:
- The Datastore name for the VM.
- The VM folder name.
- A list of VMDK filenames corresponding to the VM’s disks.
Create the target VM
Create a target VM with identical hardware and resources as assigned to Source VM , Without HDD . Incase you added HDD over there delete that . And verify the resource details from Web client.
SSH to ESXi
Using an SSH client such as putty, log in ESXi as root and xopy the VMDKs from the source VM to the one created.
Note: The datastore, folder, and VMDK names will differ from those cited here for obvious reasons. Also the Source VM has to powered off
a. Navigate to the folder of the VM you want to be cloned. In this case, TEST-VM-01 is the virtual machine.
[root@esx-test-01:~] cd /vmfs/volumes/datastore1/
[root@esx-test-01:/vmfs/volumes/5a51f02a-1703aa74-950f-9c8e99143c88] ls
TEST-VM-01-CLONE TEST-VM-01
[root@esx-test-01:~] cd /vmfs/volumes/datastore1/TEST-VM-01/
b.Verify the File inside the VM and Copy
[root@esx-test-01:/vmfs/volumes/5a51f02a-1703aa74-950f-9c8e99143c88/TEST-VM-01] ls
TEST-VM-01-061a04e4.vswp TEST-VM-01.vmdk TEST-VM-01.vmx.lck vmware-2.log vmx-TEST-VM-01-102368484-1.vswp
TEST-VM-01-flat.vmdk TEST-VM-01.vmsd TEST-VM-01.vmx~ vmware-3.log
TEST-VM-01.nvram TEST-VM-01.vmx vmware-1.log vmware.log
c. Copy the source VMDK files to the folder of the VM previously created, TEST-VM-01-Clone in my case. We need to copy the VMDK files – both the descriptor and flat file .
[root@esx-test-01:/vmfs/volumes/5a51f02a-1703aa74-950f-9c8e99143c88/TEST-VM-01] cp TEST-VM-01.vm
TEST-VM-01.vmdk TEST-VM-01.vmsd TEST-VM-01.vmx TEST-VM-01.vmx.lck TEST-VM-01.vmx~
root@esx-test-01:/vmfs/volumes/5a51f02a-1703aa74-950f-9c8e99143c88/TEST-VM-01] cp TEST-VM-01-flat.vmdk /vmfs/volumes/datastore1/TEST-VM-01-CLONE/
Note :- You can Copy the File from Data store Folder by browsing
Attach the copied VMDK to the target VM
Now that we finished copying the VMDK(s) to the target VM’s folder, we need to them via the VM’s hardware settings. Before powering up the VM, make sure to disable the network card first. This allows us to change the networking configuration thus avoiding a potential IP conflict with the source VM.
To add the disk, I’ve used the ESXi host client as follows:
- Go to Edit Settings on the Cloned Virtual Machines
- Select the Add hard disk -> Exiting hard disk option
- Browse the the Copied VMDK file and Select
- Verify that disk has been added and select save option .
Note:- The Clone virtual machine will have only thick disk , if you want to convert to this follow KB
Now Power on the virtual Machine and You can see it is booting up .