Moving or copying a virtual machine within a VMware environment
search cancel

Moving or copying a virtual machine within a VMware environment

book

Article ID: 317919

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

In certain circumstances you may want to relocate a virtual machine from one location to another location. These circumstances may include, but are not limited to, the following:
  • Moving a virtual machine 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

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:

Considerations and Caveats

The following 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. For more information, see Disk Chaining and Redo Logs in the Virtual Disk API Programming Guide.
  • To prevent performance and data management related issues on ESX, avoid the use of using scp, cp, or mv for storage operations; instead use vmkfstools, VMware's virtual machine Importer tool. For more information regarding the usage of tools within the service console, see Third-Party Software in the Service Console.
  • To avoid any potential issues involving snapshots and inconsistent disk chains, 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.
  • You must know exactly where the virtual disk file you want to move is located, and you must ensure that the virtual machine is powered off.

Copying or moving the virtual machine and virtual disks

Follow these high-level steps to move a virtual machine to an alternate location:
  1. Select the virtual machine.
  2. Commit all snapshots on the virtual machine. For more information, see Committing snapshots from within the Service Console (1006847).
  3. Identify the working directory of the virtual machine.
  4. Identify the location of all virtual disks.
  5. Power off the virtual machine.
  6. Create a folder for the copy of the virtual machine.
  7. Copy the virtual machine configuration file ( .vmx) to the new folder.
  8. Copy the virtual disks to the new folder. For more information, see Moving or Copying Virtual Disks in a VMware Environment (900).
  9. Register the new virtual machine.
  10. Add the virtual disk copies to the virtual machine copy.
  11. Upgrade the virtual hardware if necessary.
  12. Power on the virtual machine.
  13. Test the new virtual machine.
  14. Optionally, delete the original virtual machine files.

Note: For more information about performing these general steps, see Commands for ESX and ESXi and Commands for VMware Server and VMware desktop products in this article.

Creating a new virtual machine and copying or moving the virtual disks

Creating a new virtual machine instead of copying the original virtual machine configuration file has advantages. By creating a new virtual machine, you do not have to create folders, upgrade the virtual machine hardware, or register a virtual machine.
 
Follow these high-level steps to recreate a virtual machine in an alternate location:
  1. Select the virtual machine.
  2. Make note of the networking, memory, and CPU configuration of the virtual machine.
  3. Commit all snapshots on the virtual machine. For more information, see Committing snapshots from within the Service Console (1006847).
  4. Identify the location of all virtual disks.
  5. Power off the virtual machine.
  6. Remove virtual disks.

    Warning: Do not delete the virtual disk.
  7. Create a new virtual machine and recreate the configuration identified in step 2.
  8. Copy the virtual disks to the folder of the new virtual machine.For more information, see Moving or Copying Virtual Disks in a VMware Environment (900).
  9. Add the virtual disk copies to the new virtual machine.
  10. Power on the new virtual machine.
  11. Test the new virtual machine.
  12. Optionally, delete the original virtual machine files.

Note: For more information about performing these general steps, see Commands for ESX and ESXi and Commands for VMware Server and VMware desktop products in this article.

Commands for ESX and ESXi

The steps to create a copy a virtual machine to a new location or recreate a virtual machine in an alternate location are different for ESX and ESXi.
 
For specific instructions to perform the following tasks, see the appropriate product documentation:
  • Power on the virtual machine
  • Power off the virtual machine
  • Remove virtual disks
  • Upgrade the virtual hardware
  • Adding virtual disks
Warning: In certain situations, you may want to run some of the above steps via the command line or service console. 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.
 
Registering a virtual machine
 
To register a virtual machine from the ESX Service Console, run the command:
vmware-cmd <cfg> register, where <cfg> is the full path to the vmx file
 
where <cfg> is the full path to the .vmx file
 
In Versions ESXi 4.1, 5.0, 5.1 and 5.5 vmware-cmd is no longer a valid command .vCLI (vSphere CLI) will have to be installed. Please see the following link for more information:
 
 
To register a virtual machine from ESXi and thevSphere CLI, run the command:
vmware-cmd.pl -H <host> -U <username> -P <password> <cfg> register

where <cfg> is the full path to the .vmx file
In ESXi 5.x, use this command to register the virtual machine:
vmware-cmd.pl -H <vc_server> -U <login_user -P <login_password --vihost <esx_host> -s register /vmfs/volumes/Storage2/testvm/testvm.vmx
Note: The system returns 0 to indicate success, 1 to indicate failure.
 
Identifying the working directory
 
To identify the working directory of the virtual machinefrom the ESX Service Console, run the command:
vmware-cmd -l
To identify the working directory of the virtual machinefrom ESXi and the vSphere CLI, run the command:
vmware-cmd.pl -H <host> -U <username> -P <password> -l
Identifying the location of all virtual disks
 
To identify the location of all virtual disks from the ESX Service Console, run the command:
grep -i vmdk <cfg>
 
where <cfg> is the full path to the vmx file
Creating a folder for the copy of the virtual machine
 
To create a folder for the copy of the virtual machine from the ESX Service Console, run the command:
mkdir /vmfs/volumes/<datastore>/<dir>

where <datastore> is the desired datastore, and <dir> is the desired directory name</dir></dir>
To create a folder for the copy of the virtual machine from ESXi and the vSphere CLI, run the command:
vifs.pl -H <host> -U <username> -P <password> --mkdir '[datastore] dir'

where datastore is the name of the datastore, and dir is the name of the new directory

Copying the virtual machine configuration file to the new folder

To copy the virtual machine configuration ( .vmx) file to the new folder from the ESX Service Console, run the command:
cp <source> <destination>
 
where <source> is the full path of the virtual machine configuration file, and <destination> is the desired location for the .vmx file.
To copy the virtual machine configuration file to the new folder from ESXi and the vSphere CLI, run the command:
vifs.pl -H <host> -U <username> -P <password> --copy '[src datastore] <src dir>/<vmx>' '[dst datastore] <dst dir>/<vmx>'
 
where:
  • src datastore and dst datastore are the source and destination datastores
  • <src dir> and <dst dir> are the source and destination directories
  • <vmx> is the name of the . vmx file
Notes:

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. Here are several options to transport files across 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. For more information about MD5 checksums, please see Using MD5 Checksums.
 
 
Additional Information:

For translated versions of this article, see: