Copying or moving the virtual machine and virtual disks
The information below has been replicated from kb.vmware.com:
Follow these high-level steps to move a virtual machine to an alternate location:
- Select the virtual machine.
- Commit all snapshots on the virtual machine. For more information, see Committing snapshots from within the Service Console (1006847).
- Identify the working directory of the virtual machine.
- Identify the location of all virtual disks.
- Power off the virtual machine.
- Create a folder for the copy of the virtual machine.
- Copy the virtual machine configuration file ( .vmx) to the new folder.
- Copy the virtual disks to the new folder. For more information, see Moving or Copying Virtual Disks in a VMware Environment (900).
- Register the new virtual machine.
- Add the virtual disk copies to the virtual machine copy.
- Upgrade the virtual hardware if necessary.
- Power on the virtual machine.
- Test the new virtual machine.
- Optionally, delete the original virtual machine files.
Step 8 above:
Copying virtual disk files using the ESX service console
- Log into the ESX host as root using either a remote console or SSH. For details on how to enable SSH, see Enabling root SSH login on an ESX host (8375637).
- In the event that the virtual machine which is using the virtual disk is using snapshots, you must consolidate those snapshot prior to performing any storage operations.
- Run the command vmware-cmd -l command to list all full paths to the configuration (vmx) files of the virtual machines registered to this host.
Note: The full path of the configuration file is identified by <cfg> for the rest of this article.
- Run the vmware-cmd <cfg> stop command to shut down the desired virtual machine.
- Run the grep -i vmdk <cfg> command to list all virtual disk files associated with the virtual machine.
scsi0:0.fileName = "VMtest.vmdk"
scsi0:0.fileName = "/vmfs/volumes/478e0d5b-3535f6a8-0ee2-0017a446ae31/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, then 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).
- Run vmkfstools -i <src> <dst> where <dst> is the destination of where you would like to file to be copied.
Note: Syntax from older versions of ESX may vary. For ESX 2.5.X. see Examples of Using vmkfstools from the ESX 2.5.X documentation.
[root@esxhost ~]# mkdir /vmfs/volumes/EMM/emmruby.int.copy
[root@esxhost ~]# cd /vmfs/volumes/EMM/emmruby.int.com
[root@esxhost ~]# vmkfstools -i emmruby.int.com.vmdk -d thin ../emmruby.int.copy/emmruby.int.com.vmdk
[root@esxhost ~]# ls -lh /vmfs/volumes/EMM/emmruby.int.copy/
-rw------- 1 root root 146G Mar 15 15:29 emmruby.int.com-flat.vmdk
-rw------- 1 root root 560 Mar 15 15:29 emmruby.int.com.vmdk
-rwxr-xr-x 1 root root 2.9K Mar 15 15:36 emmruby.int.com.vmx
In the above example, I specified the disk format as thin:
SUPPORTED DISK FORMATS
These are the arguments that can be passed to the ´-d´ option for the ´-c´ (create virtual disk) and ´-i´ (clone virtual disk) operations.
Space required for the virtual disk is allocated at creation time.
Any data remaining on the physical device is not erased during
creation, but will be zeroed out on demand at a later time on
first write from the virtual machine. The virtual machine does not
read stale data from disk.
Space required for the virtual disk is allocated at creation
time. In contrast to zeroedthick format, the data remaining on
the physical device is zeroed out during creation. It might take
much longer to create disks in this format than to create other
types of disks.
Thin-provisioned virtual disk. Unlike the ´zeroedthick´ or
´eagerzeroedthick´ format, space required for the virtual disk is
not allocated during creation, but, it is allocated on demand during
first write issued to the block. Virtual disk size is zero at
creation time. This format provides more efficient user of storage
space and enables thin provisioning of virtual disks. This format is
recommended when space utilization is the main concern, and for all
types of applications except clustering.