This blog post is a part of “the things I learned while working on popcorn”, Popcorn tracks usage of linux packages. Ionuț Arțăriși is my mentor for this GSoC project for openSUSE.

Popcorn requires UUIDs (Universally unique IDs) so that it doesn’t receive submissions from the same system again before a certain period of time.

We used to use smolt id, but smolt package is not present in all Linux distributions.

So on a quest to find a universally unique ID that is present on all distributions, Petr Uzel pointed me to Lennart’s Blog Post.

tl;dr use/var/lib/dbus/machine-id if you are looking for a globally unique id for a Linux system.

Hardware IDs:

  • /sys/class/dmi/id/productuuid: mainboard uuid

  • CPUID/EAX=3: CPU serial number

  • /sys/class/net/*/address: One or more network MAC addresses

  • /sys/bus/usb/devices/*/serial:Serial numbers of various USB devices

The problems with hardware IDs are that:

  • They are bound to specific, replaceable hardware

  • Not universally available

  • Filled with bogus data/random in virtual environments

Software IDs:

  • /proc/sys/kernel/random/bootid: Random ID unique for each boot

  • /var/lib/dbus/machine-id: identifies specific Linux installation.
    • Doesn’t change if hardware is replaced

    • Reliable in virtualized environments

    • Globally unique

  • /proc/self/sessionid: identifies a specific login session, maintained by kernel and shared by each process of a session. In some distributions this is always(uint32_t) -1

  • getuid(): To identify a particular user. Locally unique, may be reassigned to new user if users are deleted.

We can combine locally unique ids with /var/lib/dbus/machine-id to generate globally unique ids for a particular user or session.

Generating UUIDs:

You can also generate UUIDs using uuidgen command or simply read 16 bytes from /dev/random