1

In self-generated grub.cfg, there is a lot of

if [ x$feature_platform_search_hint = xy ] ...

if [ x$feature_default_font_path = xy]...

if [ x$feature_all_video_module = xy ]...

My believe is that it is checking if the feature is present or not in the past when the answer might be false, like when grub2 was under development. But after so many years, will they ever be false in any case?

I'm more interested in the $feature_platform_search_hint, and as per here,

The predefined variables such as feature_platform_search_hint are hardcoded in the normal module at build time, and are essentially undocumented except by studying the source code. In current versions of grub, these variables are defined to be y at all times, so these variables seem to indicate support for specific features of a given grub version, and testing them can be done to write grub.cfg files that work with multiple versions of grub.

What I don't understand is why the self-generated grub.cfg has to be such over-complicated. E.g.,

Will I ever need to worry about the $feature_platform_search_hint now and in the future? If I manually write my own maintenance free Grub2 menu, do I have to repeat the self-generated grub.cfg like:

        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt8 --hint-efi=hd0,gpt8 --hint-baremetal=ahci0,gpt8  23cbdbaf-9bc8-49d0-a483-1ce445cf6fb4
        else
          search --no-floppy --fs-uuid --set=root 23cbdbaf-9bc8-49d0-a483-1ce445cf6fb4
        fi

OK I just always use the --hint parameters?

xpt
  • 1,530

1 Answers1

0

Reposting from here:

The list of features is maintained as features global variable in normal/main.c. feature_platform_search_hint has been available since GRUB 2.00 (released 2012)(ten years ago). So the conditional code checking for this feature is pointless in all modern Linux distributions.

At the time of this writing (Sep 27 '19), the latest feature added was feature_timeout_style, available since 2.02-beta1.

I repeat, "the conditional code checking for this feature is pointless in all modern Linux distributions".

xpt
  • 1,530
  • What is the conclusion? That 'else' branches in grub.cfg can safely be deleted (and delete the rest of the 'if' construct)? Or conversely, only keep the 'else' branches in grub.cfg (and delete the rest of the 'if' construct)? (For example, it makes for huge simplification during debugging boot problems.) – Peter Mortensen Mar 11 '23 at 11:07
  • Yes @PeterMortensen, the entire conditional code checking is useless and can be deleted, not only the else branches, but the 'if' part as well, as these variables are defined to be y at all times, and yes it will surely makes for huge simplification of grub.cfg writing and debugging, which I've already tested myself. – xpt Mar 11 '23 at 21:21