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

Add boot counting #24

Merged
merged 2 commits into from
Jul 31, 2018
Merged

Add boot counting #24

merged 2 commits into from
Jul 31, 2018

Conversation

LorbusChris
Copy link
Contributor

@LorbusChris LorbusChris commented Jul 25, 2018

Introduces a boot_counter env var that counts down boot attempts to 0.

If 0 is reached it will set default=1 to boot the next older entry once (I don't need to set boot_once here for this, do I?)

Also introduces a fallback_active var that is set to true in this case, to make it easy to determine from userspace that this is a fallback boot.

As I need the automatic boot_success reset mechanism in all cases, I put this in 00_menu_auto_hide.in for now.

Use case: https://github.com/LorbusChris/greenboot/pull/16

RFC please
@jwrdegoede @dustymabe @jlebon @nullr0ute

save_env boot_counter
fi
fi

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this belong to 00_menu_auto_hide.in, since this an independent feature I would add it in a new script file (i.e: 01_fallback_support).

That way we can for example ship the menu auto hide and fallback support independently depending on the Fedora variant that needs it, users can choose to disable one feature bit removing the script executable bit without affecting the other feature, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That way, both features couldn't be used at the same time. I'd like to have that option for workstations (even if it weren't active by default). I need the lines resetting and saving boot_success from this script. maybe @jwrdegoede has an idea how to separate things cleanly here?

if [ "\${boot_counter}" = "0" ]; then
set default=1
set fallback_active=true
save_env fallback_active
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably you don't need this fallback_active variable, I would just use the boot_counter variable as an indication that the fallback entry was booted. For example you can set here boot_counter to -1 or unset it so user-space knows that the default entry failed to boot.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack

EOF

# Disable / skip generating menu-auto-hide config parts on serial terminals
for x in ${GRUB_TERMINAL_INPUT} ${GRUB_TERMINAL_OUTPUT}; do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this the distinction made between Server and Workstation editions?

Copy link
Contributor

@jlebon jlebon left a comment

Choose a reason for hiding this comment

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

Nice! Just some minor comments below.

cat << EOF
# Boot Counting
if [ "\${boot_counter}" ]; then
if [ "\${boot_success}" = "0"]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: can we just collapse these two as:

if [ "\${boot_counter}" -a "\${boot_success}" = "0" ]; then

?

Copy link
Contributor

Choose a reason for hiding this comment

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

@jlebon I don't think we can since boot_counter not set is used as an indication that fallback is disabled on that system.

Otherwise you would need to have in the case statement:

elif [ "\${boot_counter}" ]; then

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I'm not sure I understand this. Isn't

if A then
  if B then
    ...
  fi
fi

logically equivalent to:

if A and B then
  ...
fi

?

Copy link
Contributor

Choose a reason for hiding this comment

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

@jlebon yes it is, but you are missing the else part in your example:

if A then
    if B then
    ...
    else
    ...
    fi
fi
if A and B then
    ...
else
    ...
fi

The else statement will be executed even if not A so then you need:

if A and B then
    ...
elif not A then
    ...
fi

Copy link
Contributor

Choose a reason for hiding this comment

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

There is no else on the first two if-statements though, only the third. :)
Anyway, it's just a minor nit; not really worth discussing it more than we already have.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jlebon sorry, I misread and thought you were talking about the second if-statement. Yes, for the first one you are correct! cc @LorbusChris

save_env boot_counter
else
set boot_counter=$((\${boot_counter}-1))
save_env boot_counter
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: we can just factor out the save_env boot_counter outside the if-statement, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

@jlebon agreed.

@LorbusChris
Copy link
Contributor Author

Changes since v1:

  • Moved code into 01_fallback_support.in.
  • Renamed 00_menu_auto_hide.in to 01_menu_auto_hide.in

@martinezjavier
Copy link
Contributor

Renamed 00_menu_auto_hide.in to 01_menu_auto_hide.in

You are missing this bit though, it has to be on a preparatory commit before adding 01_fallback_support.in.

@LorbusChris LorbusChris force-pushed the boot-counting branch 2 times, most recently from db8cd3e to a4eb01c Compare July 27, 2018 13:47
@LorbusChris
Copy link
Contributor Author

done @martinezjavier @jlebon

@martinezjavier
Copy link
Contributor

@LorbusChris the second patch looks good to me now. Could you please add a commit message in the same commit explaining why this rename is needed.

Also, could you please rebase on top of the latest fedora-29 branch?

@LorbusChris LorbusChris force-pushed the boot-counting branch 2 times, most recently from 0b72724 to 0b54f71 Compare July 31, 2018 05:29
@LorbusChris LorbusChris changed the title [WIP] Add boot counting Add boot counting Jul 31, 2018
@LorbusChris
Copy link
Contributor Author

LorbusChris commented Jul 31, 2018

@martinezjavier please re-check =)

Edit: Changes v2 -> v3:
Named the new script 01_fallback_counting.in instead of 01_fallback_support.in as there seems to be another unrelated fallback feature (using fallback env var) in grub. Please tell if you have a better name in mind!

This is necessary to accommodate the fallback counting script which
needs to run before this one because the menu auto hide script sets
boot_success = 0, which will be used by the boot counting script
Adds 01_fallback_counting.in script to support boot counting before
falling back to the previous menu entry automatically
Copy link
Contributor

@martinezjavier martinezjavier left a comment

Choose a reason for hiding this comment

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

Looks good to me now.

@vathpela vathpela merged this pull request into rhboot:fedora-29 Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants