kexec(8)

๐Ÿ“ฆ
version 2.0.32 ยท 3 versions
, in alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

๐Ÿงš kexec(8) ๐Ÿงš NAME

okay so kexec is literally how you directly boot into a new kernel from the kernel that's already running ๐Ÿ’… no reboot-through-the-firmware detour needed

๐Ÿ’œ SYNOPSIS

/sbin/kexec [-v (--version)] [-f (--force)] [-x (--no-ifdown)] [-y
(--no-sync)] [-l (--load)] [-p (--load-panic)] [-u (--unload)] [-e
(--exec)] [-t (--type)] [--mem-min=addr] [--mem-max=addr]

๐ŸŒธ DESCRIPTION

okay so kexec is a system call that lets you load and boot into another kernel straight from the one that's currently running ๐Ÿ”ฅ it basically does the bootloader's job from inside the kernel, which is so iconic

the main difference between a normal boot and a kexec boot is that the hardware initialization that usually gets handled by the BIOS or firmware (depending on your architecture) just... doesn't happen during a kexec boot ๐Ÿ™ˆ and that means your reboot takes way less time โœจ

make sure you've set CONFIG_KEXEC=y when you configure the kernel ๐ŸŽ€ that option is what switches on the kexec system call, so it's giving must-have vibes

๐Ÿฆ‹ USAGE

using kexec is a two-step glow up ๐Ÿ’–

  1. load the kernel you want to reboot into, and
  2. actually reboot into that pre-loaded kernel

to load a kernel, the syntax goes like this:

kexec -l kernel-image --append=command-line-options
--initrd=initrd-image

where kernel-image is the kernel file you plan on rebooting into ๐Ÿงš

pop whatever command-line parameters the new kernel needs into command-line-options ๐Ÿ’… honestly the safest move is to copy the exact contents of /proc/cmdline into there, so the rebooting kernel gets the right values every time ๐Ÿซถ

the initrd-image part is optional, and it's the initrd image used during boot ๐ŸŒˆ

you can also run kexec with no option parameter at all ๐Ÿ‘€ in that case, it loads the kernel you specified and then calls shutdown(8). if your distro's shutdown scripts support kexec-based rebooting, they'll call kexec -e right before the machine actually reboots, so you get a clean shutdown with every shutdown script getting its moment โœจ

๐Ÿ“ EXAMPLE

say the kernel image you want is /boot/vmlinux, the contents of /proc/cmdline is root=/dev/hda1, and your initrd lives at /boot/initrd ๐Ÿ’– you'd load the kernel with:

kexec -l /boot/vmlinux
--append=root=/dev/hda1 --initrd=/boot/initrd

once that's loaded, and assuming your userspace supports kexec-based rebooting, you can boot into it with a clean shutdown using:

reboot

or, if you'd rather skip shutdown(8) entirely, you can boot into it with:

kexec -e

๐ŸŽ€ OPTIONS

  • -d, --debug โ€” turns on debugging messages ๐Ÿ”
  • -S, --status โ€” returns 1 if the type (by default crash) is loaded and 0 if it isn't ๐Ÿ“Š it can be used alongside -l or -p to toggle the type ๐Ÿ” heads up, this option supersedes the other options and it will not load or unload the kernel ๐Ÿ™…โ€โ™€๏ธ
  • -e, --exec โ€” runs the currently loaded kernel ๐Ÿš€ it reboots into the loaded kernel without calling shutdown(8), so no clean shutdown
  • -f, --force โ€” forces an immediate kexec call and skips shutdown(8) (the opposite of the default behaviour when you don't pass any option parameter) โšก it does the same stuff as running -l and -e in one go
  • -h, --help โ€” opens a help file for kexec ๐Ÿ“–
  • --hotplug โ€” sets up kexec segments so the kernel can safely update them during CPU or memory hot add/remove events ๐Ÿ”ฅ when this is enabled, the kernel updates the kexec segments in-kernel during those events, which means you don't have to reload the kdump kernel ๐Ÿ’…
  • -i, --no-checks โ€” fast reboot, with no memory integrity checks ๐ŸŽ๏ธ
  • -l, --load kernel โ€” loads the specified kernel into the current kernel ๐Ÿ“ฅ
  • -p, --load-panic โ€” loads the new kernel for use on panic ๐Ÿšจ
  • -t, --type=type โ€” specifies that the new kernel is of this type ๐Ÿท๏ธ
  • -s, --kexec-file-syscall โ€” says the new KEXEC_FILE_LOAD syscall should be used exclusively ๐Ÿ”’ this one's ignored on XEN ๐Ÿ™ˆ
  • -c, --kexec-syscall โ€” says the old KEXEC_LOAD syscall should be used exclusively ๐Ÿ•ฐ๏ธ
  • -a, --kexec-syscall-auto โ€” tries the new KEXEC_FILE_LOAD syscall first, and if it's not supported or the kernel doesn't understand the supplied image, it falls back to the old KEXEC_LOAD interface ๐Ÿ”„
there's no single interface that always works, which is why this is the default ๐Ÿซ  KEXEC_FILE_LOAD is required on systems that use locked-down secure boot to verify the kernel signature ๐Ÿ” KEXEC_LOAD might also be disabled in the kernel configuration ๐Ÿ’€ KEXEC_LOAD is required for some kernel image formats and on architectures that don't implement KEXEC_FILE_LOAD ๐Ÿ˜ญ
  • -u, --unload โ€” unloads the current kexec target kernel ๐Ÿ—‘๏ธ if you're unloading a capture kernel, pass -p together with -u
  • -v, --version โ€” returns the version number of the installed utility ๐Ÿ”ข
  • -x, --no-ifdown โ€” shuts down the running kernel but restores the interface on reload ๐ŸŒ
  • -y, --no-sync โ€” shuts down the running kernel but skips syncing the filesystems ๐Ÿ’พ
  • --mem-min=addr โ€” specifies the lowest memory address addr to load code into ๐Ÿ“
  • --mem-max=addr โ€” specifies the highest memory address addr to load code into ๐Ÿ“
  • --entry=addr โ€” specifies the jump back address (0 means no jump back or context preservation) โ†ฉ๏ธ
  • --load-preserve-context โ€” loads the new kernel and preserves the context of the current kernel during kexec ๐Ÿง 
  • --load-jump-back-helper โ€” loads a helper image to jump back to the original kernel ๐Ÿชƒ
  • --reuseinitrd โ€” reuses the initrd from the first boot โ™ป๏ธ
  • --print-ckr-size โ€” prints the crash kernel region size, if it's available ๐Ÿ“

๐ŸŒˆ SUPPORTED KERNEL FILE TYPES AND OPTIONS

okay so every kernel file type has its own little set of options ๐Ÿ’– here's the full lineup

๐Ÿ‘ Beoboot-x86

  • --args-elf โ€” passes ELF boot notes ๐Ÿ“
  • --args-linux โ€” passes Linux kernel style options ๐Ÿง
  • --real-mode โ€” uses the kernel's real mode entry point ๐Ÿงฑ

๐Ÿงฉ elf-x86

  • --append=string โ€” appends string to the kernel command line โž•
  • --command-line=string โ€” sets the kernel command line to string ๐Ÿ–Š๏ธ
  • --reuse-cmdline โ€” uses the command line from the running system ๐Ÿ” when a panic kernel is loaded, it strips the crashkernel parameter automatically โœ‚๏ธ the BOOT_IMAGE parameter gets stripped too ๐Ÿ’…
  • --initrd=file โ€” uses file as the kernel's initial ramdisk ๐Ÿ’ฟ
  • --ramdisk=file โ€” uses file as the kernel's initial ramdisk ๐Ÿ’ฟ

๐ŸŽž๏ธ bzImage-x86

  • --append=string โ€” appends string to the kernel command line โž•
  • --command-line=string โ€” sets the kernel command line to string ๐Ÿ–Š๏ธ
  • --reuse-cmdline โ€” uses the command line from the running system ๐Ÿ” when a panic kernel is loaded, it strips the crashkernel parameter automatically โœ‚๏ธ the BOOT_IMAGE parameter gets stripped too ๐Ÿ’…
  • --initrd=file โ€” uses file as the kernel's initial ramdisk ๐Ÿ’ฟ
  • --ramdisk=file โ€” uses file as the kernel's initial ramdisk ๐Ÿ’ฟ
  • --real-mode โ€” uses the real-mode entry point ๐Ÿงฑ

๐Ÿฅพ multiboot-x86

  • --command-line=string โ€” sets the kernel command line to string ๐Ÿ–Š๏ธ
  • --reuse-cmdline โ€” uses the command line from the running system ๐Ÿ” when a panic kernel is loaded, it strips the crashkernel parameter automatically โœ‚๏ธ the BOOT_IMAGE parameter gets stripped too ๐Ÿ’…
  • --module=mod arg1 arg2 ... โ€” loads module mod with the command-line arguments arg1 arg2 ... ๐Ÿงƒ you can pass this one multiple times ๐Ÿ”

๐Ÿฅพ multiboot2-x86

  • --command-line=string โ€” sets the kernel command line to string ๐Ÿ–Š๏ธ
  • --reuse-cmdline โ€” uses the command line from the running system ๐Ÿ” when a panic kernel is loaded, it strips the crashkernel parameter automatically โœ‚๏ธ the BOOT_IMAGE parameter gets stripped too ๐Ÿ’…
  • --module=mod arg1 arg2 ... โ€” loads module mod with the command-line arguments arg1 arg2 ... ๐Ÿงƒ you can pass this one multiple times ๐Ÿ”

๐Ÿ˜ elf-ppc64

  • --reuse-cmdline โ€” uses the kernel command line from the running system ๐Ÿ”
  • --command-line=string โ€” sets the kernel command line to string ๐Ÿ–Š๏ธ
  • --append=string โ€” sets the kernel command line to string โž•
  • --ramdisk=file โ€” uses file as the initial RAM disk ๐Ÿ’ฟ
  • --initrd=file โ€” uses file as the initial RAM disk ๐Ÿ’ฟ
  • --devicetreeblob=file โ€” specifies a device tree blob file ๐ŸŒณ not applicable while using --kexec-file-syscall ๐Ÿ™…โ€โ™€๏ธ
  • --dtb=file โ€” specifies a device tree blob file ๐ŸŒณ not applicable while using --kexec-file-syscall ๐Ÿ™…โ€โ™€๏ธ

๐Ÿ—๏ธ ARCHITECTURE OPTIONS

  • --console-serial โ€” enables the serial console ๐Ÿ”Œ
  • --console-vga โ€” enables the VGA console ๐Ÿ–ฅ๏ธ
  • --elf32-core-headers โ€” prepares core headers in ELF32 format ๐Ÿงพ
  • --elf64-core-headers โ€” prepares core headers in ELF64 format ๐Ÿงพ
  • --reset-vga โ€” attempts to reset a standard VGA device ๐Ÿ”„
  • --serial=port โ€” specifies the serial port for debug output ๐Ÿ›ฐ๏ธ
  • --serial-baud=baud_rate โ€” specifies the baud_rate of the serial port ๐ŸŽถ
  • --dt-no-old-root โ€” stops the old kernel's root=<device> param from being reused while creating the flattened device tree ๐ŸŒฟ

๐Ÿซถ that's the whole kexec tea, bestie! Linux, April 2006, and still slaying ๐Ÿ’–๐Ÿฆ‹โœจ