2

I am developing an embedded Linux device. I have successfully created an InitramFS CPIO archive that runs quickly after boot. Now, I want to change the initial kernel command line to include "quiet" parameter so I can boot even faster.

However, once the splash screen is displayed in the InitramFS, I want to remove the quiet option for the kernel so the remainder of the boot is NOT quiet.

How can I achieve this? How can I reverse the initial "quiet" kernel command line option once I've reached the InitramFS?

Thanks.

2
+100

You can't really change the kernel command-line after boot, but what you can do is reproduce the effects of setting or unsetting the quiet command-line through other means, which should accomplish what you want to achieve here.

In short, to increase verbosity once you don't want quiet anymore, you can use this command:

# echo 7 >/proc/sys/kernel/printk

And to emulate what quiet does, this is what you can use:

# echo 4 >/proc/sys/kernel/printk

This should take care of the kernel side of the setting... But sometimes userspace will also change behavior based on this kernel option. For instance, systemd will parse the quiet option in the kernel command-line, and act as if ShowStatus=auto was used in /etc/systemd/system.conf. If you want to revert that (to enforce the default and ignore the quiet option), edit that config file and uncomment the ShowStatus=yes line there, which should take care of it.

There might be other systems in userspace that look at this option, so you might need to take a closer look at those to see how they behave and how to reproduce (or undo) the behavior of the option being present in the kernel command-line.

The following is a deep dive into the sources to explain the behavior of the quiet option in the kernel and systemd.


The kernel parses the quiet option by calling the quiet_kernel() initialization function, which does:

static int __init quiet_kernel(char *str)
{
    console_loglevel = CONSOLE_LOGLEVEL_QUIET;
    return 0;
}

early_param("quiet", quiet_kernel);

The console_loglevel pseudo-variable is actually the first element of the console_printk array:

extern int console_printk[];

#define console_loglevel (console_printk[0])

Log level "quiet" is defined as 4:

#define CONSOLE_LOGLEVEL_QUIET   4 /* Shhh ..., when booted with "quiet" */

A few lines below, the default log level is defined through a kernel config:

/*
 * Default used to be hard-coded at 7, we're now allowing it to be set from
 * kernel config.
 */
#define CONSOLE_LOGLEVEL_DEFAULT CONFIG_CONSOLE_LOGLEVEL_DEFAULT

And that kernel config is set in Kconfig.debug, still defaults to 7:

config CONSOLE_LOGLEVEL_DEFAULT
    int "Default console loglevel (1-15)"
    range 1 15
    default "7"

(You might want to check that your kernel is using the default config, either in /boot/config-* or in /proc/config.gz.)

And for more details on using /proc/sys/printk, see the kernel documentation for it. But, in short, it is possible to write only a single number, in which case only the first element of the array will be updated, which is what you want here.


systemd will also parse the kernel command-line, looking for entries typically named systemd.*, but it turns out systemd also recognizes the quiet kernel command-line and uses it to set the ShowStatus:

    } else if (streq(key, "quiet") && !value) {

            if (arg_show_status == _SHOW_STATUS_UNSET)
                    arg_show_status = SHOW_STATUS_AUTO;

In this case, it will only set it if it wasn't previously set (_SHOW_STATUS_UNSET) and will set it to "auto" (SHOW_STATUS_AUTO.)

Another way to set the ShowStatus is through the configuration file:

            { "Manager", "ShowStatus",                config_parse_show_status,      0, &arg_show_status                       },

This line describes the configuration option named ShowStatus= under the [Manager] section of system.conf. The parser for this option takes either the "auto" string (in which case it sets it to SHOW_STATUS_AUTO) or takes a boolean, which can be "yes", "true" or "1" to enable it, or "no", "false" or "0" to disable it.

The systemd documentation for --show-status= is also pretty helpful here. It cites the ShowStatus= configuration too (since passing systemd command-line arguments directly is not always easy to do, updating a configuration file is definitely a more straightforward way to configure this setting.)


I hope you find this helpful and that it helps you accomplish the right verbosity for your particular use case!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.