grub2: Generate config from pending deployment

Generate a grub2 config using the pending deployment, if a grub2
bootloader is detected in the sysroot. Allows grub2-mkconfig
to run if there are no previous deployments.

Fixes: #1774

Closes: #1831
Approved by: jlebon
This commit is contained in:
Robert Fairley 2019-03-14 19:16:07 -04:00 committed by Atomic Bot
parent 42573eae59
commit d69214ade3
6 changed files with 23 additions and 17 deletions

View File

@ -332,6 +332,7 @@ grub2_child_setup (gpointer user_data)
static gboolean static gboolean
_ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader, _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
int bootversion, int bootversion,
GPtrArray *new_deployments,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
@ -357,15 +358,11 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
if (use_system_grub2_mkconfig && ostree_sysroot_get_booted_deployment (self->sysroot) == NULL if (use_system_grub2_mkconfig && ostree_sysroot_get_booted_deployment (self->sysroot) == NULL
&& g_file_has_parent (self->sysroot->path, NULL)) && g_file_has_parent (self->sysroot->path, NULL))
{ {
g_autoptr(GPtrArray) deployments = NULL;
OstreeDeployment *tool_deployment; OstreeDeployment *tool_deployment;
g_autoptr(GFile) tool_deployment_root = NULL; g_autoptr(GFile) tool_deployment_root = NULL;
deployments = ostree_sysroot_get_deployments (self->sysroot); g_assert_cmpint (new_deployments->len, >, 0);
tool_deployment = new_deployments->pdata[0];
g_assert_cmpint (deployments->len, >, 0);
tool_deployment = deployments->pdata[0];
/* Sadly we have to execute code to generate the bootloader configuration. /* Sadly we have to execute code to generate the bootloader configuration.
* If we're in a booted deployment, we just don't chroot. * If we're in a booted deployment, we just don't chroot.
@ -380,6 +377,8 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
grub2_mkconfig_chroot = g_file_get_path (tool_deployment_root); grub2_mkconfig_chroot = g_file_get_path (tool_deployment_root);
} }
g_debug ("Using grub2-mkconfig chroot: %s\n", grub2_mkconfig_chroot);
g_autoptr(GFile) new_config_path = NULL; g_autoptr(GFile) new_config_path = NULL;
g_autoptr(GFile) config_path_efi_dir = NULL; g_autoptr(GFile) config_path_efi_dir = NULL;
if (self->is_efi) if (self->is_efi)

View File

@ -108,10 +108,11 @@ append_config_from_loader_entries (OstreeBootloaderSyslinux *self,
} }
static gboolean static gboolean
_ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader, _ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader,
int bootversion, int bootversion,
GCancellable *cancellable, GPtrArray *new_deployments,
GError **error) GCancellable *cancellable,
GError **error)
{ {
OstreeBootloaderSyslinux *self = OSTREE_BOOTLOADER_SYSLINUX (bootloader); OstreeBootloaderSyslinux *self = OSTREE_BOOTLOADER_SYSLINUX (bootloader);

View File

@ -158,10 +158,11 @@ create_config_from_boot_loader_entries (OstreeBootloaderUboot *self,
} }
static gboolean static gboolean
_ostree_bootloader_uboot_write_config (OstreeBootloader *bootloader, _ostree_bootloader_uboot_write_config (OstreeBootloader *bootloader,
int bootversion, int bootversion,
GCancellable *cancellable, GPtrArray *new_deployments,
GError **error) GCancellable *cancellable,
GError **error)
{ {
OstreeBootloaderUboot *self = OSTREE_BOOTLOADER_UBOOT (bootloader); OstreeBootloaderUboot *self = OSTREE_BOOTLOADER_UBOOT (bootloader);

View File

@ -54,13 +54,15 @@ _ostree_bootloader_get_name (OstreeBootloader *self)
gboolean gboolean
_ostree_bootloader_write_config (OstreeBootloader *self, _ostree_bootloader_write_config (OstreeBootloader *self,
int bootversion, int bootversion,
GPtrArray *new_deployments,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
g_return_val_if_fail (OSTREE_IS_BOOTLOADER (self), FALSE); g_return_val_if_fail (OSTREE_IS_BOOTLOADER (self), FALSE);
return OSTREE_BOOTLOADER_GET_IFACE (self)->write_config (self, bootversion, return OSTREE_BOOTLOADER_GET_IFACE (self)->write_config (self, bootversion,
cancellable, error); new_deployments,
cancellable, error);
} }
gboolean gboolean

View File

@ -44,6 +44,7 @@ struct _OstreeBootloaderInterface
const char * (* get_name) (OstreeBootloader *self); const char * (* get_name) (OstreeBootloader *self);
gboolean (* write_config) (OstreeBootloader *self, gboolean (* write_config) (OstreeBootloader *self,
int bootversion, int bootversion,
GPtrArray *new_deployments,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);
gboolean (* is_atomic) (OstreeBootloader *self); gboolean (* is_atomic) (OstreeBootloader *self);
@ -61,6 +62,7 @@ const char *_ostree_bootloader_get_name (OstreeBootloader *self);
gboolean _ostree_bootloader_write_config (OstreeBootloader *self, gboolean _ostree_bootloader_write_config (OstreeBootloader *self,
int bootversion, int bootversion,
GPtrArray *new_deployments,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);

View File

@ -2122,7 +2122,8 @@ write_deployments_bootswap (OstreeSysroot *self,
if (bootloader) if (bootloader)
{ {
if (!_ostree_bootloader_write_config (bootloader, new_bootversion, if (!_ostree_bootloader_write_config (bootloader, new_bootversion,
cancellable, error)) new_deployments, cancellable,
error))
return glnx_prefix_error (error, "Bootloader write config"); return glnx_prefix_error (error, "Bootloader write config");
} }