Sometimes it is useful to panic a linux machine, specially when testing various HA setups or kdump thingies.

I found that “echo c > /proc/sysrq-trigger” is not enough. It produces a kernel dump but the machine keeps running. So I went with the more “hardcore” option: a kernel module that calls panic(). The idea is described in Linux Crash Howto, but here it is upgraded for the 2.6 kernel.

panic.c:

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>

static int __init enter_module(void)
{
  panic("forcing kernel panic.\n");
  return 0;
}

static void __exit exit_module(void)
{
/* dead code here */
  printk("Bye!\n");
}

module_init(enter_module);
module_exit(exit_module);

MODULE_AUTHOR("John Doe");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Panic mode on!");

Makefile:

obj-m += panic.o
all:
      make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
      make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Have kernel sources handy, put these two files in a directory of your liking and simply say “make”. You're presented with a panic.ko, which you simply insmod to kill the machine.

linux/panic.txt · Last modified: 2009/05/25 00:35 (external edit)
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready