From 147641fc3e11602cf9eaf723a2b38f60f394ac0b Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Mon, 11 Apr 2022 17:03:35 +1200 Subject: [PATCH] Set machine-id to uninitialized to trigger first boot According to the systemd documentation[1], if /etc/machine-id is empty it will be populated with a unique value, but not in a way which triggers an actual first boot event (running units with ConditionFirstBoot=yes set) This change writes "uninitialized" to /etc/machine-id to ensure that systemd-firstboot.service actually runs, and other units can use first-boot-complete.target as a dependency to trigger on first boot. Since /var/lib/dbus/machine-id is sometimes a symlink to /etc/machine-id, it is truncated before writing to /etc/machine-id. On older versions of systemd before first boot semantics were formalised, any non-uuid value will trigger a new machine-id to be generated, so "uninitialized" also works. [1] https://www.freedesktop.org/software/systemd/man/machine-id.html#First%20Boot%20Semantics Change-Id: I77c35e51a3da2e8a6b5a2c80d033a159b303c9af --- .../sysprep/finalise.d/99-clear-machine-id | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/diskimage_builder/elements/sysprep/finalise.d/99-clear-machine-id b/diskimage_builder/elements/sysprep/finalise.d/99-clear-machine-id index f9557fe8..c1681077 100755 --- a/diskimage_builder/elements/sysprep/finalise.d/99-clear-machine-id +++ b/diskimage_builder/elements/sysprep/finalise.d/99-clear-machine-id @@ -6,10 +6,17 @@ fi set -eu set -o pipefail -if [ -e /etc/machine-id ]; then - > /etc/machine-id -fi - if [ -e /var/lib/dbus/machine-id ]; then > /var/lib/dbus/machine-id fi + +# According to documented First Boot Semantics writing "uninitialized" will trigger the full +# first boot behaviour. +# https://www.freedesktop.org/software/systemd/man/machine-id.html#First%20Boot%20Semantics +# On older versions of systemd before first boot semantics were formalised, any non-uuid value +# will trigger a new machine-id to be generated, so "uninitialized" also works. +# Previously this was done here by truncating /etc/machine-id. +if [ -e /etc/machine-id ]; then + echo uninitialized > /etc/machine-id +fi +