This script utilizes VMware VIMA and the VI Perl Toolkit found in VMware VIMA.
ESXi is a formidable hypervisor solution in both licensed and free operation mode. When fully licensed in a Virtual Center cluster, ESXi's features (VMotion, HA, DRS, VCB, etc...) are indistinguishable from ESX. One feature of importance, VMotion, is used to perform live migrations of VMs that reside on shared storage from one host to another. In free operation mode however, ESXi hosts are independent of each other, in which case, useful features like VMotion become unusable.
The motivation for this script (ghettoQuickMigrate.sh) then is to provide administrators running the free version of ESXi on several hosts with the capability to perform Hyper-V-like "quick" migrations of virtual machines residing on shared storage between the hosts. VMware's VIMA virtual appliance was chosen as the central launch point for the quick migration process. ghettoQuickMigration.sh is executed from within VIMA and is compatible with ESXi 3.5u2+.
Excerpt from Hyper-V Quick Migration Document:
For a planned migration, quick migration saves the state of a running guest virtual machine (memory of original server to disk/shared storage), moves the storage connectivity from one physical server to another, and then restores the guest virtual machine onto the second server (disk/shared storage to memory on the new server). The speed of the migration depends on how much memory needs to be written to disk, and on the speed of the connectivity to storage; generally, migration takes just a few seconds.
This script follows similarly to the Hyper-V Quick Migration process with the exception of replacing the disk resource swap with a virtual machine unregister/register command on the source and target hosts respectively. The state (powered ON/Suspended/OFF) of the virtual machine designated for migration is preserved through the entire process. Online virtual machines undergoing this migration will experience a temporary pause due to the suspend and resume steps.
Like VMware's VMotion storage requirement, virtual machines in environments where this quick migration script is employed must reside on shared storage between source and target hosts. The script will provide a list of validated VMs that fit this criteria. Unlike VMware's VMotion CPU feature requirements, this script does not validate and enforce source and target CPU hardware compatibility. It is up to the user to ensure that virtual machines designated for migration are compatible with both the source and target host CPU features prior to execution of the script.
VMs running on ESXi 3.5u2+
VMware VIMA (virtual appliance)
ghettoQuickMigrate input parameters:
Usage: ./ghettoQuickMigrate.sh [-s SOURCE_ESX] [-d DESTINATION_ESX] [-i CONFIG_FILE_TO_OUTPUT] [-c CONFIG_FILE] OPTIONS: -s Source ESXi 3.5u2+ Server IP or Hostname -d Destination ESXi 3.5u2+ Server IP or Hostname -i Generate a configuration file -c Configuration file to be executed (e.g.) Generate configuration file ./ghettoQuickMigrate.sh -s himalaya.primp-industries.com -d olga.resnet.ucsb.edu -i migrationConf Execute configuration file ./ghettoQuickMigrate.sh -c migrationConf
Two default VMware VI Perl Toolkit scripts require a slight modification. On initial execution, this script (ghettoQuickMigrate.sh) will duplicate and modify the necessary lines of the two scripts. This operation will require the user to enter the password for their vi-admin account. Once entered, the following two scripts will be generated and stored in /usr/lib/vmware-viperl/apps/vm.
1) my-vmregister.pl
2) my-vmcontrol.pl
Prior to starting, ensure that the VMware VIMA host is managing the appropriate ESXi 3.5u2+ hosts (those that will be utilizing the ghettoQuickMigrate.sh script). The script uses VMware VI Fast Pass authentication to connect to the ESXi server(s). The following steps will demonstrate how to set this up prior to executing the script.
1. Add ESXi hosts to VIMA managment using vifp
A password prompt for the vi-admin account and root password to the pertinent ESXi host(s) will be presented.
[vi-admin@vima-primp-industries ~]$ sudo vifp addserver olga.resnet.ucsb.edu root@olga.resnet.ucsb.edu's password: [vi-admin@vima-primp-industries ~]$
2. Verify that the appropriate hosts are being managed by VIMA
[vi-admin@vima-primp-industries ~]$ sudo vifp listservers olga.resnet.ucsb.edu himalaya.primp-industries.com
3. Lastly, prior to running any of the RCLI or VI Perl Toolkits that utilize VI Fast Pass (not all can), run the following command on the appropriate ESXi host(s).
[vi-admin@vima-primp-industries ~]$ vifpinit olga.resnet.ucsb.edu
To remove a server from VIMA, use the argument “removeserver” on the host and provide the appropriate credentials.
Now, you're ready to begin!
1. Initial script preparation and VI Fast Pass authentication
[vi-admin@vima-primp-industries ~]$ ./ghettoQuickMigrate.sh -s olga.resnet.ucsb.edu -d kalina.resnet.ucsb.edu -i migrationConf VI Fast Pass "vifpinit" has not been executed for either "olga.resnet.ucsb.edu" or "kalina.resnet.ucsb.edu"! Please run the following once prior to executing this script: vifpinit olga.resnet.ucsb.edu or vifpinit kalina.resnet.ucsb.edu You can check your environmental variables to ensure the following have been defined: env | grep VI VI_SERVER, VI_PROTOCOL, VI_PORTNUMBER, VI_SERVICEPATH, VI_USERNAME and VI_PASSWORD [vi-admin@vima-primp-industries ~]$ vifpinit olga.resnet.ucsb.edu
2. Generating available virtual machine list
[vi-admin@vima-primp-industries ~]$ ./ghettoQuickMigrate.sh -s olga.resnet.ucsb.edu -d kalina.resnet.ucsb.edu -i migrationConf Retrieving info from: olga.resnet.ucsb.edu ... Generating virtual machine list (this may take some time).... 1) quickMigrate-1 2) quickMigrate-2 3) quickMigrate-3 4) exit Please select VM(s) to be migrated (e.g. 1,2,3,4,5 or 1,2,3-5):
3. Confirmation of selected VM(s)
Note: The current configuration will be saved to the specified file if migration is not executed.
[vi-admin@vima-primp-industries ~]$ ./ghettoQuickMigrate.sh -s olga.resnet.ucsb.edu -d kalina.resnet.ucsb.edu -i migrationConf Retrieving info from: olga.resnet.ucsb.edu ... Generating virtual machine list (this may take some time).... 1) quickMigrate-1 2) quickMigrate-2 3) quickMigrate-3 4) exit Please select VM(s) to be migrated (e.g. 1,2,3,4,5 or 1,2,3-5): 1-3 Selected VM(s): 1) quickMigrate-1 2) quickMigrate-2 3) quickMigrate-3 Please confirm the quick migration of the listed 3 VM(s) from "olga.resnet.ucsb.edu" to "kalina.resnet.ucsb.edu"? (y or n) y
4. Execution of migration
-------------------------------------------------------------------- SOURCE :: |olga.resnet.ucsb.edu| -------------------------------------------------------------------- quickMigrate-1 [ ] quickMigrate-2 [ queued ] quickMigrate-3 [ queued ] -------------------------------------------------------------------- TARGET :: |kalina.resnet.ucsb.edu| -------------------------------------------------------------------- ==================================================================== Migrating quickMigrate-1 Status: Suspending 0/3 VM(s) migrated -- 3 VM(s) left to migrate
5. Migration progress for each VM will be updated on the screen
-------------------------------------------------------------------- SOURCE :: |olga.resnet.ucsb.edu| -------------------------------------------------------------------- quickMigrate-2 [#### ] quickMigrate-3 [ queued ] -------------------------------------------------------------------- TARGET :: |kalina.resnet.ucsb.edu| -------------------------------------------------------------------- quickMigrate-1 [ migrated ] ==================================================================== Migrating quickMigrate-2 Status: Unregistering 1/3 VM(s) migrated -- 2 VM(s) left to migrate
-------------------------------------------------------------------- SOURCE :: |olga.resnet.ucsb.edu| -------------------------------------------------------------------- quickMigrate-3 [ queued ] -------------------------------------------------------------------- TARGET :: |kalina.resnet.ucsb.edu| -------------------------------------------------------------------- quickMigrate-1 [ migrated ] quickMigrate-2 [######## ] ==================================================================== Migrating quickMigrate-2 Status: Resuming 2/3 VM(s) migrated -- 1 VM(s) left to migrate
6. Migration completed
-------------------------------------------------------------------- SOURCE :: |olga.resnet.ucsb.edu| -------------------------------------------------------------------- -------------------------------------------------------------------- TARGET :: |kalina.resnet.ucsb.edu| -------------------------------------------------------------------- quickMigrate-1 [ migrated ] quickMigrate-2 [ migrated ] quickMigrate-3 [ migrated ] ==================================================================== 3/3 VM(s) migrated Start time: Mon Jan 26 00:58:34 PST 2009 End time: Mon Jan 26 01:00:00 PST 2009 Duration : 1.43 Minutes
Right, this does not work very well.
I just tried to move a machine from an ESXi standalone server that sits outside my vCenter foundation. The machine disappeared and I can't start up a new machine with the old hard drive, network binding fails 😕
fpjs,
The document states clearly that you need to have shared storage amongst the ESX/ESXi hosts that you're attempting the "quick migration", if you do not, it will not work. The VM is just unregistered and should still be residing on the original ESXi host that you tried to migrate from. You should be able to go into the datastore and browse for the VM and re-register.
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
Note, VMware ESXi 3.5u4 was just released and the internal API seems to have been fixed and VI API will have only read-only access when using the free licensed version of ESXi. This script will most likely not work on U4, please be advised if you're going to upgrade. I have not had a chance to verify but I believe this will be the case: http://tinyurl.com/cxayy6 U3 will continue to have this hole in the API to provide both read/write access to the VI API.
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
Hello,
can I use this script to migrate VMs between two ESXi 4.0 hypervisors?
I have not tested on ESX(i) 4.0, I know there have been some changes to vMA 4.0 and it may or may not work but have not had any time to really test the various scripts I've written for ESX(i) 4.0
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
I've tried to use this script in vMA 4.0 but I'm getting error related to perl toolkit:
Could not locate /usr/lib/vmware-viperl/apps/vm/vminfo.pl, please ensure system has VI Perl Toolkit installed.
With vMA 4.0, the path has changed to /usr/lib/vmware-vcli/apps/ and you just need to update that in the script. Again, one of the few changes from VIMA 1.0 to vMA 4.0
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Now I'm getting this error:
"In order for this script to function, modifications to two VI Perl Toolkit scripts must be made. These scripts will be duplicated for modification and the process will require your sudo password:
ERROR: It seems that the original scripts: "/usr/lib/vmware-vcli/apps/vm/vmcontrol.pl" or "/usr/share/doc/vmware-viperl/samples/vm/vmregister.pl" may have been modified, new required modifications can not be completed."
It looks like it try to ask for a password but I can't enter it because script is closing right away
Like I said before, there are going to be differences in the scripts I expect which is probably the bulk of the work. Good Luck
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Hi,
maybe this is a dumb question
If this script is adapted to run with vix vmrun 1.62 maybe will run?
Regards/Saludos,
Pablo
Please consider awarding
any helpful answer. Thanks!! -Por favor considera premiar
las respuestas útiles. ¡¡Muchas gracias!!Probably since 1.62 isn't being checked for licensing, you could probably modify the script to use vmrun, though the 1.62 does have it's bugs/glitches
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at: http://engineering.ucsb.edu/~duonglt/vmware/
VMware Code Central - Scripts/Sample code for Developers and Administrators
If you find this information useful, please award points for "correct" or "helpful".
Does this script still work with ESXi 4.1? Looking for a way to migrate VMs without Virtualcenter with shared storage.