From 78af4ee6be02fa60b6d44213fb05dc7fce355048 Mon Sep 17 00:00:00 2001 From: Robert Fairley Date: Thu, 14 Mar 2019 19:16:07 -0400 Subject: [PATCH] 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 --- src/libostree/ostree-bootloader-grub2.c | 8 +++++--- src/libostree/ostree-bootloader-syslinux.c | 9 +++++---- src/libostree/ostree-bootloader-uboot.c | 9 +++++---- src/libostree/ostree-bootloader.c | 6 ++++-- src/libostree/ostree-bootloader.h | 2 ++ src/libostree/ostree-sysroot-deploy.c | 3 ++- tests/test-admin-deploy-grub2.sh | 17 ++++++++++++++++- 7 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/libostree/ostree-bootloader-grub2.c b/src/libostree/ostree-bootloader-grub2.c index 57673c7d6b..ae0d3c0f59 100644 --- a/src/libostree/ostree-bootloader-grub2.c +++ b/src/libostree/ostree-bootloader-grub2.c @@ -332,6 +332,7 @@ grub2_child_setup (gpointer user_data) static gboolean _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader, int bootversion, + GPtrArray *new_deployments, GCancellable *cancellable, GError **error) { @@ -363,9 +364,8 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader, deployments = ostree_sysroot_get_deployments (self->sysroot); - g_assert_cmpint (deployments->len, >, 0); - - tool_deployment = deployments->pdata[0]; + g_assert_cmpint (new_deployments->len, > , 0); + tool_deployment = new_deployments->pdata[0]; /* Sadly we have to execute code to generate the bootloader configuration. * If we're in a booted deployment, we just don't chroot. @@ -380,6 +380,8 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader, 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) config_path_efi_dir = NULL; if (self->is_efi) diff --git a/src/libostree/ostree-bootloader-syslinux.c b/src/libostree/ostree-bootloader-syslinux.c index 8b09a861b2..5fb8a1dbd2 100644 --- a/src/libostree/ostree-bootloader-syslinux.c +++ b/src/libostree/ostree-bootloader-syslinux.c @@ -108,10 +108,11 @@ append_config_from_loader_entries (OstreeBootloaderSyslinux *self, } static gboolean -_ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader, - int bootversion, - GCancellable *cancellable, - GError **error) +_ostree_bootloader_syslinux_write_config (OstreeBootloader *bootloader, + int bootversion, + GPtrArray *new_deployments, + GCancellable *cancellable, + GError **error) { OstreeBootloaderSyslinux *self = OSTREE_BOOTLOADER_SYSLINUX (bootloader); diff --git a/src/libostree/ostree-bootloader-uboot.c b/src/libostree/ostree-bootloader-uboot.c index 531a375600..87a9380678 100644 --- a/src/libostree/ostree-bootloader-uboot.c +++ b/src/libostree/ostree-bootloader-uboot.c @@ -158,10 +158,11 @@ create_config_from_boot_loader_entries (OstreeBootloaderUboot *self, } static gboolean -_ostree_bootloader_uboot_write_config (OstreeBootloader *bootloader, - int bootversion, - GCancellable *cancellable, - GError **error) +_ostree_bootloader_uboot_write_config (OstreeBootloader *bootloader, + int bootversion, + GPtrArray *new_deployments, + GCancellable *cancellable, + GError **error) { OstreeBootloaderUboot *self = OSTREE_BOOTLOADER_UBOOT (bootloader); diff --git a/src/libostree/ostree-bootloader.c b/src/libostree/ostree-bootloader.c index 87823f7ea5..5b8125dcc4 100644 --- a/src/libostree/ostree-bootloader.c +++ b/src/libostree/ostree-bootloader.c @@ -54,13 +54,15 @@ _ostree_bootloader_get_name (OstreeBootloader *self) gboolean _ostree_bootloader_write_config (OstreeBootloader *self, int bootversion, + GPtrArray *new_deployments, GCancellable *cancellable, GError **error) { g_return_val_if_fail (OSTREE_IS_BOOTLOADER (self), FALSE); - return OSTREE_BOOTLOADER_GET_IFACE (self)->write_config (self, bootversion, - cancellable, error); + return OSTREE_BOOTLOADER_GET_IFACE (self)->write_config (self, bootversion, + new_deployments, + cancellable, error); } gboolean diff --git a/src/libostree/ostree-bootloader.h b/src/libostree/ostree-bootloader.h index a4793b08c8..5af2dcc8a3 100644 --- a/src/libostree/ostree-bootloader.h +++ b/src/libostree/ostree-bootloader.h @@ -44,6 +44,7 @@ struct _OstreeBootloaderInterface const char * (* get_name) (OstreeBootloader *self); gboolean (* write_config) (OstreeBootloader *self, int bootversion, + GPtrArray *new_deployments, GCancellable *cancellable, GError **error); gboolean (* is_atomic) (OstreeBootloader *self); @@ -61,6 +62,7 @@ const char *_ostree_bootloader_get_name (OstreeBootloader *self); gboolean _ostree_bootloader_write_config (OstreeBootloader *self, int bootversion, + GPtrArray *new_deployments, GCancellable *cancellable, GError **error); diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index d37861b7ba..22aa4a4385 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -2122,7 +2122,8 @@ write_deployments_bootswap (OstreeSysroot *self, if (bootloader) { if (!_ostree_bootloader_write_config (bootloader, new_bootversion, - cancellable, error)) + new_deployments, cancellable, + error)) return glnx_prefix_error (error, "Bootloader write config"); } diff --git a/tests/test-admin-deploy-grub2.sh b/tests/test-admin-deploy-grub2.sh index 231aa2f821..bfb8a89637 100755 --- a/tests/test-admin-deploy-grub2.sh +++ b/tests/test-admin-deploy-grub2.sh @@ -26,6 +26,21 @@ set -euo pipefail # Exports OSTREE_SYSROOT so --sysroot not needed. setup_os_repository "archive" "grub2 ostree-grub-generator" -extra_admin_tests=0 +extra_admin_tests=1 . $(dirname $0)/admin-test.sh + +# Check that deploying a new tree with zero previous deployments works. +# (see https://github.com/ostreedev/ostree/issues/1774). +cd ${test_tmpdir} +rm httpd osdata testos-repo sysroot -rf +setup_os_repository "archive" "grub2 ostree-grub-generator" +${CMD_PREFIX} ostree pull-local --repo=sysroot/ostree/repo --remote testos testos-repo testos/buildmaster/x86_64-runtime +# Make OSTree detect the grub2 bootloader. +mkdir -p sysroot/boot/grub2 && touch sysroot/boot/grub2/grub.cfg +${CMD_PREFIX} ostree admin deploy --karg=root=LABEL=MOO --karg=quiet --os testos testos/buildmaster/x86_64-runtime > out.txt +assert_file_has_content out.txt "Bootloader updated.*" +assert_file_has_content sysroot/boot/loader/entries/ostree-1-testos.conf 'options.* root=LABEL=MOO' +assert_file_has_content sysroot/boot/ostree/testos-${bootcsum}/vmlinuz-3.6.0 'a kernel' +assert_file_has_content sysroot/boot/ostree/testos-${bootcsum}/initramfs-3.6.0.img 'an initramfs' +echo "ok run grub2 bootloader on first deployment"