内核转储文件--内核崩溃

Ubuntu

安装crash工具

1
apt-get install linux-crashdump

检查kdump配置

1
2
3
4
5
6
7
8
9
10
11
12
13
kdump-config show

DUMP_MODE: kdump
USE_KDUMP: 1
KDUMP_COREDIR: /var/crash
crashkernel addr: 0x73000000
/var/lib/kdump/vmlinuz: symbolic link to /boot/vmlinuz-5.15.0-89-generic
kdump initrd:
/var/lib/kdump/initrd.img: symbolic link to /var/lib/kdump/initrd.img-5.15.0-89-generic
current state: ready to kdump

kexec command:
/sbin/kexec -p --command-line="BOOT_IMAGE=/boot/vmlinuz-5.15.0-89-generic root=UUID=92414257-97c5-46a0-9154-66c415ee7358 ro net.ifnames=0 consoleblank=600 console=tty0 console=ttyS0,115200n8 noibrs reset_devices systemd.unit=kdump-tools-dump.service nr_cpus=1 irqpoll nousb" --initrd=/var/lib/kdump/initrd.img /var/lib/kdump/vmlinuz

USE_KDUMP=1 代表kdump打开

KDUMP_COREDIR 代表生成的core文件在/var/crash下面

1
2
3
4
-> # dmesg | grep -i crash
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-5.15.0-89-generic root=UUID=92414257-97c5-46a0-9154-66c415ee7358 ro net.ifnames=0 consoleblank=600 console=tty0 console=ttyS0,115200n8 noibrs crashkernel=512M-:192M
[ 0.005698] Reserving 192MB of memory at 1840MB for crashkernel (System RAM: 2047MB)
[ 0.013125] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-5.15.0-89-generic root=UUID=92414257-97c5-46a0-9154-66c415ee7358 ro net.ifnames=0 consoleblank=600 console=tty0 console=ttyS0,115200n8 noibrs crashkernel=512M-:192M

dmesg 显示了crashkernel保留了192M内存,kexec命令。

手动触发sysrq

1
2
cat /proc/sys/kernel/sysrq
echo c > /proc/sysrq-trigger
  1. sysrq值不为0代表工作正常
  2. echo写主动触发kdump

CentOS

安装crash工具

1
2
yum install kexec-tools
yum install crash

安装内核调试信息包

1
2
yum install kernel-debuginfo-$(uname -r)
yum install kernel-debuginfo-common-$(uname -r)

判断服务正常开启

1
systemctl status kdump

主动触发分析

这一步跟Ubuntu的一致

分析调试

1
crash /usr/lib/debug/lib/modules/$(uname -r)/vmlinux /var/crash/XX/vmcore