Skip to content

Commit

Permalink
35coreos-ignition: handle the case where booted kargs don't match des…
Browse files Browse the repository at this point in the history
…ired

Today when you boot a system it's possible a value for a karg you
specified in the Ignition config matches the BLS config but not the
kargs from the current boot (in /proc/cmdline). Let's detect this and
reboot in that case too.
  • Loading branch information
dustymabe committed Jan 11, 2022
1 parent f9da653 commit 929203b
Showing 1 changed file with 46 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,60 @@
#!/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 "$@"

# There are a few cases we need to handle here. To illustrate this
# we'll use scenarios below where:
#
# - "booted": The kernel arguments from the currently booting system.
# - "ignition": The kernel arguments in the Ignition configuration.
# - "bls": The kernel arguments currently baked into the disk
# image BLS configs.
#
# The scenarios are:
#
# A.
# - Scenario:
# - booted: ""
# - ignition: "foobar"
# - bls: ""
# - Action: -> Update BLS configs, perform reboot
# B.
# - Scenario:
# - booted: "foobar"
# - ignition: "foobar"
# - bls: ""
# - Action: -> Update BLS configs, skip reboot
# C.
# - Scenario:
# - booted: ""
# - ignition: "foobar"
# - bls: "foobar"
# - Action: -> Skip update of BLS configs (they match already), perform reboot
#
# The logic here boils down to:
# if "ignition" != "booted"; then needreboot=1; fi
# if "ignition" != "bls"; then updatebls(); fi



# If the desired state isn't reflected by the current boot we'll need to reboot.
/usr/bin/rdcore kargs --current --create-if-changed /run/coreos-kargs-reboot "$@"
if [ -e /run/coreos-kargs-reboot ]; then
msg="Desired kernel arguments don't match current boot. Requesting reboot."
systemd-cat -t coreos-kargs <<< "$msg"
fi

if is-live-image; 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
if [ -e /run/coreos-kargs-reboot ]; then
echo "Need to modify kernel arguments, but cannot affect live system." >&2
exit 1
fi
else
# Update the BLS configs if they need to be updated.
/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.
#
# Note we write info messages via systemd-cat here because stdout gets swallowed
# by Ignition if there is no failure. This forces the info into the journal.
if [ -e /run/coreos-kargs-changed ]; then
if [ -e /run/coreos-kargs-thisboot-differ ]; then
msg="Kernel arguments were changed. Requesting reboot."
systemd-cat -t coreos-kargs <<< "$msg"
touch /run/coreos-kargs-reboot
else
msg="Kernel arguments were changed, but they match this boot. Skipping reboot."
systemd-cat -t coreos-kargs <<< "$msg"
fi
msg="Kernel arguments in BLS config were updated."
systemd-cat -t coreos-kargs <<< "$msg"
fi
fi

0 comments on commit 929203b

Please sign in to comment.