Introducing ostree-grub-generator
ostree-grub-generator can be used to customize the generated grub.cfg file. Compile time decision ostree-grub-generator vs grub2-mkconfig can be overwritten with the OSTREE_GRUB2_EXEC envvar - useful for auto tests and OS installers. Why this alternative approach: 1) The current approach is less flexible than using a custom 'ostree-grub-generator' script. Each system can adjust this script for its needs, instead of using the hardcoded values from ostree-bootloader-grub2.c. 2) Too much overhead on embedded to generate grub.cfg via /etc/grub.d/ configuration files. It is still possible to do so, even with this patch applied. No need to install grub2 package on a target device. 3) The grub2-mkconfig code path has other issues: https://bugzilla.gnome.org/show_bug.cgi?id=761180 Task: https://bugzilla.gnome.org/show_bug.cgi?id=762220 Closes: #228 Approved by: cgwalters
This commit is contained in:
1 parent
826c2149b8
commit
4e81548447
11 files changed
+187
-23
No files matched your search
File renamed without changes.
@@ -0,0 +1,101 @@
|
||||
#!/bin/sh
|
||||
|
||||
# To use a custrom script for generating grub.cfg, set the --with-grub2-mkconfig=no
|
||||
# configure switch when configuring and building OSTree.
|
||||
#
|
||||
# This script is called by ostree/src/libostree/ostree-bootloader-grub2.c whenever
|
||||
# boot loader configuration file needs to be updated. It can be used as a template
|
||||
# for a custom grub.cfg generator. What to consider when writing a custom grub.cfg
|
||||
# generator:
|
||||
#
|
||||
# - The populate_menu() function converts boot loader entries as defined by
|
||||
# https://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/ into GRUB2
|
||||
# menuentry sections. This is the core logic that is required by OSTree
|
||||
# based system.
|
||||
#
|
||||
# - Embedded systems: Be aware that this script is executed not only on a host machine by OS
|
||||
# installer, but also on a target device, thus think about shell portability. A target device
|
||||
# for example might be using busybox with a limited shell.
|
||||
#
|
||||
# Feel free to edit this script to fit your requirements.
|
||||
|
||||
set -e
|
||||
|
||||
script=$(basename ${0})
|
||||
# Atomically safe location where to generete grub.cfg when executing system upgrade.
|
||||
new_grub2_cfg=${2}
|
||||
entries_path=$(dirname $new_grub2_cfg)/entries
|
||||
|
||||
read_config()
|
||||
{
|
||||
config_file=${entries_path}/${1}
|
||||
title=""
|
||||
initrd=""
|
||||
options=""
|
||||
linux=""
|
||||
|
||||
while read -r line
|
||||
do
|
||||
record=$(echo ${line} | cut -f 1 -d ' ')
|
||||
value=$(echo ${line} | cut -s -f2- -d ' ')
|
||||
case "${record}" in
|
||||
"title")
|
||||
title=${value}
|
||||
;;
|
||||
"initrd")
|
||||
initrd=${value}
|
||||
;;
|
||||
"linux")
|
||||
linux=${value}
|
||||
;;
|
||||
"options")
|
||||
options=${value}
|
||||
;;
|
||||
esac
|
||||
done < ${config_file}
|
||||
|
||||
if [ -z "${title}" ]; then
|
||||
title="(Untitled)"
|
||||
fi
|
||||
}
|
||||
|
||||
populate_menu()
|
||||
{
|
||||
boot_prefix="${OSTREE_BOOT_PARTITION}"
|
||||
for config in $(ls ${entries_path}); do
|
||||
read_config ${config}
|
||||
menu="${menu}menuentry '${title}' {\n"
|
||||
menu="${menu}\t linux ${boot_prefix}${linux} ${options}\n"
|
||||
menu="${menu}\t initrd ${boot_prefix}${initrd}\n"
|
||||
menu="${menu}}\n\n"
|
||||
done
|
||||
# The printf command seems to be more reliable across shells for special character (\n, \t) evaluation
|
||||
printf "$menu" >> ${new_grub2_cfg}
|
||||
}
|
||||
|
||||
populate_warning()
|
||||
{
|
||||
cat >> ${new_grub2_cfg} <<EOF
|
||||
# This file was generated by ${script}. Do not modify the generated file - all changes will
|
||||
# be lost the next time file is regenerated. For more details refer to the ${script} script.
|
||||
EOF
|
||||
}
|
||||
|
||||
populate_header()
|
||||
{
|
||||
cat >> ${new_grub2_cfg} <<EOF
|
||||
serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1
|
||||
default=boot
|
||||
timeout=10
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
generate_grub2_cfg()
|
||||
{
|
||||
populate_warning
|
||||
populate_header
|
||||
populate_menu
|
||||
}
|
||||
|
||||
generate_grub2_cfg
|
||||
@@ -299,8 +299,25 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
|
||||
g_autofree char *bootversion_str = g_strdup_printf ("%u", (guint)bootversion);
|
||||
g_autoptr(GFile) config_path_efi_dir = NULL;
|
||||
g_autofree char *grub2_mkconfig_chroot = NULL;
|
||||
gboolean use_system_grub2_mkconfig = TRUE;
|
||||
const gchar *grub_exec = NULL;
|
||||
|
||||
if (ostree_sysroot_get_booted_deployment (self->sysroot) == NULL
|
||||
#ifdef USE_BUILTIN_GRUB2_MKCONFIG
|
||||
use_system_grub2_mkconfig = FALSE;
|
||||
#endif
|
||||
/* Autotests can set this envvar to select which code path to test, useful for OS installers as well */
|
||||
grub_exec = g_getenv ("OSTREE_GRUB2_EXEC");
|
||||
if (grub_exec)
|
||||
{
|
||||
if (g_str_has_suffix (grub_exec, GRUB2_MKCONFIG_PATH))
|
||||
use_system_grub2_mkconfig = TRUE;
|
||||
else
|
||||
use_system_grub2_mkconfig = FALSE;
|
||||
}
|
||||
else
|
||||
grub_exec = use_system_grub2_mkconfig ? GRUB2_MKCONFIG_PATH : LIBEXECDIR "/ostree-grub-generator";
|
||||
|
||||
if (use_system_grub2_mkconfig && ostree_sysroot_get_booted_deployment (self->sysroot) == NULL
|
||||
&& g_file_has_parent (self->sysroot->path, NULL))
|
||||
{
|
||||
g_autoptr(GPtrArray) deployments = NULL;
|
||||
@@ -318,6 +335,9 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
|
||||
*
|
||||
* In the case of an installer, use the first deployment root (which
|
||||
* will most likely be the only one.
|
||||
*
|
||||
* This all only applies if we're not using the builtin
|
||||
* generator, which handles being run outside of the root.
|
||||
*/
|
||||
tool_deployment_root = ostree_sysroot_get_deployment_directory (self->sysroot, tool_deployment);
|
||||
grub2_mkconfig_chroot = g_file_get_path (tool_deployment_root);
|
||||
@@ -361,7 +381,7 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader,
|
||||
Upstream is fixed though.
|
||||
*/
|
||||
proc = g_subprocess_launcher_spawn (launcher, error,
|
||||
"grub2-mkconfig", "-o",
|
||||
grub_exec, "-o",
|
||||
gs_file_get_path_cached (new_config_path),
|
||||
NULL);
|
||||
|
||||
|
||||
Reference in new issue
Block a user