:Kernel panic

{{Short description|Fatal error condition associated with Unix-like computer operating systems}}

File:Ubuntu 4.10 kernel paic.png, this one due to a VFS error.]]

{{Use mdy dates|date=October 2013}}

File:Kernel-panic.jpg system]]

File:Osol-dtrace-kp.png kernel panic.]]

File:Ubuntu 13.04 VirtualBox Kernel Panic.png (Linux kernel 3.8) in Oracle VM VirtualBox]]

A kernel panic (sometimes abbreviated as KP{{Cite web|title = KP - Kernel Panic (Linux) {{!}} AcronymFinder|url = http://www.acronymfinder.com/Kernel-Panic-(Linux)-(KP).html|website = www.acronymfinder.com|access-date = 2016-01-06|archive-date = October 26, 2015|archive-url = https://web.archive.org/web/20151026173210/http://www.acronymfinder.com/Kernel-Panic-(Linux)-(KP).html|url-status = live}}) is a safety measure taken by an operating system's kernel upon detecting an internal fatal error in which either it is unable to safely recover or continuing to run the system would have a higher risk of major data loss. The term is largely specific to Unix and Unix-like systems. The equivalent on Microsoft Windows operating systems is a stop error, often called a "blue screen of death".

The kernel routines that handle panics, known as panic() in AT&T-derived and BSD Unix source code, are generally designed to output an error message to the console, dump an image of kernel memory to disk for post-mortem debugging, and then either wait for the system to be manually rebooted, or initiate an automatic reboot.{{cite web|url=http://www.unix.com/man-page/FreeBSD/9/panic/|title=FreeBSD 11.0 - man page for panic (freebsd section 9) - Unix & Linux Commands|website=www.unix.com|access-date=October 26, 2010|archive-date=April 1, 2024|archive-url=https://web.archive.org/web/20240401232331/https://www.unix.com/man-page/FreeBSD/9/panic/|url-status=live}} The information provided is of a highly technical nature and aims to assist a system administrator or software developer in diagnosing the problem. Kernel panics can also be caused by errors originating outside kernel space. For example, many Unix operating systems panic if the init process, which runs in user space, terminates.{{cite web|url=http://www.unix.com/hp-ux/54221-boot-failure-init-died.html|title=boot failure-init died - Unix Linux Forums - HP-UX|website=www.unix.com|access-date=June 12, 2013|archive-date=April 1, 2024|archive-url=https://web.archive.org/web/20240401232240/https://www.unix.com/hp-ux/54221-boot-failure-init-died.html|url-status=live}}{{cite newsgroup|url=https://groups.google.com/forum/#!original/comp.sys.sgi.admin/HRY5oflBe48/tgnMPZ3vZFQJ|title=Re: PANIC: init died|author=Randolph J. Herber|newsgroup=comp.sys.sgi.admin|date=September 1, 1999|access-date=December 9, 2017|archive-date=January 22, 2011|archive-url=http://arquivo.pt/wayback/20110122130054/https://groups.google.com/forum/#!original/comp.sys.sgi.admin/HRY5oflBe48/tgnMPZ3vZFQJ|url-status=live}}

History

The Unix kernel maintains internal consistency and runtime correctness with assertions as the fault detection mechanism. The basic assumption is that the hardware and the software should perform correctly and a failure of an assertion results in a panic, i.e. a voluntary halt to all system activity.{{cite book|author1=Daniel P. Siewiorek|author2-link=Robert S. Swarz|author2=Robert S. Swarz|title=Reliable computer systems: design and evaluation|url=https://books.google.com/books?id=o15pmRSdQIIC&pg=PA622|access-date=May 6, 2011|year=1998|publisher=A K Peters, Ltd.|isbn=978-1-56881-092-8|page=622}} The kernel panic was introduced in an early version of Unix and demonstrated a major difference between the design philosophies of Unix and its predecessor Multics. Multics developer Tom van Vleck recalls a discussion of this change with Unix developer Dennis Ritchie:

I remarked to Dennis that easily half the code I was writing in Multics was error recovery code. He said, "We left all that stuff out. If there's an error, we have this routine called panic, and when it is called, the machine crashes, and you holler down the hall, 'Hey, reboot it.{{' "}}{{cite web|url=http://www.multicians.org/unix.html|title=Unix and Multics|website=www.multicians.org|access-date=May 25, 2005|archive-date=August 5, 2012|archive-url=https://web.archive.org/web/20120805155922/http://www.multicians.org/unix.html|url-status=live}}

File:WiiUKernelPanic.png kernel panic log file.]]

The original panic() function was essentially unchanged from Fifth Edition UNIX to the VAX-based UNIX 32V and output only an error message with no other information, then dropped the system into an endless idle loop. As the Unix codebase was enhanced, the panic() function was also enhanced to dump various forms of debugging information to the console.

Causes

A panic may occur as a result of a hardware failure or a software bug in the operating system. In many cases, the operating system is capable of continued operation after an error has occurred. If the system is in an unstable state, rather than risking security breaches and data corruption, the operating system stops in order to prevent further damage, which helps to facilitate diagnosis of the error and may restart automatically.{{cite book|author=Steven M. Hancock|title=Tru64 UNIX troubleshooting: diagnosing and correcting system problems|url=https://books.google.com/books?id=wh438GgIJtEC&pg=PA119|access-date=May 3, 2011|date=November 22, 2002|publisher=Digital Press|isbn=978-1-55558-274-6|pages=119–126}}

After recompiling a kernel binary image from source code, a kernel panic while booting the resulting kernel is a common problem if the kernel was not correctly configured, compiled or installed.{{cite book|author=Michael Jang|title=Linux annoyances for geeks|url=https://books.google.com/books?id=cNGbObmg6IwC&pg=PA267|access-date=April 29, 2011|year=2006|publisher=O'Reilly Media, Inc.|isbn=978-0-596-00801-7|pages=267–274}} Add-on hardware or malfunctioning RAM could also be sources of fatal kernel errors during start up, due to incompatibility with the OS or a missing device driver.{{cite book|author=David Pogue|title=Switching to the Mac: The Missing Manual, Snow Leopard Edition|url=https://books.google.com/books?id=SjuiTv7DepEC&pg=PA589|access-date=May 4, 2011|date=December 17, 2009|publisher=O'Reilly Media, Inc.|isbn=978-0-596-80425-1|page=589}} A kernel may also go into panic() if it is unable to locate a root file system.{{cite book|author=Greg Kroah-Hartman|title=Linux kernel in a nutshell|url=https://books.google.com/books?id=1rFLGKO0dywC&pg=PA59|access-date=May 3, 2011|year=2007|publisher=O'Reilly Media, Inc.|isbn=978-0-596-10079-7|page=59}} During the final stages of kernel userspace initialization, a panic is typically triggered if the spawning of init fails. A panic might also be triggered if the init process terminates, as the system would then be unusable.{{cite book|author=Wolfgang Mauerer|title=Professional Linux Kernel Architecture|url=https://books.google.com/books?id=e8BbHxVhzFAC&pg=PA1238|access-date=May 3, 2011|date=September 26, 2008|publisher=John Wiley and Sons|isbn=978-0-470-34343-2|pages=1238–1239|archive-date=April 1, 2024|archive-url=https://web.archive.org/web/20240401232239/https://books.google.com/books?id=e8BbHxVhzFAC&pg=PA1238|url-status=live}}

The following is an implementation of the Linux kernel final initialization in kernel_init():{{cite web |url=http://lxr.linux.no/linux+v3.10/init/main.c#L811 |title=linux/init/main.c |website=LXR Cross Referencer |archive-url=https://web.archive.org/web/20221006174048/http://lxr.linux.no/linux+v3.10/init/main.c#L811 |archive-date=October 6, 2022 |url-status=live}}

static int __ref kernel_init(void *unused)

{

...

/*

* We try each of these until one succeeds.

*

* The Bourne shell can be used instead of init if we are

* trying to recover a really broken machine.

*/

if (execute_command) {

if (!run_init_process(execute_command))

return 0;

pr_err("Failed to execute %s. Attempting defaults...\n",

execute_command);

}

if (!run_init_process("/sbin/init") ||

!run_init_process("/etc/init") ||

!run_init_process("/bin/init") ||

!run_init_process("/bin/sh"))

return 0;

panic("No init found. Try passing init= option to kernel. "

"See Linux Documentation/init.txt for guidance.");

}

Operating system specifics

=Linux=

{{See also|kdump (Linux)}}

File:Kernel panic message.png

File:Drm panic message.png

File:Drm panic with qr code.png

Kernel panics appear in Linux like in other Unix-like systems; however, serious but non-fatal errors can generate another kind of error condition, known as a kernel oops.{{cite web|url=https://lwn.net/images/pdf/LDD3/ch04.pdf|title=Linux Device Drivers, Chapter 4|access-date=July 21, 2016|archive-date=November 14, 2014|archive-url=https://web.archive.org/web/20141114011920/http://lwn.net/images/pdf/LDD3/ch04.pdf|url-status=live}} In this case, the kernel normally continues to run after killing the offending process. As an oops could cause some subsystems or resources to become unavailable, they can later lead to a full kernel panic.

On Linux, a kernel panic causes keyboard LEDs to blink as a visual indication of a critical condition.{{cite book

| url = https://books.google.com/books?id=FyRhZJ3h3VQC&q=linux+kernel+panic+keyboard+led+blinking&pg=PA62

| title = Linux Troubleshooting for System Administrators and Power Users

| date = May 2006

| access-date = 2016-02-05

| author1 = James Kirkland

| author2 = David Carmichael

| author3 = Christopher L. Tinker

| author4 = Gregory L. Tinker

| publisher = Prentice Hall

| page = 62

| isbn = 9780132797399

| archive-date = April 1, 2024

| archive-url = https://web.archive.org/web/20240401232239/https://books.google.com/books?id=FyRhZJ3h3VQC&q=linux+kernel+panic+keyboard+led+blinking&pg=PA62#v=snippet&q=linux%20kernel%20panic%20keyboard%20led%20blinking&f=false

| url-status = live

}}

As of Linux 6.10, drm_panic was merged allowing DRM drivers to support drawing a panic screen to inform the user that a panic occurred. This allows a panic screen to appear even when a display server was running when the panic occurred.{{cite web |url=https://fedoraproject.org/wiki/Changes/EnableDrmPanic |title=Changes/EnableDrmPanic |work=Fedora Project Wiki}}

As of Linux 6.12, drm_panic was extended where the stack trace can be encoded as a QR code.{{cite mailing list |url=https://lore.kernel.org/dri-devel/20240829144654.GA145538@linux.fritz.box/ |title=[PULL] drm-misc-next |author=Thomas Zimmermann |date=29 August 2024 |mailing-list=dri-devel}}

=macOS=

When a kernel panic occurs in Mac OS X 10.2 through 10.7, the computer displays a multilingual message informing the user that they need to reboot the system.{{cite web|url=http://support.apple.com/kb/TS3742|title=OS X: About kernel panics - Apple Support|website=support.apple.com|archive-date=May 21, 2013|archive-url=https://web.archive.org/web/20130521042317/http://support.apple.com/kb/TS3742|url-status=dead}} Prior to 10.2, a more traditional Unix-style panic message was displayed; in 10.8 and later, the computer automatically reboots and the message is only displayed as a skippable warning afterward. The format of the message varies from version to version:{{cite web|url=http://osxbook.com/book/bonus/chapter5/panic/|title=A New Screen of Death for Mac OS X|website=OSXBook.com|access-date=April 30, 2011|archive-date=May 1, 2012|archive-url=https://web.archive.org/web/20120501191934/http://osxbook.com/book/bonus/chapter5/panic/|url-status=dead}}

  • 10.0–10.1: The system displays text on the screen, giving details about the error, and becomes unresponsive.
  • 10.2: Rolls down a black transparent curtain then displays a message on a white background informing the user that they should restart the computer. The message is shown in English, French, German and Japanese.
  • 10.3–10.5: Similar to 10.2, but the background of the error message is dark grey.
  • 10.6–10.7: The text has been revised and now includes a Spanish translation.
  • 10.8 and later: The computer becomes unresponsive before it immediately reboots. After restarting, it shows a message for a few seconds informing the user that a problem caused the computer to restart, before continuing to boot. The message now includes a Chinese translation.

If five new kernel panics occur within three minutes of the first one, the Mac will display a prohibitory sign for thirty seconds, and then shut down; this is known as a "recurring kernel panic".{{cite web |title=OS X: About kernel panics |url=https://support.apple.com/en-us/TS3742 |url-status=dead |archive-url=https://web.archive.org/web/20180524032449/https://support.apple.com/en-us/TS3742 |archive-date=May 24, 2018 |website=Apple Support |publisher=Apple}}

In all versions above 10.2, the text is superimposed on a standby symbol and is not full screen. Debugging information is saved in NVRAM and written to a log file on reboot. In 10.7 there is a feature to automatically restart after a kernel panic. In some cases, on 10.2 and later, white text detailing the error may appear in addition to the standby symbol.

File:Mac OS X 10.0 10.1 Kernel Panic.jpg|Mac OS X 10.0–10.1 kernel panic

File:Mac OS X 10.2 Kernel Panic.jpg|Mac OS X 10.2 kernel panic

File:MacOSX kernel panic.png|Mac OS X 10.3–10.5 kernel panic

File:Panic10.6.png|Mac OS X 10.6 and 10.7 kernel panic

File:OS X Mountain Lion kernel panic.jpg|Message shown after a system restart due to a kernel panic in OS X 10.8 and later versions

See also

References