From Gentoo Wiki
Jump to: navigation, search

Kexec (kernel execute) is a system call that enables the kernel to load and boot into another kernel from the currently running kernel. This is useful for kernel developers or other people who need to reboot very quickly without waiting for the whole BIOS boot process to finish.

Note that kexec may not work correctly due to devices not fully re-initializing when using this method, however that's rare occasion



KERNEL Configuring the kernel for Kexec
     Processor type and features --->
          [*] kexec system call
          [*] kexec file based system call

Or use official Gentoo kernels via the Distribution Kernel project.


After installing old (which are loaded already) and new (which will be loaded) kernel, next install sys-apps/kexec-tools userspace tools:

root #emerge --ask --verbose sys-apps/kexec-tools

kexec can now be called either with a manual (kexec -l) or automatic (with kexec openrc/systemd service) methods.


Manual kernel reloading

kexec -e or kexec --exec may corrupt the system because it does not stop services and does not unmount partitions properly. Instead use the reboot -k to gracefully reboot with kexec loading.

Kexec utility documentation:

user $man kexec

Quick steps

Stage 1: load the new kernel image:

root #kexec -l path_to_kernel_image --initrd=path_to_initrd_image --append=command-line-options

Stage 2: reboot to new kernel:

root #reboot -k

Automatically kernel reloading with openrc

Edit openrc config with the following options:

Permit LOAD_DURING_SHUTDOWN="yes" to load the new kernel when system rebooting instead of loading old kernel when system started when planning to use it with the autolaunch service.
FILE /etc/conf.d/kexec
# Load kexec kernel image into memory during shutdown instead of bootup
# (default: yes)

# Additional arguments passed to kexec (8)

# Kernel image partition. Mounted automatically if not.
# (default: /boot)

# Root partition (should be autodetected)

# Kernel image pathname, relative from BOOTPART.
# If it's one of 
# {kernel-genkernel,bzImage,vmlinuz,kernel}-<currently running kernel version>,
# or bzImage, vmlinuz (without suffix),
# then it's automaticaly detected.
# Setting it to "-" will disable kexec.

# Initrd
# Same automatic detection restriction as for KNAME apply.
# initramfs-genkernel-<currently running kernel version>,
# initrd{,.img}-<currently running kernel version>{,.img}
# will be detected.

# Kernel parameters (should be autodetected)
#KPARAM="initrd=intel-uc.img rootfstype=f2fs init=/sbin/openrc-init"

# Do not try to mount /boot

Then start the service:

root #rc-service kexec start

And reboot to new kernel:

root #reboot -k