Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure update boot configuration for each deployment #7

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
ostree (2024.6-1deepin5) unstable; urgency=medium

* fix: ensure update boot configuration for each deployment.

-- lichenggang <[email protected]> Thu, 24 Oct 2024 09:55:46 +0800

ostree (2024.6-1deepin4) unstable; urgency=medium

* use a custom grub message
Expand Down
65 changes: 54 additions & 11 deletions debian/patches/deepin-use-custom-grub-message.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
diff --git a/src/libostree/ostree-bootloader-grub2.c b/src/libostree/ostree-bootloader-grub2.c
index cbe7605..2015bf5 100644
--- a/src/libostree/ostree-bootloader-grub2.c
+++ b/src/libostree/ostree-bootloader-grub2.c
Index: ostree/src/libostree/ostree-bootloader-grub2.c
===================================================================
--- ostree.orig/src/libostree/ostree-bootloader-grub2.c
+++ ostree/src/libostree/ostree-bootloader-grub2.c
@@ -25,6 +25,8 @@
#include <sys/mount.h>

Expand All @@ -11,7 +11,7 @@ index cbe7605..2015bf5 100644

// Written by bootupd
#define BOOTUPD_CONFIG "boot/bootupd-state.json"
@@ -166,6 +168,67 @@ _ostree_bootloader_grub2_get_name (OstreeBootloader *bootloader)
@@ -166,6 +168,71 @@ _ostree_bootloader_grub2_get_name (Ostre
return "grub2";
}

Expand Down Expand Up @@ -43,7 +43,11 @@ index cbe7605..2015bf5 100644
+{
+ GPtrArray *deployments = sysroot->deployments;
+
+ if (index >= deployments->len)
+ /* Check if the index exceeds the deployment array length, allowing one extra
+ * index if 'stage_deploy_time' is true.
+ * For the first time to boot, index could be 1 even if there's only one deployment.
+ */
+ if (index >= deployments->len + (stage_deploy_time ? 1 : 0))
+ return title;
+
+ g_autofree char *deploy_time = NULL;
Expand Down Expand Up @@ -79,23 +83,23 @@ index cbe7605..2015bf5 100644
/* This implementation is quite complex; see this issue for
* a starting point:
* https://github.com/ostreedev/ostree/issues/717
@@ -180,6 +243,7 @@ _ostree_bootloader_grub2_generate_config (OstreeSysroot *sysroot, int bootversio
@@ -181,6 +248,7 @@ _ostree_bootloader_grub2_generate_config
static const char hardcoded_insmods[] = "insmod gzio\n";
const char *grub2_boot_device_id = g_getenv ("GRUB2_BOOT_DEVICE_ID");
const char *grub2_prepare_root_cache = g_getenv ("GRUB2_PREPARE_ROOT_CACHE");
+ const char *stage_deploy_time = g_getenv ("OSTREE_STAGE_DEPLOY_TIME");

/* We must have been called via the wrapper script */
g_assert (grub2_boot_device_id != NULL);
@@ -214,6 +278,7 @@ _ostree_bootloader_grub2_generate_config (OstreeSysroot *sysroot, int bootversio
@@ -216,6 +284,7 @@ _ostree_bootloader_grub2_generate_config

kernel = ostree_bootconfig_parser_get (config, "linux");

+ title = ostree_update_grub_boot_message(sysroot, stage_deploy_time, title, i);
quoted_title = g_shell_quote (title);
uuid = g_strdup_printf ("ostree-%u-%s", (guint)i, grub2_boot_device_id);
quoted_uuid = g_shell_quote (uuid);
@@ -285,6 +350,8 @@ typedef struct
@@ -289,6 +358,8 @@ typedef struct
{
const char *root;
const char *bootversion_str;
Expand All @@ -104,7 +108,7 @@ index cbe7605..2015bf5 100644
gboolean is_efi;
} Grub2ChildSetupData;

@@ -299,6 +366,8 @@ grub2_child_setup (gpointer user_data)
@@ -303,6 +374,8 @@ grub2_child_setup (gpointer user_data)
if (cdata->is_efi)
setenv ("_OSTREE_GRUB2_IS_EFI", "1", TRUE);

Expand All @@ -113,7 +117,7 @@ index cbe7605..2015bf5 100644
/* Everything below this is dealing with the chroot case; if
* we're not doing that, return early.
*/
@@ -425,6 +494,11 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader, int bootver
@@ -429,6 +502,11 @@ _ostree_bootloader_grub2_write_config (O
g_autofree char *bootversion_str = g_strdup_printf ("%u", (guint)bootversion);
cdata.bootversion_str = bootversion_str;
cdata.is_efi = self->is_efi;
Expand All @@ -125,3 +129,42 @@ index cbe7605..2015bf5 100644
/* Note in older versions of the grub2 package, this script doesn't even try
to be atomic; it just does:

Index: ostree/src/libostree/ostree-sysroot-deploy.c
===================================================================
--- ostree.orig/src/libostree/ostree-sysroot-deploy.c
+++ ostree/src/libostree/ostree-sysroot-deploy.c
@@ -2842,6 +2842,25 @@ auto_early_prune_old_deployments (Ostree
return TRUE;
}

+static void
+ostree_update_grub_configuration(OstreeSysroot *self)
+{
+ g_autoptr(OstreeBootloader) bootloader = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GCancellable) cancellable = NULL;
+
+ if (!_ostree_sysroot_query_bootloader(self, &bootloader, cancellable, &error)
+ || !bootloader || g_strcmp0(_ostree_bootloader_get_name(bootloader), "grub2") != 0)
+ return;
+
+ g_autofree gchar *error_output = NULL;
+ gboolean ret = g_spawn_command_line_sync("update-grub", NULL, &error_output, NULL, NULL);
+ if (ret)
+ ot_journal_print(LOG_INFO, "update grub configuration successfully");
+ else
+ ot_journal_print(LOG_ERR, "failed to update grub configuration: %s", error_output);
+}
+
/**
* ostree_sysroot_write_deployments_with_options:
* @self: Sysroot
@@ -3022,6 +3041,8 @@ ostree_sysroot_write_deployments_with_op
return FALSE;

bootloader_is_atomic = TRUE;
+
+ ostree_update_grub_configuration(self);
}
else
{
Loading