The
vmkfstools command offers the ability to clone virtual machine content and also convert from one virtual machine disk
(.vmdk) format into another.
Note: The host operating system chosen to perform the conversion may not necessarily support running of virtual machines via the output format defined.
vmkfstools maintains the possibility of exporting virtual disks for use in other VMware products which support alternative disk formats.
To convert a virtual machine disk from one type to another:
- Shut down the virtual machine. Virtual machine disk files are locked while in-use by a running virtual machine.
- Log in to the VMware vSphere Management Assistant (vMA). Alternatively, open a command-line interface after deploying the VMware vSphere CLI (vCLI). If terminal access is required:
- Run these vmkfstools command to clone the disk from one format to another:
From the ESX/ESXi terminal:
vmkfstools -i input output -d format -a adaptertype
From vMA/vCLI:
vmkfstools --server <vCenter or ESX IP/Hostname> -i input output -d format -a adaptertype
For example, to clone examplevm.vmdk from Datastore to Datastore 2 and thin-provision the destination copy:
From the ESX/ESXi terminal:
vmkfstools -i "/vmfs/volumes/Datastore/examplevm/examplevm.vmdk" "/vmfs/volumes/Datastore 2/newexamplevm/newexamplevm.vmdk" -d thin -a buslogic
From vMA/vCLI:
vmkfstools --server 10.21.49.14 -i '[Datastore] examplevm/examplevm.vmdk' '[Datastore 2] newexamplevm/newexamplevm.vmdk' -d thin -a buslogic
Note: For VMs that reside on vSAN make sure to add -W vsan
Note: Ensure the new destination directory is created prior to cloning the disks.
Warning: If virtual machine snapshots or delta disks are present, ensure that the source chosen is the current snapshot delta disk. Failing to do so results in an outdated destination copy. However, when using the command, the corresponding descriptor file for the latest delta disk needs to be used when cloning the disk.
For example to clone and/or convert virtual machine disk with snapshot (otherwise known as a delta disk), examplevm-000001.vmdk and like above, from Datastore to Datastore 2 , with a thin-provisioned destination copy, run these command:
From the ESX/ESXi terminal:
vmkfstools -i "/vmfs/volumes/Datastore/examplevm/examplevm-000001.vmdk" "/vmfs/volumes/Datastore 2/newexamplevm/newexamplevm.vmdk" -d thin -a buslogic
From vMA/vCLI:
vmkfstools --server 10.21.49.14 -i '[Datastore] examplevm/examplevm-000001.vmdk' '[Datastore 2] newexamplevm/newexamplevm.vmdk' -d thin -a buslogic
Note the selection of examplevm-000001.vmdk , as opposed to examplevm.vmdk for the input file. Snapshot delta disk files are appended a sequencing number, differentiating one snapshot delta disk iteration or level from another. Selecting the most recent delta disk ensures that the most recently stored data is cloned to the destination.
Note: Running the vmkfstools -i command creates a cloned drive with an LSI controller, even if the source disk is using VMware Paravirtual. This results in the virtual machine failing to boot. To resolve this issue, change the controller type to the same as the source.
For more information on steps to identify a virtual machine's current snapshot, see Confirming a virtual machine's snapshot delta disk layout (1027887).
Note: This process only clones the disk that was specified in the command. To register the newly cloned disk / VM into inventory, it requires a .vmx file. Manually copy the .vmx from the cloned VM and adjust the .vmx file to provide the path to the newly cloned disks or create a new VM from the UI and select the cloned disks in the Hard Disk section.