Debug levels in linux

Change default console loglevel during boot up [closed]

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:

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.

1 Answer 1

Do I need to recompile the kernel,

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= 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.txt file in the source tree.

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/cmdline to view the kernel command line used for the previous boot.

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_loglevel parameter to display all kernel messages.

Читайте также:  Linux mint black screen with cursor

Источник

Debug levels in linux

Date created: Sunday, September 8, 2019 7:46:53 PM. Last modified: Friday, January 3, 2020 3:35:02 PM

Linux Debug Levels

#define KERN_EMERG "" /* system is unusable*/
#define KERN_ALERT "" /* action must be taken immediately*/
#define KERN_CRIT "" /* critical conditions*/
#define KERN_ERR "" /* error conditions*/
#define KERN_WARNING "" /* warning conditions*/
#define KERN_NOTICE "" /* normal but significant condition*/
#define KERN_INFO "" /* informational*/
#define KERN_DEBUG "" /* debug-level messages*/

printk() Example

#include
#include
#include

MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("James Bensley ");
MODULE_DESCRIPTION("Kernel debug and print examples module");
MODULE_VERSION("1:0.0");


static int __init kdebug_init(void) printk(KERN_INFO "KDebug module loaded\n");

printk(KERN_WARNING "Testing KERN_WARNING\n");
printk(KERN_NOTICE "Testing KERN_NOTICE\n");
printk(KERN_INFO "Testing KERN_INFO\n");
printk(KERN_DEBUG "Testing KERN_DEBUG\n");

return 0;

>


void __exit kdebug_unload(void)
printk(KERN_INFO "KDebug module removed\n");

>


module_init(kdebug_init);
module_exit(kdebug_unload);
# Build with: sudo make

obj-m += kdebug.o
KDIR = /lib/modules/$(shell uname -r)/build

#CCFLAGS="-pedantic"
#CXXFLAGS=$CCFLAGS

# The indentation below must be a \t tab character!
all:
make -C $(KDIR) M=$(shell pwd) modules

# The indentation below must be a \t tab character!
clean:
make -C $(KDIR) M=$(shell pwd) clean
bensley@ubuntu-laptop:~/C/kdebug$ sudo make
make -C /lib/modules/4.11.0-041100-generic/build M=/home/bensley/C/kdebug modules
make[1]: Entering directory '/usr/src/linux-headers-4.11.0-041100-generic'
CC [M] /home/bensley/C/kdebug/kdebug.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/bensley/C/kdebug/kdebug.mod.o
LD [M] /home/bensley/C/kdebug/kdebug.ko
make[1]: Leaving directory '/usr/src/linux-headers-4.11.0-041100-generic'

bensley@ubuntu-laptop:~/C/kdebug$ ls -l
total 28
-rw-rw-r-- 1 bensley bensley 687 Sep 8 19:44 kdebug.c
-rw-r--r-- 1 root root 4088 Sep 8 19:49 kdebug.ko
-rw-r--r-- 1 root root 507 Sep 8 19:49 kdebug.mod.c
-rw-r--r-- 1 root root 2488 Sep 8 19:49 kdebug.mod.o
-rw-r--r-- 1 root root 2480 Sep 8 19:49 kdebug.o
-rw-rw-r-- 1 bensley bensley 326 Sep 8 19:41 Makefile
-rw-r--r-- 1 root root 40 Sep 8 19:49 modules.order
-rw-r--r-- 1 root root 0 Sep 8 19:49 Module.symvers

bensley@ubuntu-laptop:~/C/kdebug$ sudo insmod kdebug.ko

bensley@ubuntu-laptop:~/C/kdebug$ echo $?
0

bensley@ubuntu-laptop:~/C/kdebug$ dmesg | tail -n 5
[ 4014.604576] KDebug module loaded
[ 4014.604579] Testing KERN_WARNING
[ 4014.604580] Testing KERN_NOTICE
[ 4014.604581] Testing KERN_INFO
[ 4014.604582] Testing KERN_DEBUG

bensley@ubuntu-laptop:~/C/kdebug$ sudo rmmod kdebug

bensley@ubuntu-laptop:~/C/kdebug$ echo $?
0

bensley@ubuntu-laptop:~/C/kdebug$ dmesg | tail -n 1
[ 4160.378806] KDebug module removed

Источник

Оцените статью
Adblock
detector