RT Preempt Kernel - gkgkgk1215/else GitHub Wiki
Download the kernel
- Install the necessary dependencies:
sudo apt-get update
sudo apt-get install build-essential bc curl ca-certificates gnupg2 libssl-dev lsb-release libelf-dev bison flex dwarves zstd libncurses-dev doxygen libncurses-dev kernel-package devscripts
-
Check the version of kernel you should install: https://www.kernel.org/pub/linux/kernel/projects/rt/
-
Check the version of kernel you are currently using: (For ubuntu 20.04.6 LTS, the kernel 5.15.0-67-generic is installed.)
uname -r
- Download the source files. For kernel 5.15, use the following bash commands:
cd ~
mkdir kernel && cd kernel
curl -SLO https://www.kernel.org/pub/linux/kernel/v5.x/linux-5.9.1.tar.xz
curl -SLO https://www.kernel.org/pub/linux/kernel/v5.x/linux-5.9.1.tar.sign
curl -SLO https://www.kernel.org/pub/linux/kernel/projects/rt/5.9/patch-5.9.1-rt20.patch.xz
curl -SLO https://www.kernel.org/pub/linux/kernel/projects/rt/5.9/patch-5.9.1-rt20.patch.sign
- Decompress them with:
xz -d *.xz
Verifying file integrity
- You can use gpg2 to verify the .tar archives:
gpg2 --verify linux-*.tar.sign
gpg2 --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys [YOUR RSA KEYS HERE]
gpg2 --verify linux-*.tar.sign
gpg2 --verify patch-*.patch.sign
gpg2 --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys [YOUR RSA KEYS HERE]
gpg2 --verify patch-*.patch.sign
Compiling the kernel
tar xf linux-*.tar
cd linux-*/
patch -p1 < ../patch-*.patch
cp -v /boot/config-$(uname -r) .config
make olddefconfig
make menuconfig
-
The second command brings up a terminal interface in which you can configure the preemption model. Navigate with the arrow keys to General Setup > Preemption Model and select Fully Preemptible Kernel (Real-Time).
-
After that navigate to Cryptographic API > Certificates for signature checking (at the very bottom of the list) > Provide system-wide ring of trusted keys > Additional X.509 keys for default system keyring
-
Remove the “debian/canonical-certs.pem” from the prompt and press Ok. Save this configuration to .config and exit the TUI.
make -j$(nproc) deb-pkg
sudo dpkg -i ../linux-headers-*.deb ../linux-image-*.deb
Verifying the new kernel
- Restart your system. The Grub boot menu should now allow you to choose your newly installed kernel. To see which one is currently being used, see the output of the uname -a command. It should contain the string PREEMPT RT and the version number you chose. Additionally, /sys/kernel/realtime should exist and contain the the number 1.
Allow a user to set real-time permissions for its processes
sudo addgroup realtime
sudo usermod -a -G realtime $(whoami)
- Afterwards, add the following limits to the realtime group in /etc/security/limits.conf:
@realtime soft rtprio 99
@realtime soft priority 99
@realtime soft memlock 102400
@realtime hard rtprio 99
@realtime hard priority 99
@realtime hard memlock 102400
- Reboot the system.
Benchmark test
git clone git://git.kernel.org/pub/scm/utils/rt-tests/rt-tests.git
cd rt-tests
git checkout stable/v1.0
sudo apt-get install libnuma-dev
make all
sudo make install
./cyclictest -l100000 -m -n -a0 -t1 -p99 -i400 -h400