Cloning Individual Virtual Machine Disks via vMA and vCLI
search cancel

Cloning Individual Virtual Machine Disks via vMA and vCLI

book

Article ID: 310650

calendar_today

Updated On:

Products

VMware vCenter Server VMware vSphere ESXi

Issue/Introduction

This article provides basic instructions for cloning individual virtual machine disk files using the VMware vSphere Management Assistant (vMA) and the vSphere CLI (vCLI).

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.

Symptoms:



Environment

VMware vCenter Server 4.0.x
VMware vSphere ESXi 5.0
VMware ESX Server 3.5.x
VMware ESXi 4.0.x Installable
VMware vSphere ESXi 5.5
VMware vSphere CLI 4.0
VMware ESXi 4.0.x Embedded
VMware ESXi 4.1.x Embedded
VMware vSphere Management Assistant 5.1
VMware VirtualCenter 2.5.x
VMware ESXi 3.5.x Installable
VMware vSphere Management Assistant 5.5
VMware ESXi 4.1.x Installable
VMware ESX 4.1.x
VMware ESX 4.0.x
VMware vCenter Server 4.1.x
VMware vSphere ESXi 5.1
VMware ESXi 3.5.x Embedded
VMware vSphere Management Assistant 4.0.x

Resolution

Note: The virtual machine does not need to be powered off for these operations.

Cloning a virtual machine disk without delta files or snapshots

To clone a virtual machine disk using the vMA or vCLI:
  1. Start the vMA and log in. If this is your first time starting the appliance, complete the setup process. Proceed to the next step if you are using the vCLI.
  2. Run the following command to list the affected virtual machine's directory content, similar to the following image:



    vifs --server -D '[Datastore Name] examplevm'

  3. Determine what datastore you will be cloning the virtual disk in question to. Refer to the reports provided by your VMware vSphere or Infrastructure client for capacity and usage information of your datastores. You will require enough space at the destination for a clone of the virtual machine's base disk.

  4. Create a new destination directory, if it does not exist already:



    vifs --server -M '[Datastore Name] Example Directory'

    Verify the created directory (e.g. 'Example Directory') exists:



    vifs --server -D '[Datastore Name]'

  5. Run the following command to clone the virtual machine disk. Specify the descriptor file, as opposed to the flat.vmdk extent file:



    vmkfstools --server -i '[Datastore Name] examplevm/examplevm.vmdk' '[Datastore Name] Example Directory/examplevm-clone.vmdk'

    Note
    : A progress indicator is not displayed for this task in the vMA or vCLI. When the task is complete, you will be returned to the prompt.

    You may review the results using: vifs --server -D '[Datastore Name] Example Directory'

  6. Repeat the clone process for each additional virtual machine disk, if necessary.

  7. Add the cloned virtual machine disk to a virtual machine's hardware configuration to access its stored content.

Cloning a virtual machine disk with delta files or snapshots

To clone a snapshotted virtual machine disk using the vMA or vCLI:
  1. Start the vMA and log in. If this is your first time starting the appliance, complete the setup process. Proceed to the next step if you are using the vCLI.
  2. Run the following command to list the affected virtual machine's directory content, similar to the following image:



    vifs --server -D '[Datastore Name] Example Directory'

    Note: The virtual machine examplevm, in this case, has three snapshots or delta disks, based on the existence of examplevm-000001.vmdk, examplevm-000002.vmdk, and examplevm-000003.vmdk files. If this virtual machine had additional virtual hard disks, there would be an additional three snapshots for each disk.

  3. Determine what datastore you will be cloning the virtual disk in question to. Refer to the reports provided by your VMware vSphere or Infrastructure client for capacity and usage information of your datastores. You will require enough space for a clone of the virtual machine's base disk. For example, examplevm.vmdk is 20GB, where the three snapshots are approximately 10GB each. The destination only requires 20GB of free space.

  4. Create a new destination directory, if it does not exist already:



    vifs --server -M '[Datastore Name] Example Directory'

    Verify the created directory exists:



    vifs --server -D '[Datastore Name]'

  5. Run the following command to consolidate the delta disk and its parent files into a single destination file. Specify the descriptor file, as opposed to the delta.vmdk extent file:



    vmkfstools --server -i '[Datastore Name] examplevm/examplevm-000003.vmdk' '[Datastore Name] Example Directory/examplevm_consolidated.vmdk'

    Note
    : A progress indicator is not displayed for this task in the vMA or vCLI. When the task is complete, you will be returned to the prompt.

  6. Repeat the clone process for each additional snapshotted virtual machine machine disk, if necessary. For example if you have consolidated a sizable amount of delta information and no longer require additional space to consolidate the other virtual hard disks, you may consider further clones may not be necessary.

  7. Modify the virtual machine's configuration and remove the virtual hard disk that was just cloned.

    Note: Remove the disk from the virtual machine's configuration, as opposed to removing it and deleting the files from the datastore. These options are presented to you upon removal, on the right-side of the configuration applet.

  8. Add the cloned virtual machine disk to the virtual machine's configuration.

    1. Select the virtual machine and click Edit Settings.
    2. Select the Add... button above the virtual hardware list.
    3. Select Hard Disk and Use an existing virtual disk in the following step.
    4. Complete the remainder of the wizard, locating the destination datastore and disk that you have consolidated into, or cloned, in step 5.
    5. After completing the wizard, confirm that the appropriate SCSI Controller type is selected, then finalize and apply the configuration by clicking OK.

  9. Confirm you have sufficient space to start the virtual machine. For more information, see: Verifying sufficient free disk space for an ESX/ESXi virtual machine (1003755). Start the virtual machine and verify the guest operating system and contained file systems are healthy.

    In the event that you see noticeable file system damage, corruption, or appears out of date, review the steps provided in this article and ensure:
  • You have referenced the correct virtual machine snapshot or delta point to clone from.
  • You have selected the cloned disk to boot with, as opposed to the original virtual machine base disk, or otherwise.
Otherwise it may be possible that the delta disk point referenced is corrupt and you must revert to an earlier snapshot point. You may accomplish this by:
  1. Removing the cloned virtual disk from the virtual machine configuration (and opting to delete the disk from the datastore)
  2. Then create a new disk clone from examplevm-000002.vmdk, an earlier snapshot point than examplevm-000003.vmdk, to the datastore.
  3. Add the newly created clone to the virtual machine's configuration.
  4. Rename the virtual machine's snapshot database file. We have altered the snapshot layout for the virtual machine by replacing disks in the configuration and it is now invalid:

    vifs --server 10.21.49.14 -m '[Storage1 (3)] examplevm/examplevm.vmsd' '[Storage1 (3)] examplevm/examplevm.vmsd.old'

  5. Finally, verify that the virtual machine guest operating system starts successfully.
If the virtual machine starts and the guest file systems appear intact, remove the old virtual machine disk files, per the Additional Information section of the following article: Consolidating snapshots (1007849).

Additional Information

For more information on vMA and vCLI, see: For more information on snapshot consolidation, see Consolidating snapshots in ESX/ESXi 3.x and 4.x (1007849).Consolidating snapshots in ESX/ESXi 3.x and 4.x
通过 vMA 和 vCLI 克隆单个虚拟机磁盘
vMA および vCLI による個々の仮想マシン ディスクのクローン作成