I'm actually testing RHEL 5.3 with Xen between two servers in order to have a disaster recovery solution. So I'm playing with moving my domU from one dom0 server to the other server.
Unfortunatly when somebody else move the domU I don't have any clue where my domain is hosted. I'm wondering where I can't find my dom0 name with inside domU. I'm looking for something like the gzonename command on a solaris sparse zone. I check inside /proc/xen but I don't see anything special except the dom0 kernel release.
Does anybody know a wait to find this ?
We use
xenstore-write /tool/hostname $(uname -n); xenstore-chmod /tool/hostname r
onDom0
and thenxenstore-read /tool/hostname
within the VMs. Easy and lightweight ...I'm pretty sure there's no way to find the dom0 "name" (which is a nebulous concept at best) from within the domU. If you're not running pygrub, you could add something to the kernel boot command line (in the domU config file stored on each dom0) that you could query from /proc/cmdline, but that's a bit of a hack.
What you really should be doing is having a script that can query the dom0s to display which VMs are where. Even something that looped through the dom0s and ran
xm list
would probably do for your simple purposes.SLES11 has a "clever" solution provided by two rpms:
The first runs on the Dom0 and creates a small ram-disk (loop-device in /dev/shm). That ram-disk is attached in ro/read many-mode to the DomU. Then a daemon-process in Dom0 updates some information in the ram-disk at configurable intervals (Dom0-hostname, cpu-load of the Dom0, ...).
The second runs in the DomU and reads the values of that attached ram-disk.
See SLES11 XEN Documentation for further details...
Update 2017-01-31: Section 10.7
I found a clever solution (which I can't take credit for): add a parameter to the Xen script to tell the domU which dom0 it's running on
I know this has been posted for a few years but I see this is a heavily accessed page which still does not have an way to find this retroactively, so here's the method I used:
From the VM, use tcpdump to find the switch name and port number:
Give it a few min. to run; when it's done, look for these two lines in the output (they will be separated by other output lines):
You will then need to look at your switch port to determine what physical server is attached. Hopefully you either have physical access to the switch and can perform a cable trace or can engage someone who can, or you have good descriptions on switch port configurations and can view that information or engage someone who can. I have read access to our switches and was able to find my host server that way:
Install lldpd on the Xen Dom0 and DomUs. Then lldpctl will tell you which network bridge and the hostname of the bridge (i.e. the name of the Dom0). On the Dom0 you will also see the upstream switches if they have LLDP enabled, which can also be useful.
This works for PV, PVHVM, etc. In fact, it should work for any virtualisation platform that can run LLDP on the host, unless the host forwards LLDP packets straight through (which it should not).