Rich Freeman <ri...@gentoo.org> wrote:
> On Sun, Apr 17, 2022 at 3:00 PM Martin Vaeth <mar...@mvath.de> wrote:
>>
>> Yes, without a manually written grub.cfg you get none of these features -
>> the default grub.cfg is just horrible.
>> Well, the most powerful feature is probably still available:
>> The possibility to edit the kernel's command line, partition and path which
>> theoretically can cover everything else, though it is rather inconvenient.

Just to clarify: I mean to edit the kernel's command line immediately
before booting (that is, for instance, in emergency cases like a non-booting
new kernel together with a damaged init-system. Or when you are at a
conference with your laptop and need to connect to a beamer which for some
reason did not display anything so that perhaps forcing a different
resolution helps. I had all this, and wouldn't like to miss grub in such
situations).

> The GRUB bootloader just parses its config file, which can be manually
> edited as you point out.

This config file has many shell-like features like functions and variables
and can source helper libraries. I suggest to use of all this! (See below.)

> You also have grub-mkconfig

grub-mkconfig is meant for binary distributions. A gentoo user typically
compiles the kernel manually, anyway, and they typically know precisely
which kernel they want to boot. So they have no use for any of the
(mis-)features from grub-mkconfig.
They might use it *once* to get some grub.cfg to start with, but then
I recommend to dump grub-mkconfig.

> grub-mkconfig just runs a bunch of shell scripts to generate
> everything [...] Obviously it would be more elegant to add a loop over
> a configuration variable.

That's not what I meant. I meant to dump grub-mkconfig completely and
not writing any substitute for it. Instead, write your grub.cfg manually,
making full use of its features like variables and functions.

For instance, I have one menu entry for each init-system (openrc,
systems, and 3 more for emergency shells). But selecting such an
entry just changes a (grub.cfg) variable and does not boot yet.

Then there are menu entries for selecting/editing the resolution
variables, etc.

And only a few menu entries are for actually choosing the kernel and
booting it (according to the previously set variables).

Of course, there are default values for the variables if I make no
selection and a default boot entry as well which normally is
auto-booted after a few seconds.

Note that if I would like to have a separate entry for each
combination I might ever have a need for, I would need hundreds of
menu entries, as their number is exponential in the number of
variables which are used.

> I'm not aware of anybody having actually done this, however, so you'd
> have to DIY.

https://github.com/vaeth/grub-cfg-mv/releases/
You can install it with sys-boot/grub-cfg-mv in the mv overlay, but
you still have to read the instructions and write the "main" grub.cfg
by yourself (although you can start from the example and from the
grub.cfg generated by one initial call of grub-mkconfig).


Reply via email to