Overview
3 AM. Your alarm goes off. You log into the server and see a single line on the screen: Kernel panic - not syncing: Fatal exception. Then the system reboots. When you finally get back in, the crash scene is completely gone — no logs, no core dump, no call trace. You stare at systemd-logind: System is going down with nothing to work with.
If you’ve been in ops for a few years, you’ve been there. Kernel panics are painful enough, but the real nightmare is when you can’t capture anything after the crash — the problem becomes impossible to diagnose.
That’s exactly what kdump solves. Think of it as a flight recorder for Linux servers. When a plane crashes, the black box tells you what happened in the final seconds. When a kernel panics, kdump preserves the complete memory state at the crash moment, so you can analyze it frame by frame afterward using the crash tool.
This article is straight to the point — from how kdump works under the hood, through the complete production configuration process, to hands-on analysis with the crash tool. After reading this, you should be able to set up a reliable crash capture system on your own servers.
How kdump Works
The Dual-Kernel Mechanism
To understand kdump, you first need to grasp a key concept: the crashed kernel is no longer trustworthy. You can’t expect a kernel that’s already panicking to cleanly save its own memory — it can barely execute code at all.
kdump’s approach is clever: at system boot, it reserves a block of physical memory and loads a stripped-down “capture kernel” (also called the second kernel) into it. While the primary kernel runs normally, this reserved memory is isolated — nothing touches it. When the primary kernel crashes, the kexec mechanism directly transfers CPU control to the capture kernel — no BIOS, no hardware reboot, it just starts running in the reserved memory. Once the capture kernel takes over, the primary kernel’s memory contents are still intact, and the capture kernel packages them into a vmcore file on disk.
The whole process looks like this:
┌──────────────────────────────────────────────┐
│ Physical Memory Layout │
│ │
│ ┌────────────────┐ ┌───────────────────┐ │
│ │ Primary Kernel │ │ Reserved Memory │ │
│ │ (running) │ │ (crashkernel) │ │
│ │ │ │ │ │
│ │ User processes │ │ Capture kernel + │ │
│ │ Kernel modules │ │ initramfs │ │
│ │ Page cache... │ │ (standing by) │ │
│ └────────────────┘ └───────────────────┘ │
│ │
│ Primary crashes → kexec switch → capture │
│ kernel boots → reads /proc/vmcore → writes │
│ to /var/crash/ │
└──────────────────────────────────────────────┘
kexec: Hot-Switching Without Rebooting
kexec is the underlying technology that makes kdump possible. It allows loading a kernel image directly into memory and jumping to it — without going through the BIOS boot sequence. A normal reboot goes through BIOS POST, GRUB bootloader, kernel decompression — a long chain that can take minutes. kexec skips all of that and jumps directly from one kernel to another in milliseconds.
This is critical for crash capture: after the primary kernel panics, the data in memory will be lost if not captured quickly. kexec’s fast switching lets the capture kernel freeze the crash scene before the memory data gets corrupted.
According to the Red Hat Kernel Crash Dump Guide, the kdump workflow breaks down into these steps:
- At boot, the
crashkernelkernel parameter reserves memory - After the primary kernel boots, the kdump service loads the capture kernel into the reserved memory
- The primary kernel runs normally; the capture kernel stands by
- The primary kernel crashes; kexec triggers the capture kernel to boot
- The capture kernel mounts the filesystem and dumps the primary kernel’s memory as vmcore
- After the dump completes, the capture kernel reboots the system
Production Configuration Guide
Installing Required Components
CentOS / RHEL:
# Install kexec-tools (includes kdump service and kexec tool)
sudo dnf install kexec-tools
# Install crash tool (for post-mortem vmcore analysis)
sudo dnf install crash
# Install kernel debuginfo package (required by crash, package name matches kernel version)
sudo dnf install kernel-debuginfo-$(uname -r)
Ubuntu / Debian:
sudo apt install kexec-tools makedumpfile crash
sudo apt install linux-image-$(uname -r)-dbg
On Ubuntu, the kexec-tools installer will prompt you whether to enable kdump on crashes — choose Yes.
Reserving Memory: the crashkernel Parameter
This is the most critical step in configuring kdump, and also the most error-prone.
crashkernel is a kernel boot parameter that tells the kernel “reserve this much memory for the capture kernel.” It’s set in the GRUB configuration.
Edit /etc/default/grub:
# Edit GRUB configuration
sudo vi /etc/default/grub
# Add crashkernel parameter to GRUB_CMDLINE_LINUX line
# Common patterns:
# crashkernel=256M Fixed reservation of 256M
# crashkernel=auto Auto-calculate (RHEL supports this, but can be inaccurate)
# crashkernel=128M@64M Reserve 128M starting at offset 64M
# crashkernel=2G-16G:256M,16G-64G:512M Tiered reservation based on system memory
GRUB_CMDLINE_LINUX="crashkernel=256M rd.lvm.lv=centos/root rhgb quiet"
How much memory to reserve? This is the most common question. My rule of thumb:
| System RAM | Recommended crashkernel | Notes |
|---|---|---|
| 4G - 8G | 128M - 256M | Small memory machines, minimize reservation |
| 8G - 16G | 256M | Common config, sufficient |
| 16G - 64G | 256M - 512M | Medium scale, leave some headroom |
| 64G - 256G | 512M - 768M | Large memory, vmcore will be bigger too |
| 256G+ | 768M - 1G | Very large memory, may need 1G+ |
The actual requirement depends on kernel version, number of loaded modules, and how much filtering you do with makedumpfile. The best approach is to start with the recommended value, then trigger an actual crash test to verify the capture kernel can boot and complete the dump.
Update GRUB and reboot:
# RHEL/CentOS 7
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
# RHEL/CentOS 8+ / Fedora
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
# Or (EFI systems)
sudo grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
# Ubuntu / Debian
sudo update-grub
# Reboot to activate crashkernel reservation
sudo reboot
Verify the reservation after reboot:
# Check if kernel boot parameters include crashkernel
cat /proc/cmdline | grep crashkernel
# Check reserved memory region
dmesg | grep -i "crashkernel"
# Expected output:
# Reserving 256MB of memory at 800MB for crashkernel
# Check kdump service status
systemctl status kdump.service
kdump Configuration File
kdump’s main configuration file is /etc/kdump.conf (RHEL/CentOS) or /etc/default/kdump-tools (Ubuntu). This controls where dump files are stored, compression method, notification scripts, etc.
A production-grade configuration example:
# /etc/kdump.conf
# vmcore storage path (default: /var/crash)
path /var/crash
# Core collector: makedumpfile
# -d 8: Filter out these page types (bitmask):
# 1=zero pages, 2=cache pages, 4=cache private, 8=user data,
# 16=free pages
# -c: Compress output
# Use -d 31 to filter all filterable pages, significantly reducing vmcore size
core_collector makedumpfile -l --message-level 1 -d 31
# Action after dump completes (default: reboot)
# Options: reboot / halt / poweroff / shell
# shell mode drops to a shell after dumping, useful for manual inspection
default reboot
# Dump target override (optional)
# If /var/crash is on a small partition, specify a different target
# ext4 /dev/sdb1
# nfs my.nfs.server:/export/crashdumps
# Behavior on dump failure
# failure_action options: continue / halt / reboot / shell
# Recommended for production: shell — at least gives you a chance to troubleshoot
failure_action shell
Let’s expand on makedumpfile filter levels. If you save all memory as-is in vmcore, a machine with 64G of RAM produces a 64G dump file — writing it to disk takes a long time and could fill up the /var/crash partition. makedumpfile analyzes the kernel’s page table structure to filter out unneeded pages:
| Filter Flag | Filtered Content | Space Saved |
|---|---|---|
-d 1 | Zero pages | 5-15% |
-d 2 | Kernel page cache | 10-30% |
-d 4 | Private cache pages | 5-10% |
-d 8 | Userspace process data | 30-60% |
-d 16 | Free pages | 20-50% |
-d 31 | All of the above | Typically 70-90% reduction |
For production, -d 31 is recommended unless you need to inspect a userspace process’s memory in the vmcore. Adding -l for compression typically reduces vmcore from 100% of raw memory to 5-15%.
Configuring SSH Remote Dumping
If your server has limited local disk space, or the local filesystem might be unavailable after a crash (e.g., root partition is on LVM and the LVM has issues), you can dump vmcore directly to a remote server:
# /etc/kdump.conf
# SSH remote dumping
ssh root@crash-collector.internal
sshkey /root/.ssh/id_rsa
path /data/crashdumps
core_collector makedumpfile -l --message-level 1 -d 31
default reboot
When configuring remote dumping, ensure:
- The capture kernel’s initramfs includes the SSH client and network drivers
- The target server has the source server’s key in
authorized_keys - Network configuration works in the initramfs environment (may need static IP or DHCP)
Regenerate initramfs to apply the configuration:
# RHEL/CentOS
sudo kdumpctl restart
# Ubuntu/Debian
sudo systemctl restart kdump-tools
Verifying kdump Service
# Check service status
systemctl status kdump
# Check if capture kernel is loaded into reserved memory
# Method 1: Check kexec load status
kexec -p -l /boot/vmlinuz-$(uname -r) 2>&1
# If already loaded, it will say "kexec_load failed: File exists" or similar
# Method 2: Check kdump kernel load log
dmesg | grep -i kdump
# Expected output:
# kdump: Loaded kdump kernel at 0x...
# kdump: kexec: kdump kernel loaded
# Method 3: Check /sys/kernel/kexec_loaded
cat /sys/kernel/kexec_loaded
# 0 = not loaded, 1 = loaded (should be 1 when kdump is working)
# Check kexec_crash_loaded (whether crash capture kernel is loaded)
cat /sys/kernel/kexec_crash_loaded
# 1 = crash capture kernel is in place
Manually Triggering a Crash Test
If you don’t test after configuring, it’s as good as not configuring. I do this on every new server before it goes live.
Warning: This will immediately crash and reboot your server. Make sure no business traffic is running, or use a test machine.
# Step 1: Confirm kdump service is healthy
systemctl status kdump
# Step 2: Confirm panic_on_oops is enabled
sysctl kernel.panic_on_oops
# Should be 1; if not:
sudo sysctl -w kernel.panic_on_oops=1
# Step 3: Ensure auto-reboot after panic
sysctl kernel.panic
# Value > 0 means reboot after N seconds; 0 means no auto-reboot
# Recommended:
sudo sysctl -w kernel.panic=10
# Step 4: Sync disk data to avoid filesystem corruption
sync && sync && sync
# Step 5: Trigger kernel crash!
# Method A: Via SysRq (recommended)
echo c > /proc/sysrq-trigger
# Method B: If SysRq is disabled, enable it first
echo 1 > /proc/sys/kernel/sysrq
echo c > /proc/sysrq-trigger
echo c > /proc/sysrq-trigger triggers a null pointer dereference that causes a kernel panic. If your kdump is configured correctly, the system will:
- Print panic information to the console
- kexec switches to the capture kernel
- The capture kernel boots and starts collecting vmcore
- After collection completes, the system auto-reboots
Check after reboot:
# Check if vmcore was saved
ls -lh /var/crash/
# Expected to see something like:
# drwxr-xr-x 2 root root 4096 Jul 17 09:20 127.0.0.1-2026-07-17-09:20:01
# Inside should be vmlinux (or vmlinuz) and vmcore files
# Check vmcore file size
ls -lh /var/crash/*/vmcore*
# Compressed vmcore is typically between a few hundred MB to a few GB
Common Configuration Failure Troubleshooting
If you don’t find vmcore after triggering a crash, or the kdump service won’t start at all, follow this checklist:
Problem 1: kdump.service fails to start
# View specific errors
journalctl -u kdump.service -e
# Most common cause: crashkernel parameter not set or insufficient reservation
# Check:
cat /proc/cmdline | grep crashkernel
# If no crashkernel= parameter, GRUB config wasn't updated
# Check if memory reservation took effect
dmesg | grep -i crashkernel
# If you see "crashkernel reservation failed", the reservation failed
# Possible causes: too little memory, or reserved address conflicts with another region
As noted in this CSDN article on kdump.service startup failures, incorrect crashkernel parameter configuration is the “number one culprit” for kdump startup failures.
Problem 2: No vmcore generated after crash
# Check if there are kdump logs
journalctl -b -1 | grep -i kdump
# -b -1 means previous boot's logs
# Check if /var/crash has space
df -h /var/crash
# Check console output (if you have serial console or IPMI logs)
# Common causes:
# 1. Capture kernel's initramfs missing disk drivers
# 2. /var/crash partition out of space
# 3. makedumpfile parameter errors
Problem 3: crashkernel=auto doesn’t work
crashkernel=auto may fail to correctly calculate reservation size in some environments (especially VMs or custom kernels). I recommend using a fixed value instead of auto. VM environments are particularly tricky — some hypervisors don’t support crashkernel memory reservation.
Analyzing vmcore with the crash Tool
Getting a vmcore is just the first step — without analysis, it’s useless. The crash tool is the standard tool for analyzing vmcore. Combined with kernel debuginfo, it lets you debug the kernel as if you were using GDB on a userspace program.
Starting crash
# Basic usage: crash <vmcore> <vmlinux-debuginfo>
# vmlinux-debuginfo is typically at /usr/lib/debug/lib/modules/$(uname -r)/vmlinux
crash /var/crash/127.0.0.1-2026-07-17-09:20:01/vmcore \
/usr/lib/debug/lib/modules/$(uname -r)/vmlinux
If you can’t find the vmlinux debuginfo file:
# RHEL/CentOS
sudo dnf install kernel-debuginfo-$(uname -r)
# Ubuntu
sudo apt install linux-image-$(uname -r)-dbg
# Find vmlinux file location
find /usr/lib/debug -name vmlinux
Common crash Commands
Once in the crash interactive prompt, these commands are most frequently used:
crash> bt # Print kernel call trace at crash time (most used)
crash> bt -a # Print call traces for all CPUs
crash> ps # List all processes at crash time
crash> ps | grep -i "D" # Filter D-state (uninterruptible sleep) processes
crash> log # Print kernel log buffer (dmesg content)
crash> sys # Show system info (kernel version, CPU, memory, etc.)
crash> files # List open files at crash time
crash> vm # Show virtual memory info
crash> kmem -i # Kernel memory usage overview
crash> dev -l # List loaded device drivers
crash> mod # List loaded kernel modules
crash> mod -s <name> # Load debug info for a specific module
crash> struct <type> <addr> # Inspect struct contents at given address
crash> rd <addr> <count> # Read memory
crash> dis <addr> # Disassemble code at given address
Practical Analysis Example
Suppose we triggered a panic. Let’s analyze the crash cause with crash:
# 1. First look at the call trace to determine where the crash occurred
crash> bt
PID: 0 TASK: ffffffff81c10480 CPU: 0 COMMAND: "swapper/0"
#0 [ffff88003fc03c90] machine_kexec at ffffffff8105f7a0
#1 [ffff88003fc03ce0] crash_kexec at ffffffff810b0a72
#2 [ffff88003fc03db0] oops_end at ffffffff81009524
#3 [ffff88003fc03dd0] no_context at ffffffff8104b6a5
#4 [ffff88003fc03e20] __bad_area_nosemaphore at ffffffff8104b6e5
#5 [ffff88003fc03e70] bad_area at ffffffff8104b810
#6 [ffff88003fc03ea0] do_page_fault at ffffffff8104bd76
#7 [ffff88003fc03f30] page_fault at ffffffff816012b8
[exception RIP: my_driver_write+42]
RIP: ffffffffa0001234 RSP: ffff88003fc03fe8 RFLAGS: 00010246
RAX: 0000000000000000 RBX: ffff88003e8a0000 RCX: 0000000000000000
RDX: 0000000000000100 RSI: ffff88003e8a1000 RDI: 0000000000000000
RBP: ffff88003fc03ff0
#8 [ffff88003fc03ff8] sys_write at ffffffff811df3a2
# Call trace interpretation:
# 1. sys_write was called (userspace write syscall)
# 2. Entered my_driver_write (custom driver module's write function)
# 3. page_fault occurred (page fault exception)
# 4. bad_area → no_context → oops_end → crash_kexec → machine_kexec
# Conclusion: my_driver_write accessed an invalid memory address, triggering a page fault
# 2. Disassemble the code at the crash location
crash> dis ffffffffa0001234
0xffffffffa0001234 <my_driver_write+42>: mov %rax,(%rdi)
# RDI = 0 (from register info above), mov %rax,(0) is a null pointer dereference
# 3. Check which module this belongs to
crash> mod -s my_driver
MODULE NAME SIZE OBJECT FILE
ffff88003e8a0000 my_driver 16384 /lib/modules/.../my_driver.ko
# 4. View the source code in the module (requires debuginfo)
crash> sym ffffffffa0001234
ffffffffa0001230 (t) my_driver_write+38 /usr/src/my_driver/write.c: 42
# Located write.c line 42 — found an uninitialized pointer being written to
This example demonstrates the complete workflow of going from vmcore to a specific line of code. In practice, most kernel panics can be traced to the problem function in three steps: bt → dis → sym.
Analyzing D-State Processes
Sometimes crashes aren’t caused by null pointers but by deadlocks — processes stuck in D state (uninterruptible sleep), eventually triggering hung task detection and a panic. In these cases, you need a different approach:
# Find D-state processes
crash> ps | grep "UN"
PID PPID CPU TASK ST %MEM VSZ RSS COMM
12345 1 0 ffff88003e5b8000 UN 0.2 262144 8192 mysql
# UN = Uninterruptible Sleep
# View this process's call trace
crash> bt ffff88003e5b8000
PID: 12345 TASK: ffff88003e5b8000 CPU: 0 COMMAND: "mysql"
#0 [ffff88003e8a3d80] __schedule at ffffffff8109a2a3
#1 [ffff88003e8a3dd0] schedule at ffffffff8109a3a5
#2 [ffff88003e8a3e00] schedule_timeout at ffffffff8109a6b0
#3 [ffff88003e8a3e50] wait_for_completion at ffffffff8109a8c0
#4 [ffff88003e8a3ea0] flush_work at ffffffff81098123
#5 [ffff88003e8a3ef0] __cancel_work_timer at ffffffff81098456
#6 [ffff88003e8a3f50] cancel_work_sync at ffffffff81098501
# This process is stuck in cancel_work_sync → wait_for_completion
# Meaning a work_struct never completed execution
# Check what this process is waiting for
crash> struct task_struct ffff88003e5b8000
struct task_struct {
...
state = 2, // TASK_UNINTERRUPTIBLE
...
}
Kernel Parameters Related to kdump
Besides crashkernel, several other kernel parameters affect kdump behavior. Recommended for production:
# /etc/sysctl.d/99-kdump.conf
# Trigger kdump on panic (instead of just rebooting)
kernel.panic_on_oops = 1
# Auto-reboot N seconds after panic (gives kdump time to complete dump)
# Too short may cut off the dump before it finishes
kernel.panic = 10
# SysRq functionality (allows manual crash trigger via /proc/sysrq-trigger)
kernel.sysrq = 1
# Hung task detection: processes in D state beyond this many seconds trigger a warning
# Default 120 seconds, adjust based on your workload
kernel.hung_task_timeout_secs = 120
# Hung task detection triggers panic (default: warning only, no panic)
# Set to 1 if you want hung tasks to trigger kdump capture
kernel.hung_task_panic = 1
# Hardware NMI (non-maskable interrupt) triggers panic
# For hangs caused by hardware failures, NMI is the last resort
kernel.unknown_nmi_panic = 1
# Soft lockup detection: CPU not yielding for too long triggers a warning
kernel.softlockup_panic = 1
A common pitfall: if kernel.panic is set to 0, the system won’t auto-reboot after a panic — it just hangs. On physical servers, this means a trip to the data center to press the power button. But if you set it too short (e.g., 1 second), kdump may not finish dumping before the forced reboot. I typically use 10 seconds — sufficient for most environments.
Configuration Strategies for Different Scenarios
Physical Servers
Physical servers are where kdump adds the most value. Hardware failures, driver bugs, and firmware issues can all cause kernel panics, and capturing the crash scene on physical servers is the hardest — you don’t have hypervisor-level memory snapshot capabilities.
Configuration notes:
# Physical servers typically have more memory, reserve a bit more
# GRUB parameter:
crashkernel=512M
# Configure IPMI to view console output during crash
# Even if kdump fails to save vmcore, IPMI System Event Log
# may record hardware information from before the crash
# Consider configuring serial console to output panic info to serial port
# Add to GRUB parameters:
console=tty0 console=ttyS0,115200
Virtual Machines (KVM/QEMU)
There are several things to note when configuring kdump in VM environments:
# VMs typically have less memory, reserve less
crashkernel=128M
# Ensure the VM is configured with enough reserved memory
# Check memory and currentMemory settings in libvirt XML
# VMs can leverage hypervisor memory snapshots as a supplement
# virsh dump <domain> <file> --memory-only
# This command is especially useful when the VM is completely unresponsive
Container Hosts
Configuring kdump on container hosts (Docker host / Kubernetes node) is especially important because a kernel crash on one node affects all containers running on it:
# Host configuration is the same as a regular server
crashkernel=256M
# Critical: ensure kdump's initramfs includes storage driver modules
# If using overlay2, verify relevant modules are in initramfs
# Add to /etc/dracut.conf.d/kdump.conf:
add_drivers+=" overlay br_netfilter nf_conntrack "
# Notify Kubernetes after dump completes
# Configure kdump_post script in /etc/kdump.conf:
# kdump_post /usr/local/bin/kdump-notify.sh
kdump notification script example:
#!/bin/bash
# /usr/local/bin/kdump-notify.sh
# Executed after kdump dump completes, $1 is status (0=success, 1=failure)
if [ "$1" -eq 0 ]; then
# Dump successful, send notification
logger -t kdump "vmcore captured successfully at $(date)"
# Can call WeChat Work/Feishu/DingTalk webhook here
curl -s -X POST "https://your-webhook.example.com/notify" \
-H "Content-Type: application/json" \
-d "{\"event\":\"kernel_panic\",\"host\":\"$(hostname)\",\"vmcore\":\"$(ls -t /var/crash/ | head -1)\"}"
else
# Dump failed
logger -t kdump "vmcore capture FAILED at $(date)"
fi
vmcore Storage Management
vmcore files can be several GB each. Without management, they’ll quickly fill up the disk. You need an automatic cleanup strategy:
#!/bin/bash
# /usr/local/bin/cleanup-vmcore.sh
# Keep the most recent 5 vmcores, automatically delete older ones
CRASH_DIR="/var/crash"
KEEP_COUNT=5
# Sort by modification time, delete the oldest
cd "$CRASH_DIR" || exit 1
ls -dt */ 2>/dev/null | tail -n +$((KEEP_COUNT + 1)) | while read dir; do
echo "Removing old vmcore: $dir"
rm -rf "$dir"
done
# Check disk usage, delete oldest if over 80%
USAGE=$(df "$CRASH_DIR" | awk 'NR==2{print $5}' | tr -d '%')
while [ "$USAGE" -gt 80 ]; do
OLDEST=$(ls -dt */ 2>/dev/null | tail -1)
if [ -z "$OLDEST" ]; then
break
fi
echo "Disk usage ${USAGE}%, removing: $OLDEST"
rm -rf "$OLDEST"
USAGE=$(df "$CRASH_DIR" | awk 'NR==2{print $5}' | tr -d '%')
done
Add to crontab:
# Run cleanup daily at 3 AM
0 3 * * * /usr/local/bin/cleanup-vmcore.sh >> /var/log/vmcore-cleanup.log 2>&1
kdump vs systemd-coredump
People often confuse kdump and systemd-coredump. Here’s a comparison:
| Dimension | kdump | systemd-coredump |
|---|---|---|
| Capture target | Kernel crash (kernel panic) | Userspace process crash (segfault, etc.) |
| Working level | Kernel space | Userspace |
| Dump content | Entire system memory image | Single process memory image |
| Trigger condition | Kernel panic / Oops | Process receives SIGSEGV/SIGABRT, etc. |
| Analysis tool | crash | gdb / coredumpctl |
| File size | Hundreds of MB ~ several GB | A few MB ~ hundreds of MB |
| Requires reboot? | Yes, system reboots after dump | No, only the crashed process is affected |
Simply put: use coredump for userspace crashes, kdump for kernel crashes. They don’t conflict and can be configured simultaneously.
Production Configuration Checklist
Here’s a summary of everything above into a ready-to-use configuration script:
#!/bin/bash
# kdump production configuration script
# For RHEL/CentOS 8+, adjust package names for other distros
set -euo pipefail
echo "=== 1. Install components ==="
dnf install -y kexec-tools crash
dnf install -y "kernel-debuginfo-$(uname -r)" 2>/dev/null || \
echo "Warning: kernel-debuginfo not found, crash analysis may be limited"
echo "=== 2. Configure crashkernel parameter ==="
GRUB_FILE="/etc/default/grub"
if ! grep -q "crashkernel=" "$GRUB_FILE"; then
sed -i 's/GRUB_CMDLINE_LINUX="/GRUB_CMDLINE_LINUX="crashkernel=256M /' "$GRUB_FILE"
echo "Added crashkernel=256M to GRUB"
else
echo "crashkernel already configured"
fi
echo "=== 3. Configure sysctl parameters ==="
cat > /etc/sysctl.d/99-kdump.conf << 'EOF'
kernel.panic_on_oops = 1
kernel.panic = 10
kernel.sysrq = 1
kernel.hung_task_timeout_secs = 120
kernel.hung_task_panic = 1
kernel.unknown_nmi_panic = 1
kernel.softlockup_panic = 1
EOF
sysctl --system
echo "=== 4. Configure kdump.conf ==="
cat > /etc/kdump.conf << 'EOF'
path /var/crash
core_collector makedumpfile -l --message-level 1 -d 31
default reboot
failure_action shell
EOF
echo "=== 5. Enable and start kdump ==="
systemctl enable kdump
systemctl restart kdump
echo "=== 6. Create vmcore cleanup cron ==="
cat > /usr/local/bin/cleanup-vmcore.sh << 'SCRIPT'
#!/bin/bash
CRASH_DIR="/var/crash"
KEEP_COUNT=5
cd "$CRASH_DIR" || exit 1
ls -dt */ 2>/dev/null | tail -n +$((KEEP_COUNT + 1)) | while read dir; do
rm -rf "$dir"
done
USAGE=$(df "$CRASH_DIR" | awk 'NR==2{print $5}' | tr -d '%')
while [ "$USAGE" -gt 80 ]; do
OLDEST=$(ls -dt */ 2>/dev/null | tail -1)
[ -z "$OLDEST" ] && break
rm -rf "$OLDEST"
USAGE=$(df "$CRASH_DIR" | awk 'NR==2{print $5}' | tr -d '%')
done
SCRIPT
chmod +x /usr/local/bin/cleanup-vmcore.sh
echo "0 3 * * * root /usr/local/bin/cleanup-vmcore.sh >> /var/log/vmcore-cleanup.log 2>&1" > /etc/cron.d/vmcore-cleanup
echo "=== 7. Update GRUB ==="
grub2-mkconfig -o /boot/grub2/grub.cfg
echo ""
echo "=== Configuration complete ==="
echo "Reboot the system to activate crashkernel: sudo reboot"
echo "After reboot, verify:"
echo " 1. cat /proc/cmdline | grep crashkernel"
echo " 2. systemctl status kdump"
echo " 3. cat /sys/kernel/kexec_crash_loaded (should be 1)"
echo ""
echo "Test kdump (will trigger crash and reboot):"
echo " echo c > /proc/sysrq-trigger"
Summary
kdump is the classic “you don’t need it until you really need it” tool in Linux operations. Configuration takes less than half an hour, but having a vmcore during a kernel crash can be the difference between 2 hours and 2 days of troubleshooting.
Here are my practical takeaways:
When in doubt, reserve more memory, not less. The capture kernel needs memory to boot. Insufficient reservation means dump failure. 256M is safe for most scenarios; bump to 512M for large-memory machines.
Use
-d 31for makedumpfile filtering. Uncompressed vmcore can be as large as physical memory.-d 31 -lcompresses it down to 5-15% of the original size.You must actually trigger a test. Configuring without testing is gambling.
echo c > /proc/sysrq-triggeris something I run on every new server before it goes live.kernel.panic must not be 0. Without auto-reboot, a physical server just hangs — you’ll need to visit the data center. But don’t set it too short either; 10 seconds is reasonable — enough time for kdump to finish dumping.
vmcore needs a cleanup strategy. Each vmcore is several GB. Accumulate a few and the disk fills up, turning kdump itself into a new failure source.
Remote dumping is worth configuring. When a local filesystem issue causes the crash, local dumping fails too. SSH remote dumping is your safety net.
Enable hung_task_panic and softlockup_panic. Many kernel issues aren’t panics but deadlocks. These parameters ensure kdump captures deadlock scenarios too.
One final word: kdump is not optional — it’s a standard requirement for production servers. Don’t wait until something breaks to set it up.
References & Acknowledgments
The following resources were consulted during the writing of this article. Thanks to the original authors for their contributions:
- Red Hat Enterprise Linux Kernel Crash Dump Guide — Red Hat, official kdump documentation covering working principles and configuration parameters
- Hands-on Kdump Configuration for Kernel Crash Capture on CentOS 7/8 — CSDN, practical kdump configuration and crashkernel memory reservation guide for CentOS 7/8
- Troubleshooting kdump.service Startup Failures on RHEL 8 — CSDN, diagnostic process for kdump service failures caused by incorrect crashkernel parameters
- Kernel Crash Scene Investigation Guide: Analyzing Panic Logs with kdump and crash — CSDN, hands-on guide to analyzing vmcore with the crash tool
- 3 Methods for Capturing Complete Oops Logs Compared — CSDN, comparison of Oops log capture methods and kdump configuration guide