38

What is the best-practiced way to get an unique machine ID in GNU/Linux for i386 architecture?

Are there any good ways except the mac address?

jww
  • 97,681
  • 90
  • 411
  • 885

4 Answers4

61

Depending on your kernel, the DMI information may be available via sysfs. Try those:

# cat /sys/class/dmi/id/board_serial
xxxxxxxxxxxxxxx
# cat /sys/class/dmi/id/product_uuid
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

or using a tool

# dmidecode -s baseboard-serial-number
...
# dmidecode -s system-uuid
...
c00kiemon5ter
  • 16,994
  • 7
  • 46
  • 48
31

On modern machines with systemd: machine id is created by systemd-machine-id-setup. The location of machine id is documented - in freedesktop machine-id and man machine-id and machine id has a more standardized format - see RFC4122. Just:

cat /etc/machine-id
Community
  • 1
  • 1
KamilCuk
  • 120,984
  • 8
  • 59
  • 111
  • 1
    the machine-id may be the same on cloned VMs. – pynexj Sep 15 '21 at 02:12
  • 1
    But isn't that the whole idea of having a "cloned VM" of begin the same machine-id. Here the VM software seems to be the real problem as a clone is a to simplified command without specifying what the clone is used for. – Lothar Jul 08 '23 at 15:54
5

You can use lshal. This needs hal (apt-get install hal or yum install hal) to be installed first. This way you can access all the info of dmidecode without root permissions.

A non-root equivalent of

# dmidecode | grep -i uuid

will be

$ lshal |grep -i system.hardware.uuid

And similarly other info as per your needs.

adnan kamili
  • 8,967
  • 7
  • 65
  • 125
  • 8
    If `lshal` is available on said system, this means `hal` is installed, which means `dbus` is installed. Therefore it is simply `cat /var/lib/dbus/machine-id` – malat Mar 05 '15 at 11:26
  • 6
    @malat it is clear from the question that user wants to generate a uuid which is permanent and doesn't change. "dbus/machine-id" can even change after every reboot. – adnan kamili Mar 13 '15 at 17:35
  • 1
    Is machine-id useful for licensing beside mac? – user4271704 Aug 10 '17 at 15:49
0

A simple and portable way of computing your own sysid may be to serialize uname(), gethostid() and some inodes like /home or your application homedir (obtained with stat()) etc. in a string and hash It.

andrelsm
  • 9
  • 1