Skip to content

sd-boot: fix menu ordering with boot counting#15577

Merged
poettering merged 1 commit intosystemd:masterfrom
danielfullmer:boot-menu-order
May 26, 2020
Merged

sd-boot: fix menu ordering with boot counting#15577
poettering merged 1 commit intosystemd:masterfrom
danielfullmer:boot-menu-order

Conversation

@danielfullmer
Copy link
Contributor

systemd-boot selects the last valid entry by default, not the first.

Fixes: #15256

Please let me know if I'm misunderstanding something. I'm looking to implement automatic boot fallback using systemd-boot in NixOS here: NixOS/nixpkgs#84204

systemd-boot selects the last valid entry by default, not the first.

Fixes: systemd#15256
@poettering
Copy link
Member

hmm? not sure i follow. sd-boot generlly boots the first entry in the boot menu, not the last, hence when we consider a boot entry "bad" we order it to the end?

not sure i groke this? can you elaborate?

@poettering poettering added sd-boot/sd-stub/bootctl needs-reporter-feedback ❓ There's an unanswered question, the reporter needs to answer labels Apr 29, 2020
@danielfullmer
Copy link
Contributor Author

@poettering I don't believe its true that sd-boot selects the first entry by default. To test, I placed 3 files in /boot/loader/entries with versions 1, 2, and 3, and made sure there is was no "default" in loader.conf. Upon booting, version 3 is selected at the bottom (excluding the "boot into firmware interface" option):

systemd-boot-menu-order

If you only have 1 loader entry, and some automatically generated options, which are ordered at the end of the list, it might appear that systemd-boot selects the first entry. However, those automatically generated options are not selected only because they are given a no_autoselect flag in the code.

Finally, here is the relevant code in config_default_entry_select which shows that it selects the last entry which doesn't have no_autoselect set:

systemd/src/boot/efi/boot.c

Lines 1628 to 1651 in f20078d

/*
* Match the pattern from the end of the list to the start, find last
* entry (largest number) matching the given pattern.
*/
if (config->entry_default_pattern) {
i = config->entry_count;
while (i--) {
if (config->entries[i]->no_autoselect)
continue;
if (MetaiMatch(config->entries[i]->id, config->entry_default_pattern)) {
config->idx_default = i;
return;
}
}
}
/* select the last suitable entry */
i = config->entry_count;
while (i--) {
if (config->entries[i]->no_autoselect)
continue;
config->idx_default = i;
return;
}

@poettering poettering added this to the v246 milestone May 15, 2020
@poettering poettering merged commit e6190e2 into systemd:master May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-reporter-feedback ❓ There's an unanswered question, the reporter needs to answer sd-boot/sd-stub/bootctl

Development

Successfully merging this pull request may close these issues.

systemd-boot menu ordering and boot counting

3 participants