Alternative to using Grub's GRUB_CMDLINE_LINUX_DEFAULT

I am using GRUB2 for my bootloader. In the grub configuration file, i.e. /etc/default/grub/, the length or number of characters in line which which has GRUB_CMDLINE_LINUX_DEFAULT is almost 220 characters. I am getting a bit concerned about the size/length. Not only because of its size but also soon it will become unwieldy to manage.

Is there a different way to pass parameters to GRUB2 bootloader apart from using GRUB_CMDLINE_LINUX_DEFAULT? What is the recommended way to pass boot parameters to Linux Kernel if we are using GRUB2?
What is the length/size limitation for text that can be put for GRUB_CMDLINE_LINUX_DEFAULT? Is it 256 characters? Or 512 characters? Or 1024 characters? or some other?

This question got me curious so I will try and answer as best I can.

First, why do you need such a long list of parameters?

In terms of a character limit you are nowhere near the max. from what I understand.

However, in terms of readability it is awkward and unmanageable.

But you could tidy it up by concatenating the lines.

Say, for example, you have this currently:

GRUB_CMDLINE_LINUX_DEFAULT=“quiet splash apparmor=1 security=apparmor noapic acpi=force mitigations=off pci=nomsi ipv6.disable=1 audit=0”

Reformat across multiple lines like this:

GRUB_CMDLINE_LINUX_DEFAULT=“quiet splash \
apparmor=1 security=apparmor \
noapic acpi=force \
mitigations=off \
pci=nomsi \
ipv6.disable=1 \
audit=0”

The backslash at the end of a line tells the shell that the string continues on the next line after it.

The entire line stays readable and you can easily see which parameters are active.

Caveat: I have not tested this so please wait for more input before trying it.

Hope this helps.

1 Like

EndeavourOS uses dracut and with dracut you could manage kernel command line options via drop in configuration files within the folder /etc/dracut.conf.d/.

There should be already the file eos-defaults.conf available which is handling some kernel modules, for the cmdline you can create the file cmdline.conf and in case you want to just add a single kernel parameter, you can append a single parameter via the line
kernel_cmdline+=" <your_param_here> ".

Take into account that the spaces are required and not included by accident from my side.

2 Likes

Note that /etc/default/grub can use bash syntax, so you can write

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash apparmor=1 security=apparmor"
GRUB_CMDLINE_LINUX_DEFAULT+=" noapic acpi=force mitigations=off pci=nomsi"
GRUB_CMDLINE_LINUX_DEFAULT+=" ipv6.disable=1 audit=0”

Note the leading space inside the quoted string on the second and third line.

4 Likes

Why do you have such a long line (about 220 chars)?
Can you show the line where you set GRUB_CMDLINE_LINUX_DEFAULT?

By trying to optimize the kernel runtime and also to make it a bit more hardy. :grin: . I have a few more items to be added. But I was concerned that if I just go and keep on making additions to this line, I might enter values beyond the permissible length.

Any idea on what is the limit?
Yeah it is horrid in terms or readability and manageability.
It would have been sooo much better to have a config file like it is there for dracut where these parameters could be put in their separate config file, say 10-apparmour-lsm.conf or 20-raid-lvm-luks-nvme.conf and so on.

This helps. I will wait for more input before trying this out.

@1093i3511 this is very appealing, to put it in in a conf file inside /etc/dracut.conf.d/. But can we put all the parameters like audit=1 loglevel=5 in the key kernel_cmdline ? To make the changes come into effect do we have to run dracut-rebuild? This means that initramfs is rebuild every time a change has to be made into the Kernel boot parameters.

Also how is this different from putting it in the GRUB2 configuration file? These parameters will become part of initramfs or will they be passed to kernel on every boot/reboot? Is there best practice or recommendation on what is ought to be done? Put it in the GRUB or use dracut?

That is a good suggestion. This should be part of the Arch Wiki on Grub or on the Grub manual pages.
Any idea on how many times can the key GRUB_CMDLINE_LINUX_DEFAULT+= be used? 5 times, 10 times or something else?

@manuel my GRUB_CMDLINE_LINUX_DEFAULT is very similar to what @rubi1200 has.
quiet splash apparmor=1 security=apparmor ipv6.disable=1
The difference is that in addition to the above I also have
nowatchdog nvme_load=YES resume=......... audit=1 loglevel=5
This is put inside the file /etc/default/grub.
The reason why it is so long is that I have passed a few parameters to harden the system a bit and to tweak it to run better.

Unfortunately I don’t have a definite answer to that question, but I tend to say that dracut-rebuild would have to be executed to make those changes. If someone could share his insights, I`ld like to know as well !

Therefore, adding individual parameters to the kernel as @manuel mentioned via appending individual parameters to the GRUB_CMDLINE_LINUX_DEFAULT should be more straight forward. For persistence, it wouldn’t make that much of a difference.

I should note that using drop in files /etc/dracut.conf.d/*.conf should follow alphanumeric naming conventions, i.e. using the prefix 50-59 for user provided configurations. Has definitely the advantage that specific parameters could be organized within dedicated configuration files.

There are definitely several ways to skin the cat.

1 Like