Linux 在启动期间更改默认控制台日志级别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16390004/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:51:46  来源:igfitidea点击:

Change default console loglevel during boot up

linuxlinux-kernel

提问by Ahmed A

I setup a CentOS 6.3 setup, on which the console loglevel is set to 4, and default log level is set to 4. I know I can change the default console log level using the following steps:

我设置了 CentOS 6.3 设置,其中控制台日志级别设置为 4,默认日志级别设置为 4。我知道我可以使用以下步骤更改默认控制台日志级别:

cat /proc/sys/kernel/printk

4   4   1   7

echo 5 > /proc/sys/kernel/printk
cat /proc/sys/kernel/printk

5   4   1   7

However, upon reboot, the console log level reverts back to the original value. Do I need to recompile the kernel, or is there a way I can get the changed value to be persistent across reboot.

但是,重新启动后,控制台日志级别将恢复为原始值。我是否需要重新编译内核,或者有什么方法可以使更改后的值在重新启动后保持不变。

采纳答案by sawdust

Do I need to recompile the kernel,

我需要重新编译内核吗,

No.

不。

or is there a way I can get the changed value to be persistent across reboot.

或者有什么方法可以使更改后的值在重新启动时保持不变。

Yes.
Use the kernel command line parameter loglevel:

是的。
使用内核命令行参数loglevel

loglevel=       All Kernel Messages with a loglevel smaller than the
                    console loglevel will be printed to the console. It can
                    also be changed with klogd or other programs. The
                    loglevels are defined as follows:

                    0 (KERN_EMERG)          system is unusable
                    1 (KERN_ALERT)          action must be taken immediately
                    2 (KERN_CRIT)           critical conditions
                    3 (KERN_ERR)            error conditions
                    4 (KERN_WARNING)        warning conditions
                    5 (KERN_NOTICE)         normal but significant condition
                    6 (KERN_INFO)           informational
                    7 (KERN_DEBUG)          debug-level messages

The entire list of parameters possible on the kernel command line are in the Linux/Documentation/kernel-parameters.txtfile in the source tree.

内核命令行上可能出现的整个参数列表都在Linux/Documentation/kernel-parameters.txt源代码树的文件中。

Depending on your bootloader (e.g. Grub or U-Boot), you will have to edit text to add this new parameter to the command line. Use cat /proc/cmdlineto view the kernel command line used for the previous boot.

根据您的引导加载程序(例如 Grub 或 U-Boot),您必须编辑文本以将此新参数添加到命令行。使用cat /proc/cmdline查看使用以前的引导内核的命令行。



Addendum

附录

To display everything, the number supplied for the loglevel parameter would have be be greater than KERN_DEBUG.
That is, you would have to specify loglevel=8.
Or simply use the ignore_loglevelparameter to display all kernel messages.

要显示所有内容,为 loglevel 参数提供的数字必须大于 KERN_DEBUG。
也就是说,您必须指定loglevel=8.
或者简单地使用该ignore_loglevel参数来显示所有内核消息。