Kernel Crash Forensics
This skill is done when the event is classified as a kernel crash, a watchdog reset, a power loss or a deliberate action, with the evidence line that shows it, and, if it was a crash or can recur, the host is configured so the next occurrence leaves a journal, a console log or a vmcore.
The usual failure is theorising first. "It must be a memory leak" or "it must be the new driver" is stated before anyone has established that the host crashed at all; many unexplained reboots are power events, a hardware watchdog, a hypervisor action or a person. The second failure is capturing nothing: a volatile journal and no kdump mean the evidence of the first crash is gone, and the investigation waits for a second.
Scope
Use for: a host that restarted with no known reason; panics, oopses, soft or hard lockups, hung-task warnings; setting a host up to capture the next crash; reading a vmcore or an oops.
Do not use for: a host that fails to boot (boot-failure-recovery); the OOM killer (oom-kill-forensics); a crashing application process (debugging).
Workflow
1. Establish what happened, from last-boot evidence
journalctl --list-boots # how many boots survive; a single entry means the journal is volatile
journalctl -b -1 -k -e --no-pager # kernel log of the previous boot, end first
journalctl -b -1 --no-pager | tail -100 # what everything was doing at the end
last -x reboot shutdown | head # a reboot with no shutdown record before it means no clean shutdown
ls /sys/fs/pstore /var/lib/systemd/pstore # crash records kept across the reboot, if the platform has pstore
ipmitool sel elist # BMC system event log: power loss, watchdog reset, thermal, ECC
Decide with these cues:
- The previous boot's log ends abruptly with no shutdown messages and no panic text: power loss, a hardware watchdog reset, a hypervisor action or a hard lockup that could not log. The BMC event log and the hypervisor's own log settle which.
- The log ends with
Kernel panic,BUG:orOops:: a kernel crash. Keep the whole block. - Shutdown messages appear before the end: someone or something asked for it. Check
last -x, the journal forsystemd-logindand the unit that requested it, and the change record.
If the journal holds only one boot, say so: the storage is volatile, and step 3 comes before any conclusion.
2. Read the evidence, from the top
An oops is a cascade. Read from the first warning, not the final trace, because the last lines show the system falling over after the original fault. In order:
- The first
WARNING,BUGorOopsline and the function it names. - The
Tainted:flags.PorOmean a proprietary or out-of-tree module is loaded, which changes who can accept the report;Wmeans an earlier warning already happened;Dmeans the kernel died with an oops;Mmeans a machine check.cat /proc/sys/kernel/taintedshows the live mask. Readreferences/taint-and-messages.mdfor the full table. - The
Modules linked in:list, for third-party or recently changed modules. - The kernel build, from the
Hardware nameand version line, since a known bug is tied to an exact version. - For
BUG: soft lockup - CPU#N stuck for Ns!a CPU ran in kernel code without scheduling; forINFO: task X blocked for more than 120 secondsa task was in uninterruptible sleep, usually on storage or a lock; the stack shows what it waited for.
3. Check the hardware before the software
Memory, disk and bus faults produce panics that look like software bugs.
ras-mc-ctl --summary # corrected and uncorrected memory errors by controller (rasdaemon)
ras-mc-ctl --errors # individual error records
journalctl -k -b -1 | grep -iE 'mce|machine check|edac|nvme.*reset|blk_update_request|I/O error|ata[0-9]+.*(error|reset)'
Corrected memory errors that repeat on one DIMM, any uncorrected error, repeated NVMe or SATA link resets, and thermal throttling events in the BMC log all point at hardware. Replace or reseat the part before chasing a kernel bug, and keep the host out of the critical path meanwhile.
4. Make the next crash capturable
Do this whenever the cause is not yet known, even when the crash looks like hardware. Propose the change; applying it is the owner's call.
- Persistent journal. Create
/var/log/journalor setStorage=persistentinjournald.conf, then restartsystemd-journald. Without it, boots earlier than the last are lost. - kdump. Install the distribution's kdump package, reserve memory with
crashkernel=on the kernel command line (the size depends on memory and distribution defaults; use the distribution's documented value, then test), enable the service, and confirm withkdumpctl statusorkdump-config showandcat /sys/kernel/kexec_crash_loaded(1 when loaded). Test it once, on a drained host in a window, by deliberately crashing it withecho c > /proc/sysrq-trigger; an untested kdump is a guess. The dump lands in/var/crashby default. - Panic behaviour, set deliberately.
kernel.panic=Nreboots N seconds after a panic (0 waits forever).kernel.softlockup_panic=1,kernel.hung_task_panic=1andkernel.panic_on_oops=1turn those conditions into panics so kdump fires; set them only where a restart is better than a stuck host, and understand that a hung-task panic can fire on a slow disk that would have recovered. - Remote logging.
netconsolesends kernel messages over UDP to a collector; a serial console or the BMC's serial-over-LAN does the same for early and late messages. The last lines before a hard hang rarely reach local disk.
5. Analyse a vmcore, if there is one
Open it with the crash utility and the matching vmlinux (from the debug-symbol package for that exact kernel build). makedumpfile --dump-dmesg VMCORE OUTFILE extracts the kernel log without the symbols. Inside crash, log prints the log, bt the backtrace of the panicking task and ps the task states. The symbols must match the running build or the output is wrong.
6. Classify, and verify against the vendor
Place the event in one class and state the evidence: hardware (BMC or EDAC records, repeated device resets), driver or module (the faulting function is in a third-party or recently updated module, taint flags show it), or known kernel bug (the first warning matches a bug report for this kernel build). For the third, search the distribution's bug tracker and the kernel changelog with the exact build string, not just the symptom. If nothing matches, the next step is the capture in step 4, not a guess.
Output format
## What happened
[Crash, watchdog, power, or deliberate; the evidence line.]
## Fault
[First warning, function, taint flags, modules, kernel build.]
## Hardware checks
[EDAC, disk and NVMe resets, BMC events.]
## Classification
[Hardware, driver or kernel bug; the bug reference or why none.]
## Capture configuration
[Persistent journal, kdump tested or not, panic settings, remote logging.]
Anti-patterns
Starting from the last trace. The final lines are the collapse, not the cause.
Blaming software before hardware. Uncorrected memory errors produce arbitrary panics.
An untested kdump. A reserved size that is too small produces no dump on the day it matters.
Panic settings applied fleet-wide as a reflex. A hung-task panic can turn a slow disk into a reboot.
Searching the symptom, not the build. Kernel bugs are fixed per version.
Reference files
references/taint-and-messages.md- read at step 2: taint flag letters, what the lockup and hung-task messages mean, and the sysctls that govern them.