When using Zoning under Solaris, the hostid doesn’t change by zone, but you also obtain (via a function call, getzoneid()) a unique zoneid for your zone.
Using KVM under Linux, the hostid changes (increments) by zone – which is pretty good, but it’s not perfect – you might collide with someone elses hostid.
It there an API provided by KVM which enables me to get a zoneid?
Regarding your concerns about duplicate hostids:
Unlike Solaris, the Linux kernel does not provide the “gethostid” call. Instead, “gethostid” (used by the
/usr/bin/hostidprogram) is implemented by glibc, which tries to:/etc/hostidon my system) exists; if so, uses the 4-byte value in there;0.This means that if every system has a unique IP address they will also have a unique hostid.
If your systems do not have unique IP addresses, you can still override the hostid by using the
sethostidglibc library call (which writes to the file read by step (1) of glibc’sgethostidalgorithm above).Regarding fetching the zoneid of a KVM instance:
Unlike Solaris zones (where all instances share the same kernel), each instance of KVM runs its own copy of the Linux kernel, all of which are oblivious to other instances running. As far as I am aware, there is no direct equivalent of a Solaris zoneid, as each Linux instance has no way of collaborating with other Linux instances.
If you need a unique identifier for each running KVM instance, some options are:
Just settling for the IP Address / hostid, as described above;
When setting up / booting up your instances, generate a UUID for the system using
uuidgenand save it in a safe location on the filesystem. Such generated UUIDs will never match any other UUID with very high probability;When booting each instance of your system, pass in on the kernel command line a manually-constructed unique identifier for the instance (using the
-appendKVM command line argument). This can be fetched later from/proc/cmdline.