This repository contains installation of RT_PREEMPT patch on Ubuntu 20.04.4 LTS ; kernel 5.9.1. If you want to install with different kernel, installation steps are same, you just have to download your desired kernel sources from Linux Kernel Sources and RT_PREEMPT Patch Sources. Hope this repository will save time for you.
Note that, if you want better real-time performance you will need to change several BIOS settings. It is recommended to disable management related settings. Mostly this settings scales your CPU frequency based on the load. However to keep constant periodicity it is important to have stable frequency. Please change BIOS settings after doing a brief search about the settings, do not follow advices blindly. Each hardware has different BIOS settings, therefore, I can not know all possible settings. Keep in mind that if you have latency in your implementation, it is a good starting point to tweak BIOS settings.
Before starting to build, make sure that Safe Boot option is disabled in your BIOS settings and run commands below to get required libraries for building/installation.
sudo apt-get update
sudo apt-get install git build-essential automake autoconf libtool pkg-config cmake linux-source bc kmod cpio flex -y
sudo apt-get install intltool autoconf-archive libpcre3-dev libglib2.0-dev libgtk-3-dev libxml2-utils zstd dwarves -y
sudo apt-get install libnuma-dev libssl-dev libtool libncurses5 libncurses5-dev autogen libudev-dev libelf-dev stress -y
sudo apt-get install kernel-package fakeroot zlib1g-dev bin86 g++ bison cpufrequtils -y
You can download kernel version from : Linux Kernel Sources
You can download RT_Preempt version with same kernel : RT_PREEMPT Patch Sources
mkdir sources
cd sources
Download the kernel source and download corresponding RT patch. Note that patch has same version 5.9.1 as kernel.
wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.9.1.tar.xz
wget https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/5.9/patch-5.9.1-rt20.patch.xz
xz -cd linux-5.9.1.tar.xz | tar xvf -
cd linux-5.9.1
xzcat ../patch-5.9.1-rt20.patch.xz | patch -p1
sudo mv ../linux-5.9.1 /usr/src/ -f
cd /usr/src/linux-5.9.1
Now it is time for kernel configuration. Every kernel configuration parameter might have effect on real-time performance, you must read kernel configuration parameters and what they means. A good resource is Kernel Config Documentation. You can search any configuration settings and learn about the dependencies.
sudo make menuconfig
Processor type and features -> Preemption Model -> Fully Preemptible Kernel (RT).
Alternatively you can edit .config file, which includes all settings that you see in menuconfig window.
CONFIG_SYSTEM_TRUSTED_KEYS=""
sudo nano .config
and find the part with CONFIG_SYSTEM_TRUSTED_KEYS and make sure that it's empty like above.
For additional kernel configurations check My-Xenomai-Installation (Configurations For Realtime). Just ignore ACPI settings and Xenomai related configurations and apply all other configurations, for better real-time performance. Note that only Fully Preemptible Kernel option is enough, but if you want better performance you can try those options as well.
CONFIG_PREEMPT_RT_FULL
CONFIG_CPU_FREQ=n
CONFIG_CPU_IDLE=n
CONFIG_NO_HZ_FULL=y
CONFIG_RCU_NOCB_CPU=y
sudo -s
make -j4
make && make modules && make modules_install && make install
reboot
Just make sure there is no error during make and install process. If you face any error during make process, just read the error carefully, probably the solution will be in the explanation of the error. After reboot, if you see GRUB screen, select Advanced Options for Ubuntu, and select compiled RT kernel version to start.
uname -v
sudo nano /etc/default/grub
GRUB_TIMEOUT_STYLE = menu
GRUB_TIMEOUT = 10
sudo update-grub
sudo reboot
After reboot, if you see GRUB screen, select Advanced Options for Ubuntu, and select compiled RT kernel version to start
uname -v
If your system doesn't start after building, check this thread Compressing initramfs and apply steps below.
Restart your computer start with non-rt kernel. Open your terminal:
cd /lib/modules/5.9.1-rt20
sudo find . -name *.ko -exec strip --strip-unneeded {} +
sudo nano /etc/initramfs-tools/initramfs.conf
find COMPRESS option and change it to xz, after change it should be like below:
COMPRESS=xz
save and exit (CTRL+X and Y and Enter).
sudo update-initramfs -u -k 5.9.1-rt20
sudo update-grub2