kexec(8)
๐ง 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 ๐
- load the kernel you want to reboot into, and
- 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โ returns1if the type (by defaultcrash) is loaded and0if it isn't ๐ it can be used alongside-lor-pto 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 callingshutdown(8), so no clean shutdown-f,--forceโ forces an immediate kexec call and skipsshutdown(8)(the opposite of the default behaviour when you don't pass any option parameter) โก it does the same stuff as running-land-ein 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,--loadkernel โ 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 newKEXEC_FILE_LOADsyscall should be used exclusively ๐ this one's ignored on XEN ๐-c,--kexec-syscallโ says the oldKEXEC_LOADsyscall should be used exclusively ๐ฐ๏ธ-a,--kexec-syscall-autoโ tries the newKEXEC_FILE_LOADsyscall first, and if it's not supported or the kernel doesn't understand the supplied image, it falls back to the oldKEXEC_LOADinterface ๐
there's no single interface that always works, which is why this is the default ๐ซKEXEC_FILE_LOADis required on systems that use locked-down secure boot to verify the kernel signature ๐KEXEC_LOADmight also be disabled in the kernel configuration ๐KEXEC_LOADis required for some kernel image formats and on architectures that don't implementKEXEC_FILE_LOAD๐ญ
-u,--unloadโ unloads the current kexec target kernel ๐๏ธ if you're unloading a capture kernel, pass-ptogether 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 (0means 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 thecrashkernelparameter automatically โ๏ธ theBOOT_IMAGEparameter 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 thecrashkernelparameter automatically โ๏ธ theBOOT_IMAGEparameter 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 thecrashkernelparameter automatically โ๏ธ theBOOT_IMAGEparameter gets stripped too ๐--module=mod arg1 arg2 ...โ loads module mod with the command-line argumentsarg1 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 thecrashkernelparameter automatically โ๏ธ theBOOT_IMAGEparameter gets stripped too ๐--module=mod arg1 arg2 ...โ loads module mod with the command-line argumentsarg1 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'sroot=<device>param from being reused while creating the flattened device tree ๐ฟ
๐ซถ that's the whole kexec tea, bestie! Linux, April 2006, and still slaying ๐๐ฆโจ
๐ฆ where this page comes from
- alpine 3.24: kexec-tools-doc 2.0.32-r2 ยท GPL-2.0-only
- arch rolling: kexec-tools 2.0.32-1 ยท GPL-2.0-or-later
- centos-stream 10: kexec-tools 2.0.32-3.el10 ยท GPL-2.0-only
- centos-stream 9: kexec-tools 2.0.29-18.el9 ยท GPLv2
- debian trixie: kexec-tools 1:2.0.29-2+b2 ยท GPL-2.0-only
- fedora 43: kexec-tools 2.0.31-3.fc43 ยท GPL-2.0-only
- fedora 43: kexec-tools 2.0.32-1.fc43 ยท GPL-2.0-only
- fedora 44: kexec-tools 2.0.32-3.fc44 ยท GPL-2.0-only
- nixos 26.05: kexec-tools 2.0.32
- nixpkgs unstable: kexec-tools 2.0.32
- opensuse-leap 16.0: kexec-tools 2.0.30-160000.3.2 ยท GPL-2.0-or-later
- opensuse-leap 16.0: kexec-tools 2.0.30-160000.3.2 ยท GPL-2.0-or-later
- opensuse-leap 16.0: kexec-tools 2.0.30-160000.3.2 ยท GPL-2.0-or-later
- opensuse-leap 16.0: kexec-tools 2.0.30-160000.3.2 ยท GPL-2.0-or-later
- ubuntu questing: kexec-tools 1:2.0.31-1ubuntu2 ยท GPL-2.0-only
- ubuntu resolute: kexec-tools 1:2.0.32-3ubuntu1 ยท GPL-2.0-only
- ubuntu stonking: kexec-tools 1:2.0.32-3ubuntu2 ยท GPL-2.0-only
- ๐ girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms