![无法在内核崩溃时获取内核崩溃转储](https://linux22.com/image/196543/%E6%97%A0%E6%B3%95%E5%9C%A8%E5%86%85%E6%A0%B8%E5%B4%A9%E6%BA%83%E6%97%B6%E8%8E%B7%E5%8F%96%E5%86%85%E6%A0%B8%E5%B4%A9%E6%BA%83%E8%BD%AC%E5%82%A8.png)
我正在使用 kexec-tools 来获取内核崩溃时的内核崩溃转储。但是,当我使用 sysrq-trigger 触发恐慌时,系统冻结了。我必须关闭电源然后再打开电源才能恢复系统。没有自动重新启动,并且 /var/crash 中没有可用的故障转储。以下是配置和详细信息:
- Linux 发行版 - Debian Buster arm64
- Linux 内核 - 4.19.35
- kexec-tools v2.0.22(从源代码构建)
- 此处为启用 arm64 指定的所有内核配置:https://www.kernel.org/doc/Documentation/kdump/kdump.txt
主内核和崩溃内核完全相同。 (虽然使用未压缩的图像作为崩溃内核)
/proc/cmdline = crashkernel=512M nokaslr # Along with other arguments
崩溃内核空间被保留(由 dmesg 验证)
加载 crashkernel 以启动内核恐慌:
$ sudo kexec -p ./Image --append=" root=/dev/sda1 console=same_as_main_kernel earlycon=same_as_main_kernel rootwait rw 1 max_cpus=1 reset_devices
根文件系统与主内核使用的相同。
触发内核恐慌:
$ echo c | sudo tee /proc/sysrq-triggger
串行控制台因标准内核恐慌堆栈跟踪而冻结。 Kdump 特定的日志之一是:
[14645.1099571] CPU: 2 PID: 20518 Comm: tee Kdump: loaded Not tainted 4.19.35-g9e41bb234b42 #2
但是系统不会重新启动。
需要注意的一件事是,如果我想明确地启动,我可以启动到崩溃内核:
$ sudo kexec -l ./Image --append=" root=/dev/sda1 console=same_as_main_kernel earlycon=same_as_main_kernel rootwait rw 1 max_cpus=1 reset_devices
$ sudo kexec -e
这将引导到指定的内核。
我如何进一步解决/调试这个问题,在发生内核恐慌时崩溃内核似乎没有启动。
答案1
我认为这个问题可以用QEMU来解释。
在 QEMU 中运行 Ubuntu 22.04
qemu-system-x86_64 -hda ./ubuntu.qcow2 -enable-kvm -m 8G -smp 8 -serial stdio
编辑Ubuntu 22.04的grub,删除内核选项quiet
这样我们就可以得到调试消息。
以下是kexec -e
日志:
;-1f[ OK ] Started Show Plymouth Reboot with kexec Screen.
plymouth-kexec.service
[ OK ] Stopped LSB: Execute the k…c -e command to reboot system.
[ OK ] Stopped User Manager for UID 1000.
Stopping Userspace Out-Of-Memory (OOM) Killer...
Stopping User Runtime Directory /run/user/1000...
// -------------- and many similar entries -----------------------
// -------------- and many similar entries -----------------------
// many similar entries
[ OK ] Reached target System Shutdown.
[ OK ] Reached target Late Shutdown Services.
Starting Reboot via kexec...
[ 0.000000] Linux version 5.15.0-25-generic (buildd@ubuntu) (gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils fo
这是内核恐慌的日志:
martins3-Standard-PC-i440FX-PIIX-1996 login: [ 280.288704] sysrq: Trigger a crash
[ 280.290141] Kernel panic - not syncing: sysrq triggered crash
[ 280.292990] CPU: 6 PID: 2539 Comm: tee Kdump: loaded Not tainted 5.15.0-25-generic #25-Ubuntu
[ 280.296366] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.0-0-gd239552ce722-prebuilt.qemu.org 04/04
[ 280.298395] Call Trace:
[ 280.298847] <TASK>
[ 280.299243] show_stack+0x52/0x58
[ 280.299964] dump_stack_lvl+0x4a/0x5f
[ 280.300862] dump_stack+0x10/0x12
[ 280.301584] panic+0x149/0x321
[ 280.302254] sysrq_handle_crash+0x1a/0x20
[ 280.303120] __handle_sysrq.cold+0xcc/0x1a2
[ 280.304095] ? apparmor_file_permission+0x70/0x160
[ 280.305121] write_sysrq_trigger+0x28/0x40
[ 280.306007] proc_reg_write+0x5a/0x9
[ 280.306802] ? __cond_resched+0x1a/0x50
[ 280.307604] vfs_write+0xc3/0x260
[ 280.308316] ksys_write+0x67/0xe0
[ 280.309014] __x64_sys_write+0x19/0x20
[ 280.309798] do_syscall_64+0x5c/0xc0
[ 280.311102] ? exit_to_user_mode_prepare+0x37/0xb0
[ 280.312097] ? syscall_exit_to_user_mode+0x27/0x50
[ 280.313089] ? __x64_sys_write+0x19/0x20
[ 280.313905] ? do_syscall_64+0x69/0xc0
[ 280.314684] ? irqentry_exit_to_user_mode+0x9/0x20
[ 280.315705] ? irqentry_exit+0x19/0x30
[ 280.316524] ? exc_page_fault+0x89/0x160
[ 280.317322] ? asm_exc_page_fault+0x8/0x30
[ 280.318153] entry_SYSCALL_64_after_hwframe+0x44/0xae
[ 280.319162] RIP: 0033:0x7f39a4c57a37
[ 280.319864] Code: 10 00 f7 d8 64 89 02 48 c7 c0 ff ff ff ff eb b7 0f 1f 00 f3 0f 1e fa 64 8b 04 25 18 00 00 00 85 c0 75 14
[ 280.323539] RSP: 002b:00007ffd893cb268 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
[ 280.325084] RAX: ffffffffffffffda RBX: 0000000000000002 RCX: 00007f39a4c57a37
[ 0.000000] Linux version 5.15.0-25-generic (buildd@ubuntu) (gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, GNU ld (GNU Binutils f)
// ---------------- kernel boot messages -----------------------
// ---------------- kernel boot messages -----------------------
[ 0.610479] tun: Universal TUN/TAP device driver, 1.6
[ 0.611162] PPP generic driver version 2.4.2
[ 0.611738] VFIO - User Level meta-driver version: 0.3
[ 0.613621] kthreadd invoked oom-killer: gfp_mask=0xcc0(GFP_KERNEL), order=0, oom_score_adj=0
[ 0.614698] CPU: 0 PID: 93 Comm: kthreadd Not tainted 5.15.0-25-generic #25-Ubuntu
所以区别很明显,kexec -e
是一个包装重启系统调用。kexec -e
和内核恐慌只是有相似之处,但是不一样代码路径,因为内核在恐慌模式下无法保证太多。由于内存不足,内核恐慌无法启动,因此机器死机。
那么如何解决这个问题呢?编辑您的/boot/grub/grub.conf
,增加内核参数crashkernel
并重新启动。