Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I just completed an OS course. I heard the phrase "kernel panic" a lot. Can you explain

  1. What is a kernel panic?
  2. Why does it occur?
  3. How can I find out that a kernel panic occurred?
  4. What effect does it have on the system?
  5. Does it only occur in Linux?
  6. How can I prevent it?
share|improve this question
    
Kernel panic is part of an error message on macs. if it say's "panic we are hanging here" ( a guess is that it might be part of unix.) –  Alvar Apr 18 '11 at 10:34
13  
If you were doing an OS course, why didn't you ask your lecturers to explain the terminology they were using? You would have got a lot more out of your studies. –  TRiG Apr 18 '11 at 11:42
add comment

2 Answers

up vote 44 down vote accepted

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.'

share|improve this answer
3  
Add to q#2: missing boot files(eg. when an LVM volume is missing)... –  B. Roland Apr 18 '11 at 10:39
    
@B. Roland Added and credited –  hbdgaf Apr 18 '11 at 11:33
    
nice, thanks - I wrote it, because it once occured with me... (I accidentaly formatted a volume in LVM...) –  B. Roland Apr 18 '11 at 13:55
4  
This answer isn't correct. A kernel panic is not limited to just boot failures. JanC's answer is more correct ("kernel detects an error from which it can't recover"). Inability to boot is just one of many conditions. –  Kees Cook Apr 18 '11 at 18:19
2  
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. –  Rafał Cieślak Apr 20 '11 at 18:21
show 2 more comments

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.