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
[merged] Introducing ostree-grub-generator #228
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the sort of thing where we should probably have a config file at least for any general purpose use. It's basically what I guess this is where things are a bit nicer with the state we have with syslinux where the ostree-syslinux code edits just the entries in there, otherwise admins can edit it by hand. But that's only really possible because the syslinux format is easy to parse, which is definitely not true of grub2 😦 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, looks like it. This definitely can be improved further by Atomic project or whoever else decides that they need it first :)
I want to achieve similar funcionality in the u-boot backend by this patch: |
||
EOF | ||
} | ||
|
||
generate_grub2_cfg() | ||
{ | ||
populate_warning | ||
populate_header | ||
populate_menu | ||
} | ||
|
||
generate_grub2_cfg |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../src/boot/grub2/ostree-grub-generator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a clear enough script, but it's tempting to move the logic into C, basically what we're doing in the syslinux/u-boot ones. We don't have to do that now though, and shell script is convenient for customization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant here is that this logic could be implemented entirely in ostree. Instead of working on making a GRUB2 builtin BLS loader more configurable, there could be a C binary (configurable) in ostree project that does what normally would be the job of "GRUB2 builtin BLS loader".
Then we could reuse the same code path what is currently used by ostree-grub-generator. Where ostree instead of executing ostree-grub-generator shell script would execute the above mentioned C binary. The benefit would be that the code is better localized. Probably there are some benefits at developing this upstream (in grub2 repo) too.
Hopefully this clarifies it better.