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”:

  1. fedorapkg/kexec-tools/kdumpctl: start->start_dump->load_kdump
    • load the crash kernel image into memory (user mode, script)
  2. 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
  3. 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

  1. linux/kernel/panic.c: panic
    • kernel panic.
  2. linux/kernel/reboot.c: sys_reboot(SYSCALL_DEFINE4)
    • root reboot.
  3. linux/kernel/kexec_core.c: __crash_kexec
    • called when panic.
  4. linux/kernel/kexec_core.c: kernel_kexec
    • called when rebooting with flag LINUX_REBOOT_CMD_KEXEC.
  5. linux/arch/x86/kernel/machine_kexec_32.c: machine_kexec
    • arch-specified code, called by kernel_kexec or __crash_kexec.
  6. 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

  1. linux/fs/proc/vmcore.c: vmcore_init
    • prepare /proc/vmcore when fs init.
  2. fedorapkg/kexec-tools/kdumpctl: main->save_core
    • using makedumpfile to save vmcore, then reboot to the origin kernel.

References: