Can I give a virtual machine a unique ID which is accessible from inside the VM?

I want to be able uniquely identify my virtual machines from inside the virtual machine. The problem is that in my setup I cannot use the MAC address for that. Is it possible to configure another hardware parameter (e.g. CPU name, BIOS flags, Motherboard ID,...) to have a unique value for my VM which I can then access from inside the VM? I would be most interested in solutions which work for Xen, KVM or VMWare ESX or at best for all of them.


Solution 1:

You could generate a UUID from the host when the VM is created, and pass it in via the kernel command-line. When you transfer the machine from one hardware node to the next, the UUID would travel with it. However, when you create a new machine, a new UUID would be generated for it.

As mentioned in the other answer, this won't work if you duplicate the VM (including its configuration), but in that event it wouldn't be hard to run uuidgen from the command line and replace the UUID in the configuration file that is used to create the domain.

As a matter of practice, it's probably best not to duplicate VMs in that manner anyway; you should create a new VM and have a script run that configures the VM in whatever manner best fits your environment.