4

I have a hard drive with a Linux installation on it that I like to boot from different physical computers. My question is whether it's possible to programmatically detect which computer the drive is hooked up to. For example, I have tried calling cat /proc/cpuinfo and piping that into sha256sum in hopes to create a unique hash of hardware info for each workstation, but it seems like lists like those in /proc do not always maintain the same info after each reboot, because when I used that method, my hash kept changing.

Is there any easy way to do this?

3
  • 6
    This is actually a somewhat hard problem. My usual suggestion is to use the root partition's UUID, but that won't work here. Maybe the network interface's MAC address, if you don't change those yourself.
    – Tom Hunt
    Nov 13, 2015 at 23:51
  • 6
    cat /sys/class/dmi/id/product_uuid
    – mikeserv
    Nov 13, 2015 at 23:55
  • 2
    For modern systems with variable-speed CPUs, /proc/cpuinfo contains the current speed (not the top or rated speed) on the cpu MHz line(s). Nov 14, 2015 at 1:47

1 Answer 1

2

As Tom Hunt suggested in a comment, use the MAC address of one of the network interfaces. MAC addresses are unique. (This assumes that all of the computers have at least one network interface, but that's a plausible assumption.)

Take care that there might be multiple interfaces. I recommend that you treat all of them as valid identifiers for the same machine, to avoid trouble in various scenarios (interfaces may be assigned different names if they're detected in a different order; some interfaces may be removable (e.g. USB dongle) or disabled (e.g. wifi kill switch)).

You can use this command to list the MAC addresses of all currently available network interfaces (whether they're in use or not):

ip addr show | awk '$1 == "link/ether" {print $2}'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .