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

ostree-grub-generator: allow adding custom scripts to grub.cfg #3162

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

EdTheBearded
Copy link

Hello!
I would like to propose this change here, since this may help someone else.

First the motivation for this change: rollback
We wanted to be able to perform a rollback if our update was unsuccessful in some way. And for that we needed to add some logic to grub.cfg script to get it done.

With that in mind, I tried to do this without changing too much or just manually editing grub.cfg. I took some inspiration on what grub-mkconfig does: check /etc/grub.d for custom scripts, and add those to the final grub.cfg script, parsing the files in their alphabetical order.

So with this change, whatever files found under /etc/ostree.d (just went with whatever name at the time) are added (in alphabetical order) between the cfg header and its menuentries, allowing to add custom logic to the bootloader in a non intrusive way.

NOTE: we're using this on Yocto, so there's also a minor change to be done in ostree recipe, to create the /etc folder being used.

This changes allow us to customize grub.cfg without manually editing it.

Now, whatever files found under /etc/ostree.d are added (in alphabetical
order) between the cfg header and its menuentries, allowing to add
custom logic to the bootloader in a non intrusive way.

Signed-off-by: Eduardo Ferreira <eduardo.barbosa@toradex.com>
Copy link

openshift-ci bot commented Feb 8, 2024

Hi @EdTheBearded. Thanks for your PR.

I'm waiting for a ostreedev member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@cgwalters
Copy link
Member

I'm not opposed exactly, but I don't quite understand. grub has a fully generic system for injecting code, why can't you drop your extra stuff into the existing /etc/grub.d?

On the topic of configuring rollbacks and grub configs, you may also want to look into https://github.com/coreos/bootupd/ which is intended to pair with ostree - bootupd supports an opinionated "static grub config" model where we don't regenerate any grub configs when updating the kernel, assuming GRUB has been patched to read from /boot/loader/entries directly.

Also, there is https://github.com/fedora-iot/greenboot/ (currently relies on rpm-ostree, not ostree, but that is conceptually a bug) which also now injects some grub logic via bootupd, see fedora-iot/greenboot#129

@@ -25,6 +25,7 @@ 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
custom_scripts="/etc/ostree.d"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it should be e.g. /etc/ostree-grub.d or so.

@cgwalters cgwalters added needinfo This issue needs more information from the reporter reviewed/needs-rework labels Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needinfo This issue needs more information from the reporter needs-ok-to-test reviewed/needs-rework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants