Moving or copying virtual disks in a VMware environment
search cancel

Moving or copying virtual disks in a VMware environment

book

Article ID: 340156

calendar_today

Updated On:

Products

VMware VMware Desktop Hypervisor VMware vSphere ESXi

Issue/Introduction

In certain circumstances you may want to relocate specific virtual machine disk files from one location to another location. These circumstances may include, but are not limited to:
  • Moving a virtual machine disk from a platform using one VMware product to a different platform using another VMware product.
  • Troubleshooting issues involving high disk space usage.
  • Balancing disk space usage.
  • Cloning a virtual machine.
  • Backing up a virtual machine.
This article explores and describes different methods of relocating virtual machine files within your VMware Environment.

Resolution

Existing VMware products and features

To support certain internal operations, ESX installations include a subset of standard Linux configuration commands, for example, network and storage configuration commands. Using these commands to perform configuration tasks can result in serious configuration conflicts and render some ESX functions unusable. Always work through the vSphere Client when configuring ESX unless otherwise instructed in vSphere documentation or by VMware Technical Support.

Prior to manually moving or copying virtual machine disk files, consider using existing VMware features which can accomplish similar desired results. These VMware features include:

  • Converting virtual machines with VMware Converter.
  • Live Migrate, Cold Migrate, Clone, or Storage vMotion with VMware vCenter or VMware VirtualCenter.

Considerations and caveats

There are several caveats specific to moving or relocating virtual machine disk files:

  • Different versions of VMware products may have different implementations of a virtual disk file.
  • When using snapshots, a virtual machine's virtual disks can be comprised of multiple VMDK files which are part of an interdependent chain.
  • To prevent performance and data management related issues on ESX, avoid the use of scp, cp, or mv for storage operations. Instead use the vmkfstools utility, the Virtual Machine Importer tool from VMware.

Prior to copying virtual machine files

To avoid any potential issues involving snapshots and inconsistent disk chains, you must ensure that the virtual machine does not have any snapshots. Moving virtual machines with snapshots is outside of the scope of this article, and VMware strongly recommends using one of the alternate methods described above. Also, you must know exactly where the virtual disk file we want to move is located as well as ensure that the virtual machine is powered off.

These steps outline what to do prior to performing an operation with virtual disks from the vSphere/VI Client connected to either vCenter Server or ESX:

  1. Connect to the ESX host using the vSphere/VI Client with administrator credentials.
  2. Ensure that the virtual machine that uses the virtual disk file does not have any snapshots by right-clicking the virtual machine and clicking Snapshot > Snapshot Manager.
  3. Make note of the datastore and location of the virtual disk files that you want to copy by right-clicking the virtual machine and clicking Edit Settings. Click on the virtual disk and refer to the Disk File portion of the Virtual Machine Properties.
  4. Power off the virtual machine.

    Note: If there is no virtual machines to receive the virtual disk files, you may want to create the virtual machine in advance to establish the destination of the move or copy operation.

These steps outline what should be done prior to performing an operation with virtual disks from VMware Workstation:

  1. Open VMware Workstation, and click on the virtual machine which has the virtual disk you wish to conduct an operation on.
  2. Click VM > Snapshot > Snapshot Manager, and remove any preexisting snapshots.
  3. Click VM > Settings > Options Tab and make note of the Working Directory section on the bottom left of the Virtual Machine Settings window.
  4. Click VM > Power > Shut Down Guest to power off the virtual machine.

    Note: If there is no virtual machine to receive the virtual disk files, you may want to create the virtual machine in advance to establish the destination of the move or copy operation.

If you want to commit snapshots via the ESX service console, see Committing snapshots from within the Service Console (1006847).

Copying virtual disk files using the ESX service console

  1. Log into the ESX host as root using either a remote console or SSH. For information on how to enable SSH, see Enabling root SSH login on an ESX host (8375637).
  2. In the event that the virtual machine which is using the virtual disk is using snapshots, you must consolidate those snapshots prior to performing any storage operations.
  3. Run the vmware-cmd -l command to list all full paths to the configuration (.vmx) files of the virtual machines registered to this host.

    Example output:

    /vmfs/volumes/********-********-****-**********/VMtest/VMtest.vmx

    Note: The full path of the configuration file is identified by <cfg> for the rest of this article.
     
  4. Run the vmware-cmd <cfg> stop command to shut down the desired virtual machine.
  5. Run the grep -i vmdk <cfg> command to list all virtual disk files associated with the virtual machine.

    Example output:

    scsi0:0.fileName = "VMtest.vmdk"
    scsi0:0.fileName = "/vmfs/volumes/********-********-****-**********/VMtest_1.vmdk"


    Note: These entries may not include the full path to the directory. If a full path is not listed, refer to the full path of the <cfg> value. The full path of the source virtual disk will be identified by <src> for the rest of the article.

    Warning: If the file name ends with -#######.vmdk, your virtual machine is still running off of a snapshot. If you find that these files are present, but you do not have any snapshots in the snapshot manager, see Committing snapshots when there are no snapshot entries in the snapshot manager (1002310).
     
  6. Run the command:

    vmkfstools -i <src> <dst>
    Where <dst> is the destination where you would like the file to be copied.

    For more information, see Cloning and converting virtual machine disks with vmkfstools (1028042)

Copying virtual disk files using the vSphere Command Line Interface for ESX and ESXi

Unlike ESX, ESXi does not have a service console. To copy files, use the vifs utility that comes with the vSphere Command Line Interface. The vifs command performs common operations such as copy, remove, get (download), and put (upload) files. The command is supported against ESXi/ESX hosts but not against vCenter Server systems. Use the vifs command to perform the file operation on the virtual machine files.

Copying virtual disk files using the vSphere/VI Client datastore browser for ESX and ESXi

The datastore browser allows you to manage the contents of datastores in the vSphere/VI Client inventory. You can use the datastore browser to do these tasks:

  • View or search the contents of a datastore.
  • Add a virtual machine or template stored on a datastore to the vSphere/VI Client inventory.
  • Copy or move files from one location to another, including to another datastore.
  • Upload a file from the client computer to a datastore.
  • Download a file from a datastore to the client computer.
  • Delete or rename files on a datastore.

The datastore browser operates in a manner similar to file system applications like Windows Explorer. It supports many common file system operations, including copying, cutting, and pasting files. The datastore browser does not support drag-and-drop operations. For detailed instructions on using the datastore browser, see the vSphere/VI Client online help.

Copying virtual disk files using a web browser for ESX and ESXi

ESX and ESXi servers have a built-in web service which allows you to access files via a web browser. Although this method of copying files is only one-way and does not allow you to upload files, it may be a good alternative in certain situations. To access these files:

  1. Open a web browser.
  2. Access this URL:

    http://host_IP_address/folder

    Where host_IP_address is the IP or DNS name of the ESX host.
     
  3. Enter the appropriate credentials when prompted.
  4. Click the ha-datacenter link.
  5. Browse to and download the desired virtual disk file.

    Note: When using the browser to move and copy virtual disk files in ESX, you must copy both the flat file and the descriptor file. For example, if a virtual machine disk is named disk.vmdk, it would have a corresponding disk-flat.vmdk file which must be copied or moved as well.

Copying virtual disk files to and from VMware Server or a VMware desktop product

VMware desktop products such as VMware Workstation and VMware ACE include the VMware Virtual Disk Manager utility. These are some usage examples of the VMware Virtual Disk Manager utility:

vmware-vdiskmanager -n mydisk.vmdk "..\another_path\myNewDisk.vmdk"

vmware-vdiskmanager -n mydisk.vmdk "..\another_path\mydisk.vmdk"


Copying virtual disk files across the network to and from different platforms

Moving virtual disk files across a network can be accomplished in many ways and on many platforms. These options exist to transport files to different platforms:

  • FTP file transfer
  • SCP file transfer
  • NFS shares
  • Windows File Sharing (CIFS shares)

Steps on how to enable, configure, and transfer files using these specific methods are outside of the scope of this article. When transferring virtual disk files across the network, VMware recommends validating the information before and after the file transfer. This can be done by using MD5 checksums.