Kernel panic explained

A kernel panic (sometimes abbreviated as KP[1]) 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.[2] 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.[3] [4]

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.[5] 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.[6]

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.

Source code of panic function in V6 UNIX:[7] /* * In case console is off, * panicstr contains argument to last * call to panic. */char *panicstr;

/* * Panic is called on unresolvable * fatal errors. * It syncs, prints "panic: mesg" and * then loops. */panic(s)char *s;

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. However, the system is in an unstable state and rather than risking security breaches and data corruption, the operating system stops to prevent further damage and facilitate diagnosis of the error and, in usual cases, restart.[8]

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.[9] 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.[10] A kernel may also go into panic if it is unable to locate a root file system.[11] 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.[12]

The following is an implementation of the Linux kernel final initialization in kernel_init:[13] static int __ref kernel_init(void *unused)

Operating system specifics

Linux

See also: kdump (Linux).

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.[14] 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.[15]

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.[16] 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:[17]

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".[18]

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.

See also

Notes and References

  1. Web site: KP - Kernel Panic (Linux) AcronymFinder. www.acronymfinder.com. 2016-01-06. October 26, 2015. https://web.archive.org/web/20151026173210/http://www.acronymfinder.com/Kernel-Panic-(Linux)-(KP).html. live.
  2. Web site: FreeBSD 11.0 - man page for panic (freebsd section 9) - Unix & Linux Commands. www.unix.com. October 26, 2010. April 1, 2024. https://web.archive.org/web/20240401232331/https://www.unix.com/man-page/FreeBSD/9/panic/. live.
  3. Web site: boot failure-init died - Unix Linux Forums - HP-UX. www.unix.com. June 12, 2013. April 1, 2024. https://web.archive.org/web/20240401232240/https://www.unix.com/hp-ux/54221-boot-failure-init-died.html. live.
  4. Re: PANIC: init died. Randolph J. Herber. comp.sys.sgi.admin. September 1, 1999. December 9, 2017. January 22, 2011. http://arquivo.pt/wayback/20110122130054/https://groups.google.com/forum/#!original/comp.sys.sgi.admin/HRY5oflBe48/tgnMPZ3vZFQJ. live.
  5. Book: Daniel P. Siewiorek. Robert S. Swarz. Robert S. Swarz. Reliable computer systems: design and evaluation. May 6, 2011. 1998. A K Peters, Ltd.. 978-1-56881-092-8. 622.
  6. Web site: Unix and Multics. www.multicians.org. May 25, 2005. August 5, 2012. https://web.archive.org/web/20120805155922/http://www.multicians.org/unix.html. live.
  7. Web site: Source code /usr/sys/ken/prf.c . https://web.archive.org/web/20210224184840/https://minnie.tuhs.org/cgi-bin/utree.pl?file=V6/usr/sys/ken/prf.c . February 24, 2021 . live. from V6 UNIX
  8. Book: Steven M. Hancock. Tru64 UNIX troubleshooting: diagnosing and correcting system problemsHP Technologies SeriesITPro collection. May 3, 2011. November 22, 2002. Digital Press. 978-1-55558-274-6. 119–126.
  9. Book: Michael Jang. Linux annoyances for geeks. April 29, 2011. 2006. O'Reilly Media, Inc.. 978-0-596-00801-7. 267–274.
  10. Book: David Pogue. Switching to the Mac: The Missing Manual, Snow Leopard Edition. May 4, 2011. December 17, 2009. O'Reilly Media, Inc.. 978-0-596-80425-1. 589.
  11. Book: Greg Kroah-Hartman. Linux kernel in a nutshell. May 3, 2011. 2007. O'Reilly Media, Inc.. 978-0-596-10079-7. 59.
  12. Book: Wolfgang Mauerer. Professional Linux Kernel Architecture. May 3, 2011. September 26, 2008. John Wiley and Sons. 978-0-470-34343-2. 1238–1239. April 1, 2024. https://web.archive.org/web/20240401232239/https://books.google.com/books?id=e8BbHxVhzFAC&pg=PA1238. live.
  13. Web site: linux/init/main.c . . https://web.archive.org/web/20221006174048/http://lxr.linux.no/linux+v3.10/init/main.c#L811 . October 6, 2022 . live.
  14. Web site: Linux Device Drivers, Chapter 4. July 21, 2016. November 14, 2014. https://web.archive.org/web/20141114011920/http://lwn.net/images/pdf/LDD3/ch04.pdf. live.
  15. Book: Linux Troubleshooting for System Administrators and Power Users . May 2006 . 2016-02-05 . James Kirkland . David Carmichael . Christopher L. Tinker . Gregory L. Tinker . . 62 . 9780132797399 . April 1, 2024 . 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 . live .
  16. Web site: OS X: About kernel panics - Apple Support. support.apple.com. May 21, 2013. https://web.archive.org/web/20130521042317/http://support.apple.com/kb/TS3742. dead.
  17. Web site: A New Screen of Death for Mac OS X. OSXBook.com. April 30, 2011. May 1, 2012. https://web.archive.org/web/20120501191934/http://osxbook.com/book/bonus/chapter5/panic/. dead.
  18. Web site: OS X: About kernel panics . dead . https://web.archive.org/web/20180524032449/https://support.apple.com/en-us/TS3742 . May 24, 2018 . Apple Support . Apple.