Page MenuHomeFreeBSD

Add new rc: machine_id to generate /etc/machine-id
ClosedPublic

Authored by tcberner on Dec 17 2022, 9:22 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Oct 23, 4:31 AM
Unknown Object (File)
Wed, Oct 16, 4:16 AM
Unknown Object (File)
Oct 9 2024, 2:24 PM
Unknown Object (File)
Oct 9 2024, 2:24 PM
Unknown Object (File)
Oct 9 2024, 2:24 PM
Unknown Object (File)
Oct 9 2024, 2:24 PM
Unknown Object (File)
Oct 9 2024, 2:24 PM
Unknown Object (File)
Oct 9 2024, 2:22 PM

Details

Summary

This new default-enabled rc will generate a /etc/machine-id file if it
does not exist, and prefill it with a newly generated UUID of version 4
[2].

This file is amongst other things used by libraries like GLib.

Bump FreeBSD version to be able to easily add support for older version
of FreeBSD via a package.

[1] Linux machine-id(5): https://www.man7.org/linux/man-pages/man5/machine-id.5.html
[2] f176fe8e7f638e585afcd2f4dd52a522c4648f63

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 48776
Build 45662: arc lint + arc unit

Event Timeline

arichardson added inline comments.
libexec/rc/rc.d/machine_id
25
tijl added inline comments.
libexec/rc/rc.conf
698

I think osrelease above uses /var to support read-only /etc. So maybe you should use something like /var/db/machine-id here and make /etc/machine-id a symlink like /etc/os-release.

jlduran added inline comments.
libexec/rc/rc.d/machine_id
32

Do we want this message displayed every time after the machine-id file is created?

libexec/rc/rc.d/machine_id
32

Please, discard the comment.
It was supposed to be just the removal of -n (should be echoed with a trailing newline character) and the removal of the space at the beginning of the sentence.

bcr added inline comments.
libexec/rc/rc.conf
698

Does the comment have a superfluous "if" in it (the first one)?
I think it would be better if the comment would state:
"Create /etc/machine-id on boot if missing (or NO)."

libexec/rc/rc.conf
698

I think osrelease above uses /var to support read-only /etc. So maybe you should use something like /var/db/machine-id here and make /etc/machine-id a symlink like /etc/os-release.

If you decide to do this (which probably makes sense), you'll also need to add the symlink to etc/Makefile (see rS354922)

libexec/rc/rc.conf
698

does it make sense to have an "ideally" static file in /var/db if so, sure, I'll move it there, and create a symlink

libexec/rc/rc.d/machine_id
32

the machine-id file should only be generated once, ideally.

  • Don't spam message log if machine-id exists
  • Generate machine-id in /var/db
  • Fix comment
  • Create symlink from /var/db/machine-id to /etc/machine-id
tcberner added inline comments.
libexec/rc/rc.conf
698

^ does it make sense that machine_id_file this is configurable given the etc/Makefile change?

  • Add machine_id to libexec/rc/rc.d/Makefile

All generated files should wind up in /var/db, imho. I have lots of read-only root machines that would need yet another special case for this. They have writeable /var/db partitions though.

LGTM,
I would personnally suppress all configurability in rc.conf, but I don't think it hurts to be able to do extra config via rc.conf.

please MFC After: 1 week

This revision is now accepted and ready to land.Dec 23 2022, 7:51 AM

this says MFC 1 week. that was two weeks ago.
This revision links to machine-id(5) on Linux, but perhaps we should have that man page ourselves

This is good, but it doesn't match what Linux does. Both systemd and dbus generate 32 character UUID strings, while this creates 36 character ones.

I'd suggest we strip the '-' characters from the machine-id file, and possibly think about ensuring that dbus's idea of the machine-id is the same as the one generated here, or since dbus will use /etc/machine-id if /var/lib/dbus/machine-id doesn't exist, maybe not generating the latter at all.

This is good, but it doesn't match what Linux does. Both systemd and dbus generate 32 character UUID strings, while this creates 36 character ones.

I'd suggest we strip the '-' characters from the machine-id file, and possibly think about ensuring that dbus's idea of the machine-id is the same as the one generated here, or since dbus will use /etc/machine-id if /var/lib/dbus/machine-id doesn't exist, maybe not generating the latter at all.

@tcberner regarding this comment, should we change it to /bin/uuidgen -r | tr -d - > $t, or something similar? or is not really necessary to strip the -s?

In D37722#879899, @jlduran_gmail.com wrote:

This is good, but it doesn't match what Linux does. Both systemd and dbus generate 32 character UUID strings, while this creates 36 character ones.

I'd suggest we strip the '-' characters from the machine-id file, and possibly think about ensuring that dbus's idea of the machine-id is the same as the one generated here, or since dbus will use /etc/machine-id if /var/lib/dbus/machine-id doesn't exist, maybe not generating the latter at all.

@tcberner regarding this comment, should we change it to /bin/uuidgen -r | tr -d - > $t, or something similar? or is not really necessary to strip the -s?

Moin moin

I probably misread the documentation that said that modern systemd creates valid UUIDs. But that probably did not mean also it uses the 'dashed' format.

mfg Tobias

In D37722#879899, @jlduran_gmail.com wrote:

This is good, but it doesn't match what Linux does. Both systemd and dbus generate 32 character UUID strings, while this creates 36 character ones.

I'd suggest we strip the '-' characters from the machine-id file, and possibly think about ensuring that dbus's idea of the machine-id is the same as the one generated here, or since dbus will use /etc/machine-id if /var/lib/dbus/machine-id doesn't exist, maybe not generating the latter at all.

@tcberner regarding this comment, should we change it to /bin/uuidgen -r | tr -d - > $t, or something similar? or is not really necessary to strip the -s?

Moin moin

I probably misread the documentation that said that modern systemd creates valid UUIDs. But that probably did not mean also it uses the 'dashed' format.

mfg Tobias

Ahh, I see:
https://www.man7.org/linux/man-pages/man5/machine-id.5.html#RELATION_TO_OSF_UUIDS