kdump/kexec Workflow in Fedora x86
This post describes the detailed code control flow of kdump/kexec utilities in Fedora x86.
kdump is the utility for collecting kernel core dump when the kernel crashes. It makes use of kexec
system call provided by Linux kernel to load a second kernel, in which dumping core process happens.
kdump’s workflow in Fedora can be divided roughly into 4 phases:
- Loading the emergency kernel into memory
- Logic after kernel crashes and before emergency kernel boots
- Booting emergency kernel
- Dumping core
Loading the emergency kernel into memory
After trigerring “systemctl start kdump.service”:
fedorapkg/kexec-tools/kdumpctl: start->start_dump->load_kdump
- load the crash kernel image into memory (user mode, script)
upstream/kexec-tools/kexec/kexec.c: kexec_load
- load the crash kernel image into memory (user mode, C)
- use syscall to perform
sys_kexec_load
linux/kernel/kexec.c: sys_kexec_load(SYSCALL_DEFINE4)
- load the crash kernel image into memory (kernel mode, C)
- what about the comments before
sys_kexec_load
? I think they’re outdated.
Logic after kernel crash and before emergency kernel boot
linux/kernel/panic.c: panic
- kernel panic.
linux/kernel/reboot.c: sys_reboot(SYSCALL_DEFINE4)
- root reboot.
linux/kernel/kexec_core.c: __crash_kexec
- called when panic.
linux/kernel/kexec_core.c: kernel_kexec
- called when rebooting with flag
LINUX_REBOOT_CMD_KEXEC
.
- called when rebooting with flag
- linux/arch/x86/kernel/machine_kexec_32.c: machine_kexec
- arch-specified code, called by
kernel_kexec
or__crash_kexec
.
- arch-specified code, called by
- linux/arch/x86/kernel/relocate_kernel_32.S: relocate_kernel
- put the kernel image in place to boot. the last step before emergency kernel boots.
Booting emergency kernel
Boot into dracut-generated initramfs (specified by grub parameter). This image is generated by kdumpctl
utility during starting kdump’s service.
After booting into capture kernel
linux/fs/proc/vmcore.c: vmcore_init
- prepare /proc/vmcore when fs init.
fedorapkg/kexec-tools/kdumpctl: main->save_core
- using makedumpfile to save vmcore, then reboot to the origin kernel.