Skip to content

Commit

Permalink
Merge pull request #3205 from cgwalters/fix-grub-probing
Browse files Browse the repository at this point in the history
bootloader/grub2: Don't do anything if we have static configs
  • Loading branch information
cgwalters authored Feb 27, 2024
2 parents b4a1e38 + e47b370 commit f1e663b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/libostree/ostree-bootloader-grub2.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@

#include <string.h>

// Written by bootupd
#define BOOTUPD_CONFIG "boot/bootupd-state.json"
// Horrible hack, to avoid including a JSON parser we just grep for this
#define BOOTUPD_CONFIG_STATIC_JSON_FRAGMENT "\"static-configs\""

/* Maintain backwards compatibility with legacy GRUB
* installations that might rely on the -16 suffix
* for real-mode booting.
Expand Down Expand Up @@ -75,6 +80,22 @@ _ostree_bootloader_grub2_query (OstreeBootloader *bootloader, gboolean *out_is_a
{
OstreeBootloaderGrub2 *self = OSTREE_BOOTLOADER_GRUB2 (bootloader);

g_autoptr (GFile) bootupd_config
= g_file_resolve_relative_path (self->sysroot->path, BOOTUPD_CONFIG);
if (g_file_query_exists (bootupd_config, NULL))
{
g_autofree char *bootupd_config_contents = NULL;
if (!g_file_load_contents (bootupd_config, cancellable, &bootupd_config_contents, NULL, NULL,
error))
return glnx_prefix_error (error, "Failed to read bootupd config");
if (strstr (bootupd_config_contents, BOOTUPD_CONFIG_STATIC_JSON_FRAGMENT) != NULL)
{
g_debug ("Found static bootupd config");
*out_is_active = FALSE;
return TRUE;
}
}

/* Look for the BIOS path first */
if (g_file_query_exists (self->config_path_bios_1, NULL)
|| g_file_query_exists (self->config_path_bios_2, NULL))
Expand Down
36 changes: 36 additions & 0 deletions tests/kolainst/destructive/bootupd-static.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
set -xeuo pipefail

. ${KOLA_EXT_DATA}/libinsttest.sh

require_writable_sysroot
prepare_tmpdir

bootupd_state=/boot/bootupd-state.json
mount -o remount,rw /boot
if grep -qFe "\"static-configs\"" "${bootupd_state}"; then
echo "Host is using static configs already, overriding this"
jq 'del(.["static-configs"])' < "${bootupd_state}" > "${bootupd_state}".new
mv "${bootupd_state}.new" "${bootupd_state}"
fi

# Print the current value for reference, it's "none" on FCOS derivatives
ostree config get sysroot.bootloader || true
ostree config set sysroot.bootloader auto

ostree admin deploy --stage "${host_commit}"
systemctl stop ostree-finalize-staged.service
used_bootloader=$(journalctl -u ostree-finalize-staged -o json MESSAGE_ID=dd440e3e549083b63d0efc7dc15255f1 | tail -1 | jq -r .OSTREE_BOOTLOADER)
# We're verifying the legacy default now
assert_streq "${used_bootloader}" "grub2"
ostree admin undeploy 0

# Now synthesize a bootupd config which uses static configs
jq '. + {"static-configs": {}}' < "${bootupd_state}" > "${bootupd_state}".new
mv "${bootupd_state}.new" "${bootupd_state}"
ostree admin deploy --stage "${host_commit}"
systemctl stop ostree-finalize-staged.service
used_bootloader=$(journalctl -u ostree-finalize-staged -o json MESSAGE_ID=dd440e3e549083b63d0efc7dc15255f1 | tail -1 | jq -r .OSTREE_BOOTLOADER)
assert_streq "${used_bootloader}" "none"

echo "ok bootupd static"

0 comments on commit f1e663b

Please sign in to comment.