Knowledge Base

The VMware Knowledge Base provides support solutions, error messages and troubleshooting guides
 
Search the VMware Knowledge Base (KB)   View by Article ID
 

Cloning individual virtual machine disks via the ESX/ESXi host terminal (1027876)

Purpose

This article provides instructions on how to clone individual virtual machine disks via ESX/ESXi host's terminal.

Note: The context of the instructions will change depending on whether the virtual machine has existing snapshots or not. If the virtual machine has snapshots or delta disks, refer to the appropriate instructions included below. Both scenarios are covered in this article.

Resolution

Cloning a virtual machine disk without delta files or snapshots

To clone a virtual machine disk using the ESX/ESXi host terminal:
  1. Log into the ESX/ESXi host's terminal.

  2. Navigate to the virtual machine's directory using the cd command. It is located at:

    /vmfs/volumes/source_datastore/virtual_machine/

  3. Confirm the destination directory where the clone will be copied to. Create this directory, if required.

    For example, if this destination directory does not exist:

    /vmfs/volumes/destination_datastore/virtual_machine/

    Create the directory using this command:

    mkdir /vmfs/volumes/destination_datastore/virtual_machine/

  4. Clone the virtual hard disk using the vmkfstools -i command after shutting down the virtual machine:

    # vmkfstools -i "/vmfs/volumes/Storage1 (3)/examplevm/examplevm.vmdk" /vmfs/volumes/Storage2/examplevm_clone.vmdk

    Notes:
    • Encapsulate objects with quotes where appropriate to ensure spaces and other special characters are interpreted correctly.
    • By default, the vmkfstools -i command will create a destination thick provisioned disk. If you would like the destination disk to be thin provisioned, add -d thin to the end of the above command.

    The output appears similar to:

    Destination disk format: VMFS thick
    Cloning disk '/vmfs/volumes/Storage1 (3)/examplevm/examplevm.vmdk'...
    Clone: 100% done.

Cloning a virtual machine disk with delta files or snapshots

To clone a virtual machine disk using the ESX/ESXi host terminal:
  1. Log into the ESX/ESXi host's terminal.

  2. Navigate to the virtual machine's directory using the cd command. It is located at:

    /vmfs/volumes/source_datastore/virtual_machine/

  3. Confirm the destination directory where the clone will be copied to. Create this directory, if required.

    For example, if this destination directory does not exist:

    /vmfs/volumes/destination_datastore/virtual_machine/

    Create the directory using this command:

    mkdir /vmfs/volumes/destination_datastore/virtual_machine/

  4. Clone the virtual hard disk from its current snapshot delta point using the vmkfstools -i command.

    # vmkfstools -i /vmfs/volumes/Storage1 (3)/examplevm/examplevm-000003.vmdk /vmfs/volumes/Storage2/examplevm_clone.vmdk

    The output appears similar to:

    Destination disk format: VMFS thick
    Cloning disk '/vmfs/volumes/Storage1 (3)/examplevm/examplevm-000003.vmdk'...
    Clone: 100% done.


    Note: If the process fails, try selecting the next snapshot delta point in the snapshot tree; the selected point or one of its parents may be corrupt.

Additional Information

Additional steps for virtual machine disks with delta files or snapshots

The original virtual machine files are still intact without modifications. You may opt to either create a new virtual machine and attach the cloned disk file(s), or replace the existing disks attached to the virtual machine with the cloned copies. The following steps encompass the latter option.

To replace the original virtual machine disk(s) and delta snapshot file(s) with the cloned copy or copies:
  1. Detach the virtual hard disk from the virtual machine's configuration in the VMware vSphere or Infrastructure Client.

  2. Attach the new (cloned) virtual hard disk, /vmfs/volumes/Storage2/examplevm_clone.vmdk to the virtual machine.

  3. Rename the snapshot database (.vmsd) file for the virtual machine. At this time it is no longer valid due to manipulation of the virtual machine's disk layout during troubleshooting:

    # mv examplevm.vmsd examplevm.vmsd.old

  4. Power on the virtual machine and confirm the guest operating system can boot successfully. Verify data integrity and confirm data is not missing or corrupt.

  5. With the virtual machine still powered-on, you may remove the original disk files to free datastore space. Files in use by the powered-on virtual machine cannot be removed by the VMware ESX server. This can be used as a safeguard.

Related information

For snapshot delta file cleanup procedures and other related information, see the Additional Information section of Consolidating snapshots (1007849).

For more information on vmkfstools in this context, see Cloning and converting virtual machine disks with vmkfstools (1028042).

See Also

Update History

01/23/2012 - Added ESXi 5.0 to Products 07/25/2012 - Added link to 1028042

Request a Product Feature

To request a new product feature or to provide feedback on a VMware product, please visit the Request a Product Feature page.

Feedback

  • 9 Ratings

Did this article help you?
This article resolved my issue.
This article did not resolve my issue.
This article helped but additional information was required to resolve my issue.
What can we do to improve this information? (4000 or fewer characters)
  • 9 Ratings
Actions
KB: