jdknight
jdknight

Reputation: 1839

How does one Capture the Entire Kernel Panic on Boot

Using Buildroot, I'm attempting to make a custom kernel build. After building the image and booting it on a VirtualBox environment, the kernel always panics after the GRUB stage. General summary of what I see:

] CPU: 0 PID: 1 ...
] Hardware name: innotek GmbH ...
] <some registers>
] Call Trace:
]  [<c0a1c995>] dump_stack+...
]  [<........>] panic+...
]  [<........>] do_exit+...
]  ...
] Kernel Offset: 0x0 from 0xc0400000 ...
] ---[ end Kernel panic - not syncing: Attempted to kill init! ...

Now, I'm assuming this is only the tail of the message that I want to see, but I have no means to view it (ex: cannot Shift-PageUp). When the panic occurs, the above text is never rendered for a second on the screen.

I first stumbled upon a KernelDebuggingTricks page which states:

Slowing down kernel messages on boot

... [Build] the kernel with the following option enabled:

CONFIG_BOOT_PRINTK_DELAY=y

And boot the machine with the following kernel boot parameter:

boot_delay=N

I have confirmed that my kernel (3.16) had built with the CONFIG_BOOT_PRINTK_DELAY option and have tried setting boot_delay to 10, 500 and 1000 milliseconds in my GRUB. Even with the 1000 millisecond delay set (and waiting for a good ~5 minutes), the entire kernal panic log message is spewed out in a blink of an eye.

Does anyone have any suggestions on how I can view the root of the kernel panic? The only thing I'm thinking now is manually adding sleeps into the kernel code (which is something I'd like to avoid).

Upvotes: 8

Views: 5665

Answers (2)

kdump and netdump are two more options if you don't have the convenience of a serial port, which is the case when running on metal for most current laptops. See this answer for more info: https://unix.stackexchange.com/a/60928/32558 The setup is more involved however.

Finally, you might also be interested in step debugging the kernel with JTAG or QEMU (not sure about Virtualbox support): Linux kernel live debugging, how it's done and what tools are used?

Upvotes: 0

user149341
user149341

Reputation:

Configure your virtual machine to log to the serial console as well as the console by adding console=ttyS0 console=tty0 to the boot parameters, then configure the serial port of your machine (in the VirtualBox settings) to output to a file. If a kernel panic occurs, the details will end up in that file.

For details, see: https://www.virtualbox.org/wiki/Serial_redirect

Upvotes: 8

Related Questions