In today’s tutorial, we’ll see how to use Kernel Boot in Nitrux.

Difficulty: ★☆☆☆☆

📜 Table of Contents

  1. Introducing Kernel Boot
    1. What is Kernel Boot
    2. What Kernel Boot is not
  2. Using Kernel Boot in Nitrux
    1. Using kernels from Distrobox containers
  3. Known Issues

Introducing Kernel Boot

The Kernel Boot (kboot) utility uses kexec and is designed for Nitrux OS to provide a solution to make it friendlier to load other Linux kernels on the fly.

    • ⚠️ Important: Kernel Boot (kboot) is intended to work exclusively in Nitrux OS, and using this utility in other distributions will break them or not work at all. Please do not open issues regarding this use case; they will be closed.

kboot is designed for a particular purpose, making it friendlier to allow for a faster transition from the currently running kernel to a new kernel, avoiding the time-consuming hardware initialization and bootloader stages. It performs the following steps:

    1. Reads the settings in the specified configuration file.
    2. Then, it uses kexec to load the selected kernel using the parameters from the configuration file.

Introducing Kernel Boot.

What is Kernel Boot

What Kernel Boot is not

  • A bootloader.
    • kboot uses a mechanism for loading and executing a new kernel within an already running system, bypassing the complete boot process. In comparison, a bootloader such as GRUB is a full-featured bootloader responsible for the initial bootstrapping of the operating system. GRUB provides a menu to select the desired operating system or kernel.
  • An init or service manager.
    • kboot does not function as an init or replace an init. The init process is responsible for initializing the system, starting essential system services and daemons, and bringing up the user space environment. kboot does not perform these functions; kboot only loads a new kernel image.
  • An initrd or initram generator.
    • kboot does not replace or modify the existing initramfs generator. The initram generator tools like dracut or initramfs-tools are responsible for identifying and including the necessary modules, drivers, and scripts to correctly set up the root filesystem and handle any unique configurations (e.g., encrypted root, LVM, RAID, etc.). kboot loads a kernel and an existing initram image and transfers control to it.
  • A container, virtual machine, Live USB creator, Linux distribution, Live/Recovery/Rescue/Emergency environment, system installer, desktop environment, firmware, or “proprietary software.”
    • Note: We don’t know why anyone would think that, but one can never know, so let’s clarify that.

Using Kernel Boot in Nitrux

Kernel Boot is designed to be highly autonomous.

Commands:

Switch:

sudo kboot switch <config_file>
  • Switches the kernel using the settings in the specified configuration file, e.g., /etc/kboot.d/debian or /etc/kboot.d/liquorix.
  • ⚠️ Important: This process involves stopping the currently running kernel and starting the new kernel from scratch. All running processes, including the graphical session, are terminated during this transition.
    • ⚠️ Important: For users of Nvidia GPUs, using Kernel Boot is not a viable option due to how the Nvidia proprietary driver works with the Linux kernel. Add the necessary parameters to the default entry in the GRUB menu by editing the file /etc/default/grub. To edit files in the root directory, see XFS Features and Root Immutability in Nitrux.

Configuration:

kboot uses the directory /etc/kboot.d files to load kernels.

  • ⚠️ Important: The files in this directory must refer to a valid kernel (vmlinuz) and initram images (initrd.img) within the filesystem. We recommend putting kernel images other than the default kernel and initrd in the directory /kboot for better organization. In addition, to prevent polluting the GRUB menu.

Options:

sudo kboot -h: Displays the help of kboot.
sudo kboot -d: Runs kboot in verbose mode.
sudo kboot -v: Displays the version of kboot.

Using Kernels from Distrobox Containers

Installing a Linux kernel on a Distrobox container and using it with Kernel Boot is possible. To do this, we need to create a container using Distrobox; it is highly recommended in this case to use a Debian-based container, as one of the differences between Linux distributions is module setups and configurations tailored to their specific system environments, e.g., initrd generation.

  • 🔰 Information: To learn how to manage software in Nitrux, see the tutorial about Software Management.

Let’s assume we use a similar container as the tutorial to use Distrobox. To install the kernel package, run the following command.

#    Run the command without entering the container

distrobox-enter --name debian12-distrobox -- sudo apt install linux-image-amd64 linux-headers-amd64 dkms initramfs-tools

Then, we only copy the respective kernel image, initrd, System.map, and config files in the container’s /boot directory to any directory on our home. And also the modules for that kernel.

  • 🔰 Information: Replace the version number of the files and directory accordingly; in the examples below, we installed the Debian kernel 6.4.0-1.
#    Run this command *outside of the container*

mkdir -p $HOME/usr/lib/modules/

#    Run the commands without entering the container

distrobox-enter --name debian12-distrobox -- cp -r /boot/{vmlinuz,initrd.img,System.map,config}-6.4.0-1-amd64 $HOME
distrobox-enter --name debian12-distrobox -- cp -r /usr/lib/modules/6.4.0-1-amd64 $HOME/usr/lib/modules/

Next, we copy or move these files to the directory /kboot/debian. We include configuration files in the directory /etc/kboot.d that can be used as examples for using Kernel Boot.

#    Enter the overlay and add the files to the Kernel Boot directory; do this on a separate tab if you've entered the container
#    Replace $USER with your username

sudo overlayroot-chroot

mount -t devtmpfs dev /dev
mount -t auto $(findfs LABEL=NX_HOME) /home

cp -r /home/$USER/{vmlinuz,initrd.img,System.map,config}-6.4.0-1-amd64 /kboot/debian
cp -r /home/$USER/usr/lib/modules/6.4.0-1-amd64 /usr/lib/modules

umount /dev /home

sync

exit

#    Run this command *outside of the overlay*

rm -r $HOME/usr/lib/modules/

Optionally, create soft links to /boot in the root directory so GRUB is aware of the kernel, and it’s added to a menu entry. If that is not wanted, don’t create the soft links and use Kernel Boot to switch the kernel.

#    Enter the overlay and add the files to the Kernel Boot directory; do this on a separate tab if you've entered the container
#    Replace $USER with your username

sudo overlayroot-chroot

mount -t devtmpfs dev /dev
mount -t auto $(findfs LABEL=NX_HOME) /home

ln -sv /kboot/debian/initrd.img-6.4.0-1-amd64 /boot/initrd.img-6.4.0-1-amd64
ln -sv /kboot/debian/vmlinuz-6.4.0-1-amd64 /boot/vmlinuz-6.4.0-1-amd64
ln -sv /kboot/debian/System.map-6.4.0-1-amd64 /boot/System.map-6.4.0-1-amd64
ln -sv /kboot/debian/config-6.4.0-1-amd64 /boot/config-6.4.0-1-amd64

update-grub

umount /dev /home

sync

exit

Known Issues

  • When using Nvidia hardware, the display output is not updated when switching to a different kernel due to how the Nvidia proprietary driver works with the Linux kernel.

That’s it; this concludes today’s tutorial.