forked from rear/rear
-
Notifications
You must be signed in to change notification settings - Fork 0
BCF-6655: Default GRUB boot entry is changed after BMR #86
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
Anastasiya Kapskaya (NastyaKapskaya)
merged 2 commits into
develop
from
feature/BCF-6655-default-grub-boot-entry-is-changed-after-bmr
Mar 27, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Set up grubenv (GRUB environment block) | ||
|
|
||
| function set_grubenv() { | ||
| local grubenv_file="$VAR_DIR/recovery/grubenv" | ||
|
|
||
| # A non-existing grubenv_file is considered OK because it exists only | ||
| # if env_block was set. | ||
| if [ ! -f "$grubenv_file" ]; then | ||
| return 0 | ||
| fi | ||
|
|
||
| local grub_editenv | ||
| if ! grub_editenv=$(get_grub_editenv); then | ||
| LogPrintError "Failed to set grubenv: neither grub-editenv nor grub2-editenv was found" | ||
| return 1 | ||
| fi | ||
|
|
||
| # Remove grubenv from the restored filesystem before setting variables | ||
| local restored_grubenv | ||
| for restored_grubenv in /boot/grub2/grubenv /boot/grub/grubenv; do | ||
| restored_grubenv="${TARGET_FS_ROOT}${restored_grubenv}" | ||
| if [ -f "$restored_grubenv" ]; then | ||
| rm "$restored_grubenv" | ||
| Log "'$restored_grubenv' was removed" | ||
| fi | ||
| done | ||
|
|
||
| # It is essential to set up the environment block in the reserved btrfs sector | ||
| # See https://en.opensuse.org/GRUB#GRUB2_on_btrfs_/boot for more details | ||
| chroot "$TARGET_FS_ROOT" /bin/bash -c "\"$grub_editenv\" - unset dummy" | ||
|
|
||
| local exit_code=0 | ||
| local var_value | ||
| while IFS= read -r var_value; do | ||
| local var="${var_value%=*}" | ||
| # env_block is read-only after initialization | ||
| if [ "$var" = "env_block" ] ; then | ||
| continue | ||
| fi | ||
| if ! chroot "$TARGET_FS_ROOT" /bin/bash -c "\"$grub_editenv\" - set \"$var_value\""; then | ||
| LogPrintError "Failed to set '$var_value' to grubenv" | ||
|
svlv marked this conversation as resolved.
|
||
| exit_code=1 | ||
| fi | ||
| done < "$grubenv_file" | ||
|
|
||
| if [ $exit_code -eq 0 ]; then | ||
| Log "grubenv was set successfully" | ||
| fi | ||
|
|
||
| return $exit_code | ||
| } | ||
|
|
||
| if is_grub2_used; then | ||
| set_grubenv | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # Save grubenv (GRUB environment block) to $VAR_DIR/recovery/grubenv. | ||
| # See https://www.gnu.org/software/grub/manual/grub/html_node/Environment-block.html | ||
| # for more details about grubenv. | ||
|
|
||
| function list_grubenv() { | ||
| local grub_editenv | ||
| if ! grub_editenv=$(get_grub_editenv); then | ||
| LogPrintError "Failed to list grubenv: neither grub-editenv nor grub2-editenv was found" | ||
| return 1 | ||
| fi | ||
|
|
||
| "$grub_editenv" - list | ||
| } | ||
|
|
||
| # env_block sets the external raw block where GRUB can store environment block. | ||
| # See https://www.gnu.org/software/grub/manual/grub/html_node/env_005fblock.html | ||
| # for more details about env_block. | ||
| function is_fs_envblock_used() { | ||
| list_grubenv | grep -q "^env_block=" | ||
| } | ||
|
|
||
| function save_grubenv() { | ||
| local grubenv_file="$VAR_DIR/recovery/grubenv" | ||
|
|
||
| if ! list_grubenv > "$grubenv_file"; then | ||
| LogPrintError "Failed to save grubenv to '$grubenv_file'" | ||
| return 1 | ||
| fi | ||
|
|
||
| Log "grubenv was successfully saved to '$grubenv_file'" | ||
| return 0 | ||
| } | ||
|
|
||
| # Save grubenv only if Btrfs envblock is used, because the envblock | ||
| # located in the Btrfs header is not accessible during recovery. In other cases, | ||
| # the envblock is located at /boot/grub/envblock or /boot/grub2/envblock, | ||
| # which is backed up and restored as a regular file. | ||
| if is_grub2_used && is_fs_envblock_used; then | ||
| save_grubenv | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.