Theo Band
2012-May-11 10:51 UTC
[CentOS] How to prevent virtual machines running twice on the disk images?
I use KVM on two identical centos5 hosts. I can live migrate the virtual machines from one to the other and it works great. Once I do this, I can see VM definitions on both hosts using virt-manager or virsh list --all On one machine the VM is running, on the other it reports "shut off". The disk images are accessible to both host machines and I want to have only one running a the time (of course). If the VM locks up, I could by mistake think that the machine is not running and try to start it on the wrong host. My question is, how can I prevent host A from starting a "shut off" VM that actually has been migrated to host B? The VM could actually be running on any another host. It could also have been crashed. The most simple solution would be some sort of lock file placed next to the disk image location, so seen by all hosts. But perhaps there is another way of working with virt-manager that I am not aware of? Theo
Regendoerp, Achim
2012-May-11 11:07 UTC
[CentOS] How to prevent virtual machines running twice on the disk images?
> -----Original Message----- > From: centos-bounces at centos.org [mailto:centos-bounces at centos.org] On > Behalf Of Theo Band > Sent: 11 May 2012 11:51 > To: CentOS mailing list > Subject: [CentOS] How to prevent virtual machines running twice on the disk > images? > > I use KVM on two identical centos5 hosts. > > I can live migrate the virtual machines from one to the other and it works > great. Once I do this, I can see VM definitions on both hosts using virt- > manager or virsh list --all On one machine the VM is running, on the other it > reports "shut off". > The disk images are accessible to both host machines and I want to have only > one running a the time (of course). If the VM locks up, I could by mistake > think that the machine is not running and try to start it on the wrong host. > > My question is, how can I prevent host A from starting a "shut off" VM that > actually has been migrated to host B? The VM could actually be running on > any another host. It could also have been crashed. The most simple solution > would be some sort of lock file placed next to the disk image location, so > seen by all hosts. But perhaps there is another way of working with virt- > manager that I am not aware of? > > TheoAre those machines clustered? I used drbd/pacemaker/corosync to achieve something similar across two CentOS hosts with KVM machines, and the VM can only be started on the master node where the DRBD drive is mounted and accessible. Live migrations are fairly easy too with this method This email has been sent from Gala Coral Group Limited ("GCG") or a subsidiary or associated company. GCG is registered in England with company number 07254686. Registered office address: 71 Queensway, London W2 4QH, United Kingdom; website: www.galacoral.com. This e-mail message (and any attachments) is confidential and may contain privileged and/or proprietorial information protected by legal rules. It is for use by the intended addressee only. If you believe you are not the intended recipient or that the sender is not authorised to send you the email, please return it to the sender (and please copy it to hq at galacoral.com) and then delete it from your computer. You should not otherwise copy or disclose its contents to anyone. Except where this email is sent in the usual course of business, the views expressed are those of the sender and not necessarily ours. We reserve the right to monitor all emails sent to and from our businesses, to protect the businesses and to ensure compliance with internal policies. Emails are not secure and cannot be guaranteed to be error-free, as they can be intercepted, amended, lost or destroyed, and may contain viruses; anyone who communicates with us by email is taken to accept these risks. GCG accepts no liability for any loss or damage which may be caused by software viruses.
Tait Clarridge
2012-May-11 13:06 UTC
[CentOS] How to prevent virtual machines running twice on the disk images?
On Fri, 2012-05-11 at 12:51 +0200, Theo Band wrote:> I use KVM on two identical centos5 hosts. > > I can live migrate the virtual machines from one to the other and it > works great. Once I do this, I can see VM definitions on both hosts > using virt-manager or virsh list --all > On one machine the VM is running, on the other it reports "shut off". > The disk images are accessible to both host machines and I want to have > only one running a the time (of course). If the VM locks up, I could by > mistake think that the machine is not running and try to start it on the > wrong host. > > My question is, how can I prevent host A from starting a "shut off" VM > that actually has been migrated to host B? The VM could actually be > running on any another host. It could also have been crashed. The most > simple solution would be some sort of lock file placed next to the disk > image location, so seen by all hosts. But perhaps there is another way > of working with virt-manager that I am not aware of? > > TheoThis may not be what you are looking for, but you could always dump the xml of the domain to a file (so you could define/start it again if needed), then undefine the domain using virsh.
Paul Heinlein
2012-May-11 16:06 UTC
[CentOS] How to prevent virtual machines running twice on the disk images?
On Fri, 11 May 2012, Theo Band wrote:> I use KVM on two identical centos5 hosts. [....] > > My question is, how can I prevent host A from starting a "shut off" > VM that actually has been migrated to host B? The VM could actually > be running on any another host. It could also have been crashed. The > most simple solution would be some sort of lock file placed next to > the disk image location, so seen by all hosts. But perhaps there is > another way of working with virt-manager that I am not aware of?My way of dealing with that is to undefine the domain on host A after it's been moved to host B, e.g., virsh migrate --live myvm remote://host-b virsh undefine myvm The CentOS 6 version of virsh allows those operations to be combined: virsh migrate --live --persistent --undefinesource myvm ... -- Paul Heinlein heinlein at madboa.com 45?38' N, 122?6' W