I’m looking for a linux system session id which is constant over the full runtime of the linux session (as long as uptime is increasing). After each reboot, it should be reset to another (random) value, probably formatted as a uuid.
I need this for logging in a global context, where I need to know if two logfiles come from the same session. Placing a stamp file in /tmp/ or another volatile folder could be an option but I want to avoid flooding such global folders. Using the system startup time is also not an option because the machine doesn’t have an RTC battery and the time is reset after power loss. There will still be some milliseconds difference each time, but I don’t want to risk collisions. Same thing with hashing the system start dmesg or parts of /proc or /sys.
I wonder if the kernel doesn’t already provide such information over /proc or /sys?
Advertisement
Answer
The solution:
cat /proc/sys/kernel/random/boot_id
I found it while searching for systemd’s “boot id”. There was a DBus bug report referencing the file: https://bugs.freedesktop.org/show_bug.cgi?id=23679