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

Ahm*_*d A 21 linux linux-kernel

我设置了CentOS 6.3设置,其中控制台loglevel设置为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
Run Code Online (Sandbox Code Playgroud)

但是,重新启动后,控制台日志级别将恢复为原始值.我是否需要重新编译内核,或者有一种方法可以让更改后的值在重新引导时保持持久性.

saw*_*ust 42

我需要重新编译内核吗?

没有.

或者有没有办法可以让更改后的值在重启时保持持久性.

是.
使用内核命令行参数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
Run Code Online (Sandbox Code Playgroud)

内核命令行上可能的完整参数列表Linux/Documentation/kernel-parameters.txt位于源树中的文件中.

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


附录

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

  • 这很晚了,但您也可以在运行时使用Alt-SysRq-0等. (4认同)
  • 更新的文档链接:https://www.kernel.org/doc/Documentation/admin-guide/kernel-parameters.txt (2认同)