Monday, November 17, 2008

How to migrate guests using virsh commands?

Usually "xm migrate -l" is used to migrate a guest from one system to other system. There is no option in virt-manager to migrate a guest from one host to another. Libvirt based virsh command can be used to do this. The syntax of "virsh migrate" is a bit confusing to a lot of beginners. Details given below would help in solving those confusions.

- There are two systems - HostA and HostB. HostA is the source machine and HostB is the destination machine.

1 - If you are currently logged into HostA as root, below command can be used to migrate a guest to HostB.

# virsh migrate --live xen+ssh://HostB

Replace HostB with its ip or FQDN. You would be asked for the root password of HostB. Upon entering the right password for HostB, migration would happen successfully.

2 - If you are currently logged into a third system in the network which has "virsh" command available in it, the below command can be used to migrate a guest from HostA to HostB.

# virsh --connect xen+ssh://HostA migrate --live xen+ssh://HostB

Replace HostA and HostB with its ip addresses or FQDNs. You would be asked for the root password of HostA first, then the HostB. Upon entering the right password for both hosts, migration would happen successfully.

3 - If you are currently logged into HostB and want to migrate a guest from HostA to HostB, can this be done using virsh? Try it out yourself.

Libvirt connection over ssh (xen+ssh) is the the method used in the above example. Libvirt remote TLS connection can also be established using certificates. Since that needs a bit more deails to setup, that is apt for another doc.

6 comments:

osdocs said...

Hi could you please post what linux distro / version / libvirt version you used for the live migration? I'm trying this with ubuntu 8.10, stock libvirt and kvm with no success, thanks!

Sadique Puthen said...

I tested this using two RHEL5.2 + xen. Used libvirt-0.3.3-7.el5. Have not yet tested with KVM.

Matt said...

I'm trying this at the moment without success. 'virsh help migrate' says the syntax is:

migrate [--live] domain desturi

Having verified that:

virsh -c xen+ssh://HostA list

is running a Domain called 'Guest', I'm then trying:

virsh -c xen+ssh://HostA migrate --live Guest xen+ssh://HostB

Results in:

libvir: Xen error : Domain not found: xenUnifiedDomainLookupByName

I've tried replacing the Domain name with its id/uuid, but with no success.

Any ideas?

Sadique Puthen said...

Matt,

U r using Xen or KVM? What version and what libvirt version?

If you log in to HostA and run "virsh migrate --live xen+ssh://HostB", does it work?

If you login to HostA and do, "xm migrate -l guest HostB", does it work?

Matt said...

Apologies - I've just discovered that there was a difference in the config files for the guest on the 2 hosts - fixing this allows the migration to work successfully.

Sadique Puthen said...

AFAIK, there is no need to have configuration files for the migrating guest on both source and destination machines for live migration to work.