simulating kernel panic


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers simulating kernel panic
# 1  
Old 03-10-2010
simulating kernel panic

How can a kernel panic be simulated?
# 2  
Old 03-10-2010
Create and load a minimal module calling the kernels panic() function, eg for Linux (from Linux Crash HOWTO)
Code:
$ cat > panic.c <<EOF
// ### panic.c ###########################

#define __KERNEL__
// # MODULE 

# include init_module(void)

int init_module (void)
{
    panic(" panic has been called");
    return 0;
}
EOF
$ cc -c -I/usr/src/linux/include panic.c
$ insmod panic.o

Note: there's a bug included here on purpose in case anyone wants to try this. The purpose is simply that one shouldn't copy and paste possibly dangerous code without thinking.

---------- Post updated at 14:05 ---------- Previous update was at 13:04 ----------

OK, I should have taken a look at the timestamp of that How-To. Here's a current version for modern kernels (again, with easy to spot bug, and lots of thanks to this page):
Code:
// panic.c
#include <linu/module.h>

static int __init panic_init_module(void) {
    panic(" panic has been called");
}

module_init(panic_init_module);
MODULE_LICENSE("GPL");

Code:
# Makefile
# Intendations have to be tabs, not spaces
UNAME := $(shell uname -r)
KERNEL26 := 2.6
KERNELVERSION := $(findstring $(KERNEL26),$(UNAME))

ifeq ($(KERNELVERSION),2.6)

obj-m := panic.o

INCLUDE := -I/usr/include/asm/
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)

all::
	$(MAKE) -C $(KDIR) $(INCLUDE) SUBDIRS=$(PWD) modules
 
else

TARGET := panic
INCLUDE := -I/lib/modules/`uname -r`/build/include -I/usr/include/asm/
CFLAGS := -O2 -Wall -DMODULE -D__KERNEL__ -DLINUX
CC := gcc

all:: ${TARGET}.o

${TARGET}.o: ${TARGET}.c
	$(CC) $(CFLAGS) ${INCLUDE} -c ${TARGET}.c
 
endif

Run it using
Code:
insmod ./panic.o # Kernel 2.4
insmod ./panic.ko # Kernel 2.6

# 3  
Old 03-10-2010
Encountered the following error:

Code:
[root@wiki ~]# make panic
cc     panic.c   -o panic
panic.c:2:26: error: linux/module.h: No such file or directory
panic.c:4: error: expected â=â, â,â, â;â, âasmâ or â__attribute__â before âpanic_init_moduleâ
panic.c:8: warning: data definition has no type or storage class
panic.c:8: warning: parameter names (without types) in function declaration
panic.c:9: error: expected declaration specifiers or â...â before string constant
panic.c:9: warning: data definition has no type or storage class
make: *** [panic] Error 1

# 4  
Old 03-10-2010
First: no need for 'make panic', make alone should suffice.
Second: you'll need the sources for your current kernel installed, of course. Apparently my thinking that this would be obvious was far too idealistic.
# 5  
Old 03-10-2010
Code:
[root@wiki ~]# rpm -qa|grep kernel
kernel-headers-2.6.18-164.el5
kernel-PAE-2.6.18-128.el5
kernel-PAE-2.6.18-128.4.1.el5


Code:
[root@wiki ~]# uname -r
2.6.18-128.4.1.el5PAE

You want to mean that i need the kernel-devel package installed for the above kernel?
# 6  
Old 03-10-2010
If you are using Redhat, you install and configure kexec/kdump. Then to panic the kernel and cause it to crash you simply do the following:
Code:
# echo "c" > /proc/sysrq-trigger

See How do I configure kexec/kdump on Red Hat for full information.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Kernel panic-not syncing

dear experts linux i am using RHEL 5.5 run on a physical server. i am front of a big trouble, the Rhel can't run correctly , it show me this error message in black screen: reading all physical volumes. this my take a while .. found volume group "VolGroup00" using metadata type lvm2 9... (1 Reply)
Discussion started by: wassimpb
1 Replies

2. SCO

Kernel Panic

Hello when i booting my SCO Server I become this Message PLS can anyone help me? Cheers Christoph (1 Reply)
Discussion started by: cga
1 Replies

3. UNIX for Advanced & Expert Users

what does the kernel panic mean?

Hi, all: How should I obtain the reason of kernel panic? How should I debug the program which result in a kernel panic? What can I get from the panic information? li, kunlun (3 Replies)
Discussion started by: liklstar
3 Replies

4. UNIX for Dummies Questions & Answers

Kernel 3.0 giving me panic :)

I was very exited to try out new kernel version so i decided to give it a try. http://www.conceivablytech.com/7683/products/linux-torvalds-approves-linux-3-0-rc1 So i downloaded the kernel 3.0-rc1 from The Linux Kernel Archives It was my first kernel compilation everything went smooth... (1 Reply)
Discussion started by: pinga123
1 Replies

5. Red Hat

Kernel Panic problem

Hi all, When i load my block device driver in Fedoracore10 kernel 2.6.27. i got this type of error kernel panic - not syncing : Fatal exception in interrupt. I am unable to save the log file.... Can any one help me..... regards sundar (4 Replies)
Discussion started by: sundhar
4 Replies

6. Linux

kernel panic on RHEL3

hello all, please, help! we suffered out of power today and one of our Linux boxes cannot boot properly: .. hda set_driver_speed_status error 0X04 VFS: Unable to mount root fs on 00:00 ... the only thing that i can do - is boot in the rescue mode. i've already added noinitrd to... (2 Replies)
Discussion started by: MarGur
2 Replies

7. Linux

Kernel panic - not syncing: cannot execute a PAE-enabled kernel on PAE-less CPU

ok so I just installed fedora core 6 on my dell inspiron 700m and I go to boot into linux and I get this error. Has anyone seen this before? I also had XP Pro and Vista installed on this pc prior to putting fedora core 6 on the machine. I'm trying to setup a triple boot system. Please Help... (2 Replies)
Discussion started by: dave043
2 Replies

8. Linux

kernel panic

I have compiled kernel version 2.6.12 in my linux box mandrake 10.1. I have followed www.digitalhermit.com/linux/Kernel-Build-HOWTO.html instructions. I have copied .config file from /usr/src/linux and lightly modified it (only the processor type) by xconfig. I have compiled the source and modules.... (3 Replies)
Discussion started by: Davide71
3 Replies

9. UNIX for Dummies Questions & Answers

kernel panic

hello :-) I have one problem with my LiLO... I installed PLD Linux on my computer but when it boots, the last thing I can see is: request_module Root fs not mounted VFS: Cannot open root device 03:01 Kernel panic: VFS: unable to mount root fs on 03:01 and the system stops :-( what... (1 Reply)
Discussion started by: pgas
1 Replies

10. UNIX for Dummies Questions & Answers

RH 7.3 Kernel Panic.

I've installed rh 7.3 a fewday ago and I'm trying to boot it and I get this" Kernel panic: no init found. try passing init=options to kernel" ????? What do I do. Thanks. F,Ruiz. (2 Replies)
Discussion started by: ruizf
2 Replies
Login or Register to Ask a Question