Bug 244867 - Provide sysctl kern.boot_id
Summary: Provide sysctl kern.boot_id
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: --- Affects Some People
Assignee: Conrad Meyer
URL:
Keywords: feature
Depends on:
Blocks:
 
Reported: 2020-03-17 19:08 UTC by Ricardo Fraile
Modified: 2020-08-09 21:03 UTC (History)
2 users (show)

See Also:
cem: mfc-stable12-
cem: mfc-stable11-


Attachments
Fix output for sysctl kern.boot_id (881 bytes, patch)
2020-03-29 15:52 UTC, Ricardo Fraile
no flags Details | Diff
Update man 3 syctl with kern_boot_id (821 bytes, patch)
2020-03-29 15:53 UTC, Ricardo Fraile
no flags Details | Diff
Update man 8 syctl with kern_boot_id and order list (5.20 KB, patch)
2020-03-29 15:54 UTC, Ricardo Fraile
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ricardo Fraile 2020-03-17 19:08:20 UTC
Hello,


Tracking a new startup of the system usually fall into looking kern.boottime. But it isn't constant, sometimes drifts over time, so it isn't a 100% reliable source.

On Linux implemented /proc/sys/kernel/random/boot_id [1] with a random value generated early at boot, unique for every running kernel instance.

It would be nice to have it on FreeBSD too.



Thanks,



[1] - http://man7.org/linux/man-pages/man3/sd_id128_get_machine.3.html
Comment 1 Conrad Meyer freebsd_committer 2020-03-17 20:55:29 UTC
I agree that this would be useful to provide, and seems straightforward enough.
Comment 2 Kubilay Kocak freebsd_committer freebsd_triage 2020-03-17 21:13:34 UTC
To clarify, this is different from kern.hostuuid (and kern.hostid an alias, set via /etc/rc.d/hostid) in that each *boot* gets a new id, rather than a once per install, which is constant/immutable/read-only until the next boot? 

I also note that for kern.hostuuid, there's an associated security.jail.param.host.hostuuid sysctl.

Presumably this feature request should also apply to jails too?
Comment 3 commit-hook freebsd_committer 2020-03-17 22:28:01 UTC
A commit references this bug:

Author: cem
Date: Tue Mar 17 22:27:17 UTC 2020
New revision: 359053
URL: https://svnweb.freebsd.org/changeset/base/359053

Log:
  Implement sysctl kern.boot_id

  Boot IDs are random, opaque 128-bit identifiers that distinguish distinct
  system boots.  A new ID is generated each time the system boots.  Unlike
  kern.boottime, the value is not modified by NTP adjustments.  It remains fixed
  until the machine is restarted.

  PR:		244867
  Reported by:	Ricardo Fraile <rfraile AT rfraile.eu>
  MFC after:	I do not intend to, but feel free

Changes:
  head/sys/kern/kern_mib.c
Comment 4 Conrad Meyer freebsd_committer 2020-03-17 22:28:10 UTC
Dropping if someone wants to MFC or further enhance re jails.
Comment 5 Ricardo Fraile 2020-03-19 19:48:01 UTC
Thanks for the quick response. 

I just tried the last snapshop of 13.0-CURRENT x86 build today and the option doesn't fail but it doesn't report anything.


root@:~ # sysctl kern.boot_id
root@:~ # echo $?
0
root@:~ #
Comment 6 Ricardo Fraile 2020-03-29 15:52:02 UTC
Created attachment 212834 [details]
Fix output for sysctl kern.boot_id
Comment 7 Ricardo Fraile 2020-03-29 15:53:17 UTC
Created attachment 212836 [details]
Update man 3 syctl with kern_boot_id
Comment 8 Ricardo Fraile 2020-03-29 15:54:02 UTC
Created attachment 212837 [details]
Update man 8 syctl with kern_boot_id and order list
Comment 9 Ricardo Fraile 2020-03-29 15:54:49 UTC
I fix it with this code change, please see the patch uploaded. Also, there are two other patches to update man pages.

root@:~ # sysctl kern.boot_id
kern.boot_id: 16254718031988427779
Comment 10 Ricardo Fraile 2020-04-23 06:23:51 UTC
@cem did you see the last patches? is needed something more?

Having the functionality working on -current can allow to test it right, it would be helpful.

Thanks,
Comment 11 Ricardo Fraile 2020-06-21 11:25:45 UTC
Hello,

On FreeBSD-13.0-CURRENT-i386-20200611-r362037 I still have an empty output.

root@:~ # sysctl kern.boot_id


Thanks,
Comment 12 Mark Linimon freebsd_committer freebsd_triage 2020-07-30 23:19:29 UTC
^Triage: assign to committer.
Comment 13 Conrad Meyer freebsd_committer 2020-07-30 23:36:02 UTC
To print this value, one option is to use sysctl -x:

$ sysctl -x kern.boot_id
kern.boot_id: Format: Length:16 Dump:0x75ca41033699ae64afe63a45a6b5d258

The patch in comment #6 does not seem necessary or correct.

The patch in comment #7 documents a non-existent KERN_BOOT_ID identifier.

The patch in comment #8 combines an add and sort; those should be independent so it is clear what is being changed.

Cleared 'patch' tag.
Comment 14 Conrad Meyer freebsd_committer 2020-07-30 23:38:19 UTC
(In reply to Ricardo Fraile from comment #8)
Hm, and sysctl.8 is not an exhaustive list of all sysctls.  Mostly the tree is self-documenting or documented elsewhere.  I'm not sure adding this to that page is justified.