8

I searched my question and none of them answered me: Is machine-id as unique as mainboard UUID (fetched by "get csproduct UUID" command on windows)? And is enough reliable to bind a license on machine-id beside mac address? Or what is uuid on *nix system that can be used for licensing?

Nima
  • 91
  • 1
  • 1
  • 2

2 Answers2

11

Yes, nowadays.

This is covered in the systemd manual. The value in /etc/machine-id was originally not a valid UUID, because the systemd people did not originally write correct code for generating a version 4 UUID. But this has since been fixed.

If you bind a licence to the machine ID, be aware that it can change …

  • … if someone deletes /etc/machine-id and it gets re-created at next bootstrap;
  • … if /etc (usually on the root volume in practice) is not mounted read-write at bootstrap, /etc/machine-id is invalid or missing, and /etc cannot be later re-mounted read-write allowing /etc/machine-id to be written;
  • … if the disc volume containing /etc is replaced with another, different, disc volume whilst the operating system is not running or someone changes the machine-id on the disc volume with a tool such as systemd-firstboot;
  • … if the system is what the systemd people call "stateless" and (effectively, it being slightly more complex than this) /etc/machine-id gets re-created at every bootstrap;
  • … inside containers on the machine.

But it, intentionally, does not change …

  • … if the mainboard, processor, or NIC is replaced;
  • … if the MAC addresses of NICs are changed;
  • … if the root volume (more specifically, the volume containing /etc) is imaged onto a replacement disc with something like dd or pax;
  • … during system runtime (unless the system administrator deliberately mucks around with it);
  • …from one bootstrap to the next if /etc/machine-id is valid, non-empty, and writable the first time around.

portability notes

  • Don't use /var/lib/dbus/machine-id in preference to /etc/machine-id.
    • The original Desktop Bus file which begat /etc/machine-id is unfortunately not in a fixed location that is portable across operating systems. On some systems one finds it at /var/lib/dbus/machine-id; on others at /var/db/dbus/machine-id.
    • Sometime around 2013, D-Bus was modified to make use of /etc/machine-id if it exists, superseding the file in /var, whereever it is.
    • In 2015, the Debian/Ubuntu people made the D-Bus file in /var default to being a symbolic link to /etc/machine-id, in any case.
  • /etc/machine-id is not limited to only being available in the bootstrap process after /var is mounted or after network interfaces are brought up.
  • Although vanilla FreeBSD/TrueOS, NetBSD, and OpenBSD do not provide a /etc/machine-id, the nosh toolset provides portable tools (that are also usable on Linux) for creating it that also know of the BSD-specific places that the BSDs expect such IDs and keep the twain consistent.

Further reading

JdeBP
  • 66,967
  • 12
  • 159
  • 343
  • The answer to "Is machine-id a uuid?" is as I wrote it. – JdeBP Oct 04 '17 at 13:40
  • Then you were getting mixed up as to what answers what. (-: – JdeBP Oct 14 '17 at 15:11
  • What do you mean by *imaged onto a replacement disc with something like [...] pax*? Are you talking of the POSIX `pax` (portable archiver) command? – Stéphane Chazelas Mar 20 '19 at 16:15
  • Something I ran into the other day: cloning a VM means the clone gets the same machine-id. And what makes matters worse, systemd uses it as the DHCP client identifier which means the clone will get the same IP address as the original. – Stéphane Chazelas Mar 20 '19 at 16:17
  • You should enjoy the DESCRIPTION and EXAMPLE USERS sections from the new `machine-id` manual page that I just put into the further reading. (-: – JdeBP Mar 21 '19 at 00:58
3

From a quick Google search:

  • /etc/machine-id should be unique, and only change if the machine is reinstalled, but is provided by systemd, which many systems don't have
  • /var/lib/dbus/machine-id should be unique, and should be much more widely available. The docs say it can change if the hardware configuration changes, but in practice I think it only changes if the machine is reinstalled
  • you could use system-uuid, but you need to be root, and it will change if the motherboard changes

/var/lib/dbus/machine-id seems like the best method for most situations.

Further reading:

Mikel
  • 56,387
  • 13
  • 130
  • 149