Fork me on GitHub
Fiwix symbol
Welcome to the Fiwix project
Your small UNIX-like kernel

News

19-Apr-2023

Kexec is a mechanism that let's you switch into a different kernel without rebooting your machine. The new kernel can be another Fiwix kernel or any other ELF binary kernel. It currently only supports the Multiboot 1 Specification to be passed to the new kernel, but it's open to include support for other boot methods.

It differs from the Linux kexec implementation because it doesn't need a system call nor specific user-space tools, and your current system will completely shutdown before jumping to the new kernel.

There are three new kernel command line parameters:

  • kexec_proto=, this is the boot method of the new kernel. Currently the only supported value is multiboot1.
  • kexec_size=, size in KB of the memory space to be reserved to allocate the new kernel.
  • kexec_cmdline=, command line to be passed to the new kernel (enclosed in double quotes).

Your system needs to know at boot-time that it might switch to a different kernel. That is, you need to pass those special parameters in your kernel command line during the system boot.

This is an example of a kernel command line:

/boot/fiwix ro root=/dev/hda2 kexec_proto=multiboot1 kexec_size=500 kexec_cmdline="fiwix ro root=/dev/hda2"

Once you have specified the kexec parameters, you'll see a new RAMdisk drive appearing in the boot messages. Such RAMdisk drive will have the same size as specified in the kexec_size= parameter:

A new RAMdisk drive appears during the boot

The RAMdisk drives play an important role here. You already know that they can be used to allocate an initrd image specified during the boot, or to allocate one or more all-purpose RAMdisk drives. Now they are also used by kexec to allocate the new kernel.

Kexec uses always the first unused RAMdisk drive. You'll know which one is the first unused depending if you specified an initrd image, or if you specified to have all-purpose RAMdisk drives at boot-time.

Once you know what RAMdisk drive will be used to allocate the new kernel, you can proceed to copy the ELF binary kernel into such RAMdisk drive by using standard user-space tools like cp or dd.

Finally, when you are ready, just do a normal shutdown to switch automatically to the new kernel:

# cp fiwix /dev/ram0
# shutdown -h 0

The following is a video that shows a complete kernel switch using kexec. In this video you can see the differences in the timestamp between the first and second kernel:


First   Previous   Next