How to find dom0 name from hosted domU

Solution 1:

We use xenstore-write /tool/hostname $(uname -n); xenstore-chmod /tool/hostname r on Dom0 and then xenstore-read /tool/hostname within the VMs. Easy and lightweight ...

Solution 2:

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.

Solution 3:

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

Solution 4:

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

Solution 5:

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