From 74253ae99a81de3c329f98ca89262e44ec387c5f Mon Sep 17 00:00:00 2001 From: Itxaka Date: Fri, 2 Aug 2024 11:00:04 +0200 Subject: [PATCH] :bug: Empty machine-id instead of removing it We used to rely on a hidden feature of sysinfo that created a filled machine-id during initramfs so systemd did not trigger the first boot service. Now on the newer agent versions, that hidden functionality has gone away so if we remove it teh file, systemd will think that this is a new system and will do some work behind our back initializing and break things around. So we need to create en empty machine-id file so systemd knows that we dont want to run the first boot services/target Signed-off-by: Itxaka --- images/Dockerfile.kairos | 7 ++++++- images/Dockerfile.kairos-alpine | 7 ++++++- images/Dockerfile.kairos-debian | 7 ++++++- images/Dockerfile.kairos-opensuse | 7 ++++++- images/Dockerfile.kairos-rhel | 7 ++++++- images/Dockerfile.kairos-ubuntu | 7 ++++++- 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/images/Dockerfile.kairos b/images/Dockerfile.kairos index 2af8c3ebc..14a38b61b 100644 --- a/images/Dockerfile.kairos +++ b/images/Dockerfile.kairos @@ -85,6 +85,12 @@ RUN luet database get-all-installed --output /etc/kairos/versions.yaml # TODO what about caches? RUN kernel=$(ls /lib/modules | head -n1) && depmod -a "${kernel}" + +# Set empty machine-id +# This prevents systemd from thinking that the machine is on first boot +# and recreating /etc/ dependencies in services and such +# do this before initramfs so its in the initramfs +RUN echo "" > /etc/machine-id || true # Regenerate initrd if necessary, proper config files with immucore and custom initrd should already be in there installed by framework # for systemd distros RUN if [ -f "/usr/bin/dracut" ]; then \ @@ -105,7 +111,6 @@ RUN kernel=$(ls /boot/Image* 2>/dev/null | head -n1) && if [ -e "$kernel" ]; the # this is generally present on rhel based systems, but it doesn't hurt to remove in any case RUN rm -rf /boot/initramfs-* || true -RUN rm /etc/machine-id || true RUN rm /var/lib/dbus/machine-id || true RUN rm /etc/hostname || true diff --git a/images/Dockerfile.kairos-alpine b/images/Dockerfile.kairos-alpine index e20177911..d3b983fb4 100644 --- a/images/Dockerfile.kairos-alpine +++ b/images/Dockerfile.kairos-alpine @@ -236,6 +236,12 @@ RUN luet database get-all-installed --output /etc/kairos/versions.yaml # TODO what about caches? RUN kernel=$(ls /lib/modules | head -n1) && depmod -a "${kernel}" + +# Set empty machine-id +# This prevents systemd from thinking that the machine is on first boot +# and recreating /etc/ dependencies in services and such +# do this before initramfs so its in the initramfs +RUN echo "" > /etc/machine-id || true # Regenerate initrd if necessary, proper config files with immucore and custom initrd should already be in there installed by framework # for systemd distros RUN if [ -f "/usr/bin/dracut" ]; then \ @@ -256,7 +262,6 @@ RUN kernel=$(ls /boot/Image* 2>/dev/null | head -n1) && if [ -e "$kernel" ]; the # this is generally present on rhel based systems, but it doesn't hurt to remove in any case RUN rm -rf /boot/initramfs-* || true -RUN rm /etc/machine-id || true RUN rm /var/lib/dbus/machine-id || true RUN rm /etc/hostname || true diff --git a/images/Dockerfile.kairos-debian b/images/Dockerfile.kairos-debian index 3ee399c80..8508525da 100644 --- a/images/Dockerfile.kairos-debian +++ b/images/Dockerfile.kairos-debian @@ -249,6 +249,12 @@ RUN luet database get-all-installed --output /etc/kairos/versions.yaml # TODO what about caches? RUN kernel=$(ls /lib/modules | head -n1) && depmod -a "${kernel}" + +# Set empty machine-id +# This prevents systemd from thinking that the machine is on first boot +# and recreating /etc/ dependencies in services and such +# do this before initramfs so its in the initramfs +RUN echo "" > /etc/machine-id || true # Regenerate initrd if necessary, proper config files with immucore and custom initrd should already be in there installed by framework # for systemd distros RUN if [ -f "/usr/bin/dracut" ]; then \ @@ -269,7 +275,6 @@ RUN kernel=$(ls /boot/Image* 2>/dev/null | head -n1) && if [ -e "$kernel" ]; the # this is generally present on rhel based systems, but it doesn't hurt to remove in any case RUN rm -rf /boot/initramfs-* || true -RUN rm /etc/machine-id || true RUN rm /var/lib/dbus/machine-id || true RUN rm /etc/hostname || true diff --git a/images/Dockerfile.kairos-opensuse b/images/Dockerfile.kairos-opensuse index 4a9350377..d89873bee 100644 --- a/images/Dockerfile.kairos-opensuse +++ b/images/Dockerfile.kairos-opensuse @@ -245,6 +245,12 @@ RUN luet database get-all-installed --output /etc/kairos/versions.yaml # TODO what about caches? RUN kernel=$(ls /lib/modules | head -n1) && depmod -a "${kernel}" + +# Set empty machine-id +# This prevents systemd from thinking that the machine is on first boot +# and recreating /etc/ dependencies in services and such +# do this before initramfs so its in the initramfs +RUN echo "" > /etc/machine-id || true # Regenerate initrd if necessary, proper config files with immucore and custom initrd should already be in there installed by framework # for systemd distros RUN if [ -f "/usr/bin/dracut" ]; then \ @@ -265,7 +271,6 @@ RUN kernel=$(ls /boot/Image* 2>/dev/null | head -n1) && if [ -e "$kernel" ]; the # this is generally present on rhel based systems, but it doesn't hurt to remove in any case RUN rm -rf /boot/initramfs-* || true -RUN rm /etc/machine-id || true RUN rm /var/lib/dbus/machine-id || true RUN rm /etc/hostname || true diff --git a/images/Dockerfile.kairos-rhel b/images/Dockerfile.kairos-rhel index a0de9c841..0f0e05037 100644 --- a/images/Dockerfile.kairos-rhel +++ b/images/Dockerfile.kairos-rhel @@ -184,6 +184,12 @@ RUN luet database get-all-installed --output /etc/kairos/versions.yaml # TODO what about caches? RUN kernel=$(ls /lib/modules | head -n1) && depmod -a "${kernel}" + +# Set empty machine-id +# This prevents systemd from thinking that the machine is on first boot +# and recreating /etc/ dependencies in services and such +# do this before initramfs so its in the initramfs +RUN echo "" > /etc/machine-id || true # Regenerate initrd if necessary, proper config files with immucore and custom initrd should already be in there installed by framework # for systemd distros RUN if [ -f "/usr/bin/dracut" ]; then \ @@ -204,7 +210,6 @@ RUN kernel=$(ls /boot/Image* 2>/dev/null | head -n1) && if [ -e "$kernel" ]; the # this is generally present on rhel based systems, but it doesn't hurt to remove in any case RUN rm -rf /boot/initramfs-* || true -RUN rm /etc/machine-id || true RUN rm /var/lib/dbus/machine-id || true RUN rm /etc/hostname || true diff --git a/images/Dockerfile.kairos-ubuntu b/images/Dockerfile.kairos-ubuntu index ca9838b3e..4d339c419 100644 --- a/images/Dockerfile.kairos-ubuntu +++ b/images/Dockerfile.kairos-ubuntu @@ -450,6 +450,12 @@ RUN luet database get-all-installed --output /etc/kairos/versions.yaml # TODO what about caches? RUN kernel=$(ls /lib/modules | head -n1) && depmod -a "${kernel}" + +# Set empty machine-id +# This prevents systemd from thinking that the machine is on first boot +# and recreating /etc/ dependencies in services and such +# do this before initramfs so its in the initramfs +RUN echo "" > /etc/machine-id || true # Regenerate initrd if necessary, proper config files with immucore and custom initrd should already be in there installed by framework # for systemd distros RUN if [ -f "/usr/bin/dracut" ]; then \ @@ -470,7 +476,6 @@ RUN kernel=$(ls /boot/Image* 2>/dev/null | head -n1) && if [ -e "$kernel" ]; the # this is generally present on rhel based systems, but it doesn't hurt to remove in any case RUN rm -rf /boot/initramfs-* || true -RUN rm /etc/machine-id || true RUN rm /var/lib/dbus/machine-id || true RUN rm /etc/hostname || true