top of page
  • Mark

Copying a VM between 2 x ESXi Hosts

Updated: Mar 30


Why would i want to do this?


You may need to do this if you are working with standalone ESXi hosts with no vCenter, or if you just like playing around in your Homelab. Figuring out how to solve such problems, extends your knowledge of ESXi, which can help you in future scenarios.


In this case, I wanted to move some VMs from my old Lab on a NUC running Free ESXi, to my new Lab which is running on a separate ESXi host. Both labs are running on the same private subnet range (192.168.68.x) so networking is straightforward. I looked online and there are probably a dozen ways you can do this, with people mentioning all sorts of methods and 3rd party tools. The reality is you don't need any 3rd tools, in this guide, we're going to keep things simple, and use the tools already built into ESXi to do this, specifically the SCP command. We can use this to copy the VM directly from the source ESXi host to the destination ESXi host, then just power the VM on at the other end. Let's do this!


Pre-requisites

  • First of all, the VM you are going to copy MUST be powered off.

  • Secondly, the following assumes a some knowledge of Linux commands, but if you havn't used Linux before, it isn't a complicated process, and hopefully i've covered the steps in enough detail to follow along


Log into the Source ESXi Host

  • Connect via SSH to your source host. From a windows machine you can use Putty, or if you have a recent version of Windows 10/11 you can use SSH directly from the command prompt. Personally i prefer Putty as it maintains a kind of separation, plus with the MTPutty wrapper you can have multi-tabbed SSH sessions.

    • Note you may need to start the SSH service on the ESXi host if it isn't already running, as this service is disabled by default.

  • Once logged into the host, use the following 2 commands to "change directory" to your volumes location, and then list the contents

cd /vmfs/volumes
ls -l 

In the above screenshot, the Capacity SSD is where i have the VMs stored on my NUC (your VM folder location will obviously be different, so amend as required), so lets take a look in there. Note you can use the Tab key to autocomplete the path (which i used here, hence the slashes in the path below). I then used ls -l to list the contents


In this example, you can see i have 4 VMs on my NUC. 3 are nested ESXi hosts and there is also a DNS VM. The DNS VM (basically an Ubuntu VM I built for (yep you guess it - dns!) is the VM we are going to copy.


Check the Destination Host

Now lets SSH to my new host using the same commands to determine the destination path. Here you can see in my new lab, I have a couple of Synology Datastores mounted (via iSCSI). VM04 is going to be our destination



First attempt to copy the files

Now we have our source and destination paths, we can run the command to begin the copy (note we are running the command from the source host). The command looks like this:

scp -rv dns root@192.168.68.71:/vmfs/volumes/VM04-Synology/

Note the 'v' switch is for verbose output. I have included it here for reference, but i'm going to drop it after this point, as generates simpler output for the screenshots.


So now lets run the command......


As you can probably guess, by this section being called "first" attempt, the command eventually failed with a timeout error.


 I quickly traced this to a firewall issue, which needed a bit more configuring.


Enable SSH Outbound Firewall Rule on ESXi

after a bit of digging around, I realized that whilst SSH "inbound" was allowed, SSH "outbound" was blocked, and i need to enable it. To do this, log into the Web client for your ESXi host, then navigate to Networking > Firewall Rules. Then scroll down the list and locate the SSH Client and SSH Server rules as shown in the screenshot below


If you look closely you will see the SSH Server (inbound) rule is black in colour. This means it is enabled. Whereas the SSH Client (outbound) rule is grey in colour, meaning it is disabled.



Highlight the SSH Client Rule > Click Actions > and click enable. This will fix our problem


Second (and working) attempt to copy the VM from source to host

Now lets try that command again (note i have dropped the 'v' from the scp command now.

scp -r dns root@192.168.68.71:/vmfs/volumes/VM04-Synology/

Bingo, now we have enabled the SSH outbound rule, I get an SSH login prompt!


Next, type yes to accept the connection and enter the password for root when prompted. From there you will see scp start to copy the files :-). Note the progress section at bottom right.


You can now switch back to your destination host, cd to the Synology 04 volume, and we can see the VM folder for dns has appeared. You can then cd into that and check the files.


Fast forwarding to the end of the copy process, here's the last few VM files being copied and the SCP copy job completes. Incidentally ignore the slow transfer speeds, I was temporarily running this over wi-fi whilst moving between labs. On a 1 Gbps interface, expect to see anything up to 125 MB/s (if you have no other traffic flowing over the ports)


Checking the copied VM on the target host


From the Web UI of your target host, go to Storage.


Here i locate VM04-Synology, right click and select Browse


This opens up the Datastore browser. I can see the "dns" VM that we just copied. Drill down and locate the dns.vmx file, right click that and select Register VM



Now i'm going to switch to my vCenter (the principle is the same on a standalone host). You can see below that vCenter has detected that i have registered the VM on ESX01, and has added it to the inventory. I have also just powered it on.


  • Note when powering on, you will see a message asking if you moved or copied the VM, select "I copied it". All this does is create a unique UUID and MAC just to ensure there are no conflicts.


Here is the VM now running (as shown from within my vCenter, but as above, the principle is the same on a standalone ESXi host). Note that i had the standard VM network configured on my old and new Labs and the subnet is the same so no additional networking changes were required and i could ping and access the VM immediately.



So there you go, that's how to easily copy a VM between 2 ESXi hosts. Easy huh! :-)


If this helped you, let me know in the comments below.


50 views0 comments

Recent Posts

See All

Why core count is so important under Broadcom

In the new Broadcom licensing model, you must license a minimum of 16 cores per socket, then additionally, license every core above that number. Therefore it seems clear that switching to 16 core proc

The end of VMware Hypervisor free edition

For as long as i can remember, there has been a free version of VMware's ESXi Hypervisor, simply branded as VMware Hypervisor Free Edition. Each version of ESXi introduced a new version of the Free Ed

Comments


bottom of page