What is kernel panic?

1 Question at a time per the FAQ

  1. What is kernel panic?
    When the kernel can't load properly or "freaks out" and fails to boot properly or crashes(see edit credit at the bottom).

  2. Why it occurs?
    Hosed updates, failing hardware, unsupported hardware, failed or missing drive or partition (see edit credit at the bottom)

  3. How can I understand kernel panic occurred?
    Watch boot prompts(turn off quiet kernel parameter) OR your machine fails to boot

  4. What effect it has on system?
    Failure to boot or system crash

  5. Does it only occur in Linux?
    No, all unix-like operating systems can have kernel panics. It's the equivalent of a Windows Blue Screen of Death

  6. How can I prevent it?
    It normally doesn't happen. Test updates and troubleshoot the problem. Use stable instead of development branches.

Additional note: Kernel panic and system failure/shutdown can be directly responsible for protecting your computer from physical damage. Examples include halting before extreme overheating or disk corruption. See edit credits at the bottom for direct quote.

edits

Per B. Roland Missing or corrupted disks or volumes can cause this as well.
(Good point and I overlooked it)

Per Kees Kernel panic can also occur while running.
note: Can happen when a function fails sort of gracefully inside the kernel, but most often happens during module or kernel loading(which is usually during boot). I thought I touched on it at "during boot or system crash", but I see how my answer to (1) stated it only occurs during boot.

Per rafalcieslak direct quote - 'There is one very important thing that must be added: The main point in the whole kernel panic is to protect your computer. The kernel freezes not only because it failed to do something, but also in order to prevent your computer from f.e. overheating, hard drives corruption, and any other hardware problems, that may occur, if some incorrect orders are executed, of a module (for example a module responsible for controlling the fan) failed to load, etc. This is why the kernel prefers to freeze, than to overcome the problem.'


A kernel panic happens when the kernel detects an error from which it can't recover. A function named panic() to handle this situation (often by dumping some debug info and/or rebooting the system) was first introduced in one of the very early UNIX versions, so that's where the name comes from (and it's still called that in most UNIX-like operating systems, including Mac OS X).

The famous Blue Screen Of Death (officially called a Fatal system error, as in VMS/OpenVMS) in Microsoft's NT kernel is also a form of "kernel panic".

A linux kernel error from which the kernel can (partially or temporarily) recover is called a kernel oops (you might see those in dmesg output sometimes).

The reasons for a kernel panic can be a bug in the kernel (e.g. in a driver that is part of the kernel) or a hardware or software issue that causes an unexpected/unpredictable condition for the kernel (e.g. when it is impossible to start the init proces, or it gets killed).

To find out what caused it you can see if anything was printed on the screen or to a serial console (if you configured one). If it is configured to do so you can also have the system make a linux kernel crash dump, which saves the kernel memory to disk in case of a panic, so that a kernel developer can analyze it (of course, that requires it to be able to write to a disk). In some cases /var/log/messages might also have useful info (e.g. in some cases recovering from an oops may lead to an unrecoverable error later). There is some more detailed info here.

Tags:

Kernel