From 06bae91f306114880b670e6300a0fc63de13ce15 Mon Sep 17 00:00:00 2001 From: Dusty Mabe Date: Fri, 7 Jan 2022 12:07:09 -0500 Subject: [PATCH] 35coreos-ignition: skip reboot if changed kargs match current boot If the requested kernel arguments in the Ignition config already match the kernel arguments of the currently booted system then let's skip the reboot because the reboot won't change anything. One example of a use of this would be if someone is doing a PXE install and they want to persistently use `net.ifnames=0`. They apply `net.ifnames=0` on the PXE boot and coreos-installer transparently forwards it to the Ignition boot (for a single boot). Then the Ignition config has `net.ifnames=0` set in the kernel arguments section. ignition-kargs.service will take care of setting it persistently, but without this change the system will be rebooted. With this change we skip the reboot. --- .../35coreos-ignition/coreos-kargs.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-kargs.sh b/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-kargs.sh index 1dcc3add13..e5a8d26702 100755 --- a/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-kargs.sh +++ b/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-kargs.sh @@ -1,12 +1,25 @@ #!/bin/bash set -euo pipefail +# First check to see if the requested state is satisfied by the current boot +/usr/bin/rdcore kargs --current --create-if-changed /run/coreos-kargs-thisboot-differ "$@" + if is-live-image; then - /usr/bin/rdcore kargs --current --create-if-changed /run/coreos-kargs-changed "$@" - if [ -e /run/coreos-kargs-changed ]; then + # If we're in a live system and the kargs don't match then we must error. + if [ -e /run/coreos-kargs-thisboot-differ ]; then echo "Need to modify kernel arguments, but cannot affect live system." >&2 exit 1 fi else - /usr/bin/rdcore kargs --boot-device /dev/disk/by-label/boot --create-if-changed /run/coreos-kargs-reboot "$@" + /usr/bin/rdcore kargs --boot-device /dev/disk/by-label/boot --create-if-changed /run/coreos-kargs-changed "$@" + # If the bootloader was changed and the kernel arguments don't match this boot + # then we must reboot. If they do match this boot then we can skip the reboot. + if [ -e /run/coreos-kargs-changed ]; then + if [ -e /run/coreos-kargs-thisboot-differ ]; then + echo "Kernel arguments were changed. Requesting reboot." + touch /run/coreos-kargs-reboot + else + echo "Kernel arguments were changed, but they match this boot. Skipping reboot." + fi + fi fi