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

标签 linux linux-kernel console

<分区>

我设置了 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

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

最佳答案

Do I need to recompile the kernel,

没有。

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

是的。
使用内核命令行参数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

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

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


附录

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

关于linux - 在启动期间更改默认控制台日志级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16390004/

相关文章:

c - 在设备驱动程序中使用 stdlib.h

linux-kernel - 为什么我在运行 readelf -s 时得到这个输出

linux-kernel - uboot-MMC 没有 SD 卡

c# - 我如何获得正确的应用程序目录?

c++ - 在应用程序中编写控制台

mysql - 从外部主机/ip 访问 mysql 数据库? (即 : mysql workbench)

c - Linux:当父进程退出时退出 fork 的子进程

javascript - 在 Komodo 控制台中运行 node.js 脚本

linux - 在 shell 脚本中执行命令时在双引号内转义单引号

无法连接到本地主机