diff options
author | Tobias C. Berner <tcberner@FreeBSD.org> | 2022-12-17 09:18:03 +0000 |
---|---|---|
committer | Tobias C. Berner <tcberner@FreeBSD.org> | 2022-12-23 16:33:19 +0000 |
commit | 62a149bf621947fb7475c64b1ff04fe19fe16b29 (patch) | |
tree | e426c7e42b0c4194d1a80df5b2025bab541bfbf9 | |
parent | 3e3875413128ff01f43b7ae8e0ca8db8d8d5efca (diff) | |
download | src-62a149bf6219.tar.gz src-62a149bf6219.zip |
Add new rc: machine_id to generate /etc/machine-id
This new default-enabled rc will generate a /etc/machine-id file if it
does not exist, and pre-fill it with a newly generated UUID of version 4
[2].
The file is generated in /var/db/machine-id and symlinked to
/etc/machine-id to allow for read-only root partitions.
This file is amongst other things used by libraries like GLib.
Bump FreeBSD version 1400076 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
Approved by: bapt
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D37722
-rw-r--r-- | etc/Makefile | 2 | ||||
-rw-r--r-- | libexec/rc/rc.conf | 3 | ||||
-rw-r--r-- | libexec/rc/rc.d/Makefile | 1 | ||||
-rw-r--r-- | libexec/rc/rc.d/machine_id | 34 | ||||
-rw-r--r-- | sys/sys/param.h | 2 |
5 files changed, 41 insertions, 1 deletions
diff --git a/etc/Makefile b/etc/Makefile index 3036b7acdd19..10d2f7ea2c5c 100644 --- a/etc/Makefile +++ b/etc/Makefile @@ -59,6 +59,8 @@ distribution: ${_+_}cd ${SRCTOP}/usr.sbin/rmt; ${MAKE} etc-rmt ${INSTALL_SYMLINK} -T "package=runtime" ../var/run/os-release \ ${DESTDIR}/etc/os-release + ${INSTALL_SYMLINK} -T "package=runtime" ../var/db/machine-id \ + ${DESTDIR}/etc/machine-id .if ${MK_UNBOUND} != "no" if [ ! -e ${DESTDIR}/etc/unbound ]; then \ ${INSTALL_SYMLINK} -T "package=unbound" \ diff --git a/libexec/rc/rc.conf b/libexec/rc/rc.conf index d10855e1e5fa..a1f6a3f69e8d 100644 --- a/libexec/rc/rc.conf +++ b/libexec/rc/rc.conf @@ -694,6 +694,9 @@ harvest_mask="511" # Entropy device harvests all but the very invasive sources. osrelease_enable="YES" # Update /var/run/os-release on boot (or NO). osrelease_file="/var/run/os-release" # File to update for os-release. osrelease_perms="444" # Default permission for os-release file. +machine_id_enable="YES" # Create /var/db/machine-id on boot if missing (or NO). +machine_id_file="/var/db/machine-id" # File to update for machine-id. +machine_id_perms="444" # Default permissions for machine-id file. dmesg_enable="YES" # Save dmesg(8) to /var/run/dmesg.boot watchdogd_enable="NO" # Start the software watchdog daemon watchdogd_flags="" # Flags to watchdogd (if enabled) diff --git a/libexec/rc/rc.d/Makefile b/libexec/rc/rc.d/Makefile index 0e43b1cd94dc..e990dea60721 100644 --- a/libexec/rc/rc.d/Makefile +++ b/libexec/rc/rc.d/Makefile @@ -52,6 +52,7 @@ CONFS= DAEMON \ local \ localpkg \ lockd \ + machine_id \ mixer \ motd \ mountcritlocal \ diff --git a/libexec/rc/rc.d/machine_id b/libexec/rc/rc.d/machine_id new file mode 100644 index 000000000000..7cfd7b2d92f8 --- /dev/null +++ b/libexec/rc/rc.d/machine_id @@ -0,0 +1,34 @@ +#!/bin/sh +# +# $FreeBSD$ +# + +# PROVIDE: machine_id +# REQUIRE: mountcritremote FILESYSTEMS +# BEFORE: LOGIN + +. /etc/rc.subr + +: ${machine_id_file:=/var/db/machine-id} +: ${machine_id_perms:=444} +name="machine_id" +desc="Update ${machine_id_file}" +rcvar="machine_id_enable" +start_cmd="machine_id_start" +stop_cmd=":" + + +machine_id_start() +{ + if [ ! -f ${machine_id_file} ] ; then + startmsg -n "Creating ${machine_id_file} " + t=$(mktemp -t machine-id) + /bin/uuidgen -r -o $t + install -C -o root -g wheel -m ${machine_id_perms} "$t" "${machine_id_file}" + rm -f "$t" + startmsg 'done.' + fi +} + +load_rc_config $name +run_rc_command "$1" diff --git a/sys/sys/param.h b/sys/sys/param.h index bb56fe1140cf..9b123a38a7a8 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -76,7 +76,7 @@ * cannot include sys/param.h and should only be updated here. */ #undef __FreeBSD_version -#define __FreeBSD_version 1400075 +#define __FreeBSD_version 1400076 /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD, |