Migrate VMs in ESXi free version

ESXi free version is a great hypervisor for tests and labs, however it lacks some of the key features provided by VMWare's commercial products.

In a free ESXi version, one can use the CLI to move VMs from one datastore to aother.
First check on which datastore your VM resides. Let's say it's the PCLinuxOS VM.

The VM is located on this datastore:


I want to move it from LOCAL_DRIVE to thinlun.

~ # df

Filesystem         Bytes         Used     Available Use% Mounted on

VMFS-5     2000112582656 947863420928 1052249161728  47% /vmfs/volumes/LOCAL_DRIVE

VMFS-5      250718715904 111992111104  138726604800  45% /vmfs/volumes/datastore1

VMFS-5     2198754820096  50019172352 2148735647744   2% /vmfs/volumes/thinlun

VMFS-5     2198754820096   3220176896 2195534643200   0% /vmfs/volumes/thicklun

vfat          4293591040     31391744    4262199296   1% /vmfs/volumes/553a44c8-786ee042-fc48-001e6745c659

vfat           261853184    165023744      96829440  63% /vmfs/volumes/759c3174-ce030377-9a1b-6d92b0825c53

vfat           261853184         8192     261844992   0% /vmfs/volumes/9f31c873-8e055259-44a8-1b74b787e284

vfat           299712512    202776576      96935936  68% /vmfs/volumes/553a44bd-bd86678e-2832-001e6745c659

1. Move the folder containing the VM to the new datastore:

~ # mv /vmfs/volumes/LOCAL_DRIVE/pclinuxos /vmfs/volumes/thinlun/

2. When this operation is complete, remove the VM from inventory using the vShpere client:

Right click on the VM, "remove from inventory"

3. Edit the vmx file to reflect the VMs location has changed:

~ # cd /vmfs/volumes/thinlun/pclinuxos/

/vmfs/volumes/56d0f011-96144ad8-9d8c-001e6745c659/pclinuxos # vi pclinuxos.vmx

Look for the entry containing the old datastore's location.

sched.swap.derivedName = "/vmfs/volumes/56d0f011-96144ad8-9d8c-001e6745c659/pclinuxos/pclinuxos-4eff615b.vswp"

Edit this entry to reflect the new datastore ID.

4. Register the VM and power on.

Go to the vSphere client and browse the VMs folder in the new datastore, right click on the vmx file and add to inventory.

After this step, you can power on the VM.