crashkernel

最後更新: 2017-06-01

介紹

 


Package & Requirements

 

It relies on kexec, which can be used to boot a Linux kernel from the context of another kernel,

bypass BIOS, and preserve the contents of the first kernel's memory that would otherwise be lost.

The kdump service is installed and activated by default on new Red Hat Enterprise Linux 7

# Package

yum install kexec-tools

# Memory Requirements

on the x86_64 architecture, the amount of reserved memory will be 160 MB + 2 bits for every 4 KB of RAM.
 


reserved memory

 

Memory reserved for the kdump kernel is always reserved during system boot,

which means that the amount of memory is specified in the system's boot loader configuration.

/etc/default/grub

GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet"
grub2-mkconfig -o /boot/grub2/grub.cfg

# Amount of memory you want to reserve
# "crashkernel=XM" is a kernel parameter for kdump

crashkernel=128M

# The kernel will automatically reserve an appropriate amount of memory for the kdump kernel

crashkernel=auto

# The example above means that kdump will reserve 128 MB of memory starting at 16 MB (physical address 0x01000000).
# If the offset parameter is set to 0 or omitted entirely, kdump will offset the reserved memory automatically.

crashkernel=128M@16M

# 512M ~ 2G => reserve 64M
# > 2G      => reserve 128M

crashkernel=512M-2G:64M,2G-:128M

 


kernel crash dump

 

When a kernel crash is captured, the core dump can be either stored as a file in a local file system,

written directly to a device, or sent over a network using the NFS or SSH protocol.

/etc/kdump.conf

/var/crash/

"vmcore" dump file

kdump allows you to specify an external application (a core collector) to compress the data

core collector: makedumpfile

core_collector makedumpfile -l --message-level 1 -d 31

# -c / -l           # To enable the dump file compression ( -c: zlib / -l: lzo)
# -d                # To remove certain pages from the dump

1     Zero pages
2     Cache pages
4     Cache private
8     User pages
16     Free pages

 


kdump service

 

systemctl is-active kdump

active

systemctl status kdump

● kdump.service - Crash recovery kernel arming
   Loaded: loaded (/usr/lib/systemd/system/kdump.service; enabled; vendor preset: enabled)
   Active: active (exited) since Wed 2017-04-26 14:46:25 HKT; 1 weeks 5 days ago
  Process: 831 ExecStart=/usr/bin/kdumpctl start (code=exited, status=0/SUCCESS)
 Main PID: 831 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/kdump.service

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

 


Testing kdump (force the Linux kernel to crash)

 

# enable sysrq-trigger

echo 1 > /proc/sys/kernel/sysrq

# c => crash

echo c > /proc/sysrq-trigger