[CentOS] How to prevent virtual machines running twice on the disk images?

Fri May 11 13:06:39 UTC 2012
Tait Clarridge <tait at taiter.com>


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?
> 
> Theo

This 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.