-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
35coreos-ignition: handle the case where booted kargs don't match des…
…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
Showing
1 changed file
with
46 additions
and
16 deletions.
There are no files selected for viewing
62 changes: 46 additions & 16 deletions
62
overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-kargs.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |