Inhaltsverzeichnis

Building a Preemt-RT Kernel

Introduction

The kernel can be easily installed on a running system. During the boot process, the kernel is started with the latest version number by default. If you want to return to an old version, you can select the desired kernel version in the grub menu „Advanced options for Linux Mint“.

Preparation

Installing the toolchain

sudo apt install libncurses5-dev build-essential libssl-dev

Get the preemt-rt patch

Check here whether a patch is available for your currently installed kernel. If not, choose the next newer version and download the patch.

For example:
If you are running a 4.4.165 kernel choose the following patch:
patch-4.4.148-rt166-rc1.patch.gz

If you want to use a kernel version that is not already installed, please install the generic kernel with the correct version with this guide first.

Get the Linux sources

Install the compatible generic kernel

For RT-patch v4.4.148-rt166-rc1 install generic kernel 4.4.0

Instructions

Build the kernel

Patch the kernel sources

Choose the build variant

This selection will affect, how many modules will be built. The sizef and the range of functions of the monolitic kernel will not be changed. Additional modules can be built and installed after the kernel is installed.

Configure the kernel

a.) Full module support

  1. Copy the kernel configuration from the generic kernel.
    • Make sure you copy the correct config-file with the correct version (i.e. config-4.4.0-040400-generic)
      cd <pathToKernelSrc>
      cp /boot/<yourDistributionConfig> ./.config
  2. Applay the configuration to the patched kernel sources.
    make oldconfig
    • This will apply the configuration. However, since the kernel is patched and not identical to the generic kernel, not all configurations are defined. Acccept all presented options with ENTER.

b.) Minimal

You have three different options:

1.) Bare minimum
  1. cd <pathToKernelSrc>
  2. Depending on the CPU architecture:
    1. X86 - 64bit make x86_64_defconfig
    2. X86 - 32bit make i386_defconfig
    3. See <pathToKernelSrc>/arch/<architecture>/configs for more possibilities
  3. Open the configuration menu make menuconfig
  4. Add all modules and drivers you need.
2.) Copy module configuration from host
  1. cd <pathToKernelSrc>
  2. make localmodconfig
  3. Open the configuration menu make menuconfig
  4. Add all additional modules and drivers you need.

Note: Most modules are only loaded when they are needed.

3.) Copy module configuration from a different machine

On target machine (with generic kernel loaded):

  1. lsmod > /tmp/mylsmod

On host:

  1. cd <pathToKernelSrc>
  2. Copy the 'mylsmod' file:
    1. scp <targetUsername>@<targetHostname>:/tmp/mylsmod ./
  3. make LSMOD=./mylsmod localmodconfig
  4. Open the configuration menu make menuconfig
  5. Add all additional modules and drivers you need.

Additional configurations

  1. Open the configuration menu
    make menuconfig
  2. Enable the fully preemptible kernel (The path may be different depending on the kernel version)
    • Processor type and features —> Preemption Model /Voluntary Kernel Preemption (Desktop)) —> (X) Fully Preemptible Kernel (RT)
      • or
    • Kernel options —> Preemption Model (No Forced Preemption (Server)) —> (X) Fully Preemptible Kernel (RT)
  3. Deactivate expert mode
    1. General setup —> [ ] Configure standard kernel features (expert users)
  4. Save the configuration and exit the menu

Make and install the kernel

This will going to take about an hour.

  1. Compile kernel
    make -j8
  2. Compile modules
    make modules -j8
  3. Install kernel modules
    sudo make modules_install
  4. Install kernel
    sudo make install
  5. Reboot
  6. Check with uname -a the kernel version