VMware SCP between hosts

From Doge Microsystems
Jump to navigation Jump to search

Directly copying VMs between two VMware ESXi hosts is a simple way to migrate VMs if you don't have vSphere or the hosts are managed by different instances.

Enable SSH Service on ESX

To enable the SSH service, log in to the web interfaces for your ESX servers. Then click on Host at the top right. Click Actions then Services then make sure Enable Secure Shell (SSH) is enabled.

Enabling outbound SSH

By default outbound SSH connections are disabled but can be turned on from the ESX CLI.

Connect to the ESX server via ssh then check if the sshClient is enabled with this command:

esxcli network firewall ruleset list --ruleset-id sshClient

If the output shows false then access is not enabled:

Name       Enabled
---------  -------
sshClient    false

To enable the sshClient run the following command:

esxcli network firewall ruleset set --ruleset-id sshClient --enabled=true

Copying a VM with SCP

Log into the source ESX server via SSH and navigate to the datastore in /vmfs/volumes/ using the cd command.

Copy the VM to the destination host using scp. Substitute the source VM's folder name, the IP/host of the destination ESX server, and the datastore name.

scp -r MyVMname root@ipOfDestHost:/vmfs/volumes/datastore-name/

Converting to thin provisioning

The copying process will result in a 'thick' provisioned virtual disk that takes the full size on datastore.

To convert to a thin provisioned disk do the following:

  1. SSH into the ESX host
  2. Use cd to go to the VM's directory in the datastore in /vmfs/volumes/datastorename/vmname
  3. Convert the VMDK file to thin: vmkfstools -i VM_NAME.vmdk -d thin VM_NAME-thin.vmdk
  4. Delete the old disk with rm VM_NAME.vmdk
  5. Rename the thin VMDK to the old name mv VM_NAME-thin.vmdk VM_NAME.vmdk

Registering the VM

Browse the datastore on the destination ESX server and find the VMX file for the VM in question. Import it. When the VM powers up for the first time select the option for "I Moved it" to keep the same NIC MAC addresses.