2

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.

asmaier
  • 131
  • 1
  • 5
  • possibly related question: [Can a virtual PC find out the identity of its host?](http://serverfault.com/questions/97185/can-a-virtual-pc-find-out-the-identity-of-its-host) – warren Jul 14 '11 at 15:35

3 Answers3

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.

Michael Trausch
  • 289
  • 1
  • 7
  • (Additionally, another way you could pass it would be to create a file .vm_uuid or similar in the guest system's filesystem root, such that a program could simply read the UUID from that file instead of looking in /proc/cmdline and parsing it out from the kernel command line.) – Michael Trausch Jul 25 '11 at 20:10
0

A solution for would be to use the DMI/SMBIOS table to convey information to the guest(s).

I like chassis_asset_tag for that purpose. qemu has a -smbios command line option for that. I wrote a more detailed answer to a very similar question.

Here's a list of available strings, with their DMI category, and variable name.

Alex Stragies
  • 409
  • 4
  • 12
0

Have the VM generate and store a UUID/GUID:

http://www.ietf.org/rfc/rfc4122.txt

   This specification defines a Uniform Resource Name namespace for
   UUIDs (Universally Unique IDentifier), also known as GUIDs (Globally
   Unique IDentifier).  A UUID is 128 bits long, and can guarantee
   uniqueness across space and time.  UUIDs were originally used in the
   Apollo Network Computing System and later in the Open Software
   Foundation's (OSF) Distributed Computing Environment (DCE), and then
   in Microsoft Windows platforms.

Microsoft provide a utility called uuidgen

Python has it built in from 2.5:

http://docs.python.org/library/uuid.html

So that covers you for Windows and Linux.

gm3dmo
  • 10,057
  • 1
  • 42
  • 36
  • What happens when that VM is copied to another host? How do you ensure that the UUID is unique? – Jed Daniels Jul 14 '11 at 21:00
  • The GUID/UUID doesn't change. The relevant snippet from the RFC "can guarantee uniqueness across space and time" – gm3dmo Jul 15 '11 at 05:51
  • Right. So once you make a copy, the UUID is no longer unique, since you now have two or more machines with the same UUID. You'd have to generate a NEW uuid, after having some mechanism to recognize that you just copied your first VM (note that I said copied, not moved; if you move, you want the same UUID). – Jed Daniels Jul 15 '11 at 19:21
  • Script the process; copy, boot, regenerate UIID, register UUID in CMDB. If people are making uncontrolled copies of VM's in an environment then that environment has other problems than a UUID is going to solve. – gm3dmo Jul 16 '11 at 07:30