1

Running the following command generates different random output on each execution (which is expected, considering that random is in the path):

cat /proc/sys/kernel/random/uuid

Is there any way to modify the path so that it results in a static (not random) UUID on each call (return the same thing on each request/execution instead of being random)?

  • 4
    This doesn't make sense much. A uuid (Universal Unique IDentifier) is meant to be unique among system's generated uuid's as well as global known uuid's. If you want to refer to the same uuid you generate, just use mystaticuuid=$(uuidgen) and then call it using echo "$mystaticuuid" – Valentin Bajrami Mar 8 '17 at 9:48
4

You asked

Is there any way to modify the path so that it results in a static (not random) UUID on each call

And the answer to this is "yes, definitely".

If you prepare the environment like this:

cat /proc/sys/kernel/random/uuid >/tmp/uuid

You can modify the path to get a static UUID on each call, like this

cat /tmp/uuid
  • Well, that's obvious, I suppose. (I blame lack of sleep for not thinking that through.) – Agi Hammerthief Mar 8 '17 at 10:49
  • 1
    @Agi what are you actually trying to achieve? – roaima Mar 8 '17 at 11:16
  • What I actually want to do is create a unique ID for a machine running GNU/Linux, thinking that running a slight adaptation of /proc/sys/kernel/random/uuid would be the way to go. On Windows, I can run wmic DISKDRIVE get SerialNumber and query the registry for the value of HKLM\Software\Microsoft\Cryptography\MachineGuid to get values I can work with. I was wondering if I could achieve something similar with GNU/Linux (other than getting the HWAddrs of all NICs in the machine and hashing them, as I have seen suggested). However, I'll ask a separate question for that. – Agi Hammerthief Mar 8 '17 at 12:39
  • I have some existing Java software that uses a Windows-specific DLL to retrieve hardware information and generate a hashed UID for the machine on which it runs (implementation details of which are known to me). I'm trying to port it to GNU/Linux and the licensing is what prevents me from porting it. (The output doesn't have to be the same on both platforms, but it would be advantageous if it is.) – Agi Hammerthief Mar 8 '17 at 12:49
  • 2
    @AgiHammerthief take a look at generate consistent machine unique ID – roaima Mar 8 '17 at 13:42
1

Having recently needed to build some licensing functionality into an application (the problem I was trying to solve when first posting this question), I found that it's possible to obtain a static UUID from one of the following files:

/etc/machine-id  # preferred
/var/lib/dbus/machine-id  # Usually a symlink to /etc/machine-id
/var/db/dbus/machine-id  # usually a symlink/alternative to /var/lib/dbus/machine-id
/proc/sys/kernel/random/uuid  # Will vary on each invocation, so save output to another file 
  # (as per roaima's answer).

In the above list of files, they're listed from most preferred to least preferred.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.