本文在ubuntu20.04上安装kdump相关服务及调试内核所需的vmlinux文件,然后启用kdump服务。
1、安装
zyg@zyg:~$ sudo apt install linux-crashdump
在弹窗菜单中选择yes安装。
2、查看kdump配置
zyg@zyg:~$ kdump-config show
DUMP_MODE: kdump
USE_KDUMP: 1
KDUMP_SYSCTL: kernel.panic_on_oops=1
KDUMP_COREDIR: /var/crash
crashkernel addr: 0x
/var/lib/kdump/vmlinuz: symbolic link to /boot/vmlinuz-5.4.0-60-generic
kdump initrd:
/var/lib/kdump/initrd.img: symbolic link to /var/lib/kdump/initrd.img-5.4.0-60-generic
current state: ready to kdump
kexec command:
/sbin/kexec -p --command-line="BOOT_IMAGE=/vmlinuz-5.4.0-60-generic root=/dev/mapper/ubuntu--vg-ubuntu--lv ro maybe-ubiquity reset_devices systemd.unit=kdump-tools-dump.service nr_cpus=1 irqpoll nousb ata_piix.prefer_ms_hyperv=0" --initrd=/var/lib/kdump/initrd.img /var/lib/kdump/vmlinuz
可以看到USE_KDUMP=1,生成的vmcore文件在/var/crash下
kdump服务相关配置文件为/etc/default/kdump-tools,可以编辑该文件:
# kdump-tools configuration
# ---------------------------------------------------------------------------
# USE_KDUMP - controls kdump will be configured
# 0 - kdump kernel will not be loaded
# 1 - kdump kernel will be loaded and kdump is configured
# KDUMP_SYSCTL - controls when a panic occurs, using the sysctl
# interface. The contents of this variable should be the
# "variable=value ..." portion of the 'sysctl -w ' command.
# If not set, the default value "kernel.panic_on_oops=1" will
# be used. Disable this feature by setting KDUMP_SYSCTL=" "
# Example - also panic on oom:
# KDUMP_SYSCTL="kernel.panic_on_oops=1 vm.panic_on_oom=1"
#
USE_KDUMP=1
#KDUMP_SYSCTL="kernel.panic_on_oops=1"
# ---------------------------------------------------------------------------
# Kdump Kernel:
# KDUMP_KERNEL - A full pathname to a kdump kernel.
# KDUMP_INITRD - A full pathname to the kdump initrd (if used).
# If these are not set, kdump-config will try to use the current kernel
# and initrd if it is relocatable. Otherwise, you will need to specify
# these manually.
KDUMP_KERNEL=/var/lib/kdump/vmlinuz
KDUMP_INITRD=/var/lib/kdump/initrd.img
# ---------------------------------------------------------------------------
# vmcore Handling:
# KDUMP_COREDIR - local path to save the vmcore to.
# KDUMP_FAIL_CMD - This variable can be used to cause a reboot or
# start a shell if saving the vmcore fails. If not set, "reboot -f"
# is the default.
# Example - start a shell if the vmcore copy fails:
# KDUMP_FAIL_CMD="echo 'makedumpfile FAILED.'; /bin/bash; reboot -f"
# KDUMP_DUMP_DMESG - This variable controls if the dmesg buffer is dumped.
# If unset or set to 1, the dmesg buffer is dumped. If set to 0, the dmesg
# buffer is not dumped.
KDUMP_COREDIR="/var/crash"
#KDUMP_FAIL_CMD="reboot -f"
#KDUMP_DUMP_DMESG=
# KDUMP_NUM_DUMPS - This variable controls how many dump files are kept on
# the machine to prevent running out of disk space. If set to 0 or unset,
# the variable is ignored and no dump files are automatically purged.
KDUMP_COREDIR="/var/crash"
#KDUMP_FAIL_CMD="reboot -f"
#KDUMP_DUMP_DMESG=
#KDUMP_NUM_DUMPS=
# ---------------------------------------------------------------------------
"/etc/default/kdump-tools" [readonly] 104L, 4602C
此时可以在/boot/grub下grub.config中的系统启动参数看到:
3、reboot
4、查看内核启动命令
zyg@zyg:~$ cat /proc/cmdline
BOOT_IMAGE=/vmlinuz-5.4.0-60-generic root=/dev/mapper/ubuntu--vg-ubuntu--lv ro maybe-ubiquity crashkernel=512M-:192M
5、测试生成vmcore,手动触发系统崩溃
zyg@zyg:~$ su - root
Password:
root@zyg:~# echo c > /proc/sysrq-trigger
6、下载vmlinux
可以从这里Index of /pool/main/l/linux下载对应版本的,下载完成后dpkg -i来安装。
安装完成后,可以在/usr/lib/debug/目录下找到,vmlinux位置在/usr/lib/debug/boot/vmlinux-4.15.0-112-generic。