Home » Linux Kernel » Core Kernel » How to force panic Linux kernel intentionally ?

How to force panic Linux kernel intentionally ?

When you are working with Linux kernel internals or device driver programming, there are chances you see the Linux kernel getting panic errors and everything just comes to halt. This is the most difficult situation a kernel programmer faces during development.

Fixing the kernel panic issues are also not a cake walk, it needs extensive debugging, knowledge, trail and error to understands whats really happening and then fix the errors.

In this post, we will show some commands which you can use to forcefully put the kernel into panic so you can identify issues and debug some situations which are difficult to reproduce but when occurs it can bring complete system to halt.

Type below commands on your Linux console or UART consoles for embedded Linux.

Step 1 – Enable All functions of sysrq

$ echo 1 > /proc/sys/kernel/sysrq
  • 0 – disable sysrq completely
  • 1 – enable all functions of sysrq
  • >1 – bitmask of allowed sysrq functions (see below for detailed function description):
    • 2 = 0x2 – enable control of console logging level
    • 4 = 0x4 – enable control of keyboard (SAK, unraw)
    • 8 = 0x8 – enable debugging dumps of processes etc.
    • 16 = 0x10 – enable sync command
    • 32 = 0x20 – enable remount read-only
    • 64 = 0x40 – enable signalling of processes (term, kill, oom-kill)
    • 128 = 0x80 – allow reboot/poweroff 256 = 0x100 – allow nicing of all RT tasks

You can set the value in the file by the following command:

echo "number" >/proc/sys/kernel/sysrq

The number may be written here either as decimal or as hexadecimal with the 0x prefix. 

Step 2 – Perform system crash

$ echo "c" > /proc/sysrq-trigger

Write a character to /proc/sysrq-trigger. e.g.:

echo t > /proc/sysrq-trigger

The <command key> is case sensitive.

What are the ‘command’ keys?

CommandFunction
bWill immediately reboot the system without syncing or unmounting your disks.
cWill perform a system crash and a crashdump will be taken if configured.

Reference – https://www.kernel.org/


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment