37

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?

1
  • The mac address is not guaranteed to be unique, as it can be changed
    – cEz
    Nov 11, 2022 at 14:54

4 Answers 4

57

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
...
8
  • 14
    While googling about the /sys/class/dmi/id/board_serial availability I have found 0pointer.de/blog/projects/ids.html
    – user663896
    Apr 14, 2012 at 10:36
  • 9
    So, actually, I will use /var/lib/dbus/machine-id.
    – user663896
    Apr 14, 2012 at 10:43
  • 4
    That doesn't seem so portable, depending on dbus and all. Apr 14, 2012 at 11:16
  • That's very x86 specific. There is no such thing as /sys/class/dmi/id/product_uuid on Linux PPC (Apple based) for example.
    – malat
    Mar 5, 2015 at 11:58
  • 1
    /var/lib/dbus/machine-id can be changed with sudo
    – Ivan Kolev
    Aug 6, 2018 at 7:37
27

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
1
  • 1
    the machine-id may be the same on cloned VMs.
    – pynexj
    Sep 15, 2021 at 2:12
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.

3
  • 7
    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 5, 2015 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. Mar 13, 2015 at 17:35
  • 1
    Is machine-id useful for licensing beside mac? Aug 10, 2017 at 15:49
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy