1. Choose and download a kernel version and the real-time patch
You have to decide which kernel version to use. We recommend to choose a version as close as possible from the generic kernel corresponding to your Ubuntu version. At the time it was written, in Index of /pub/linux/kernel/projects/rt/5.15/ the last 5.15.x-rt kernel is in patch-5.15.70-rt50.patch.gz. If you choose a different version, simply substitute the numbers. Having decided on a version, use curl to download the source files:
$ mkdir rt-linux; cd rt-linux $ curl -SLO https://www.kernel.org/pub/linux/kernel/v5.x/linux-5.15.70.tar.gz $ curl -SLO https://www.kernel.org/pub/linux/kernel/projects/rt/5.15/older/patch-5.15.70-rt50.patch.gz
Decompress them with:
$ tar xvzf linux-5.15.70.tar.gz $ gunzip patch-5.15.70-rt50.patch.gz
Extract the source code and apply the patch:
$ cd linux-5.15.70 $ patch -p1 < ../patch-5.15.70-rt50.patch
2. Configure and build the kernel
First, install the necessary dependencies:
$ sudo apt-get install build-essential bc curl ca-certificates fakeroot gnupg2 libssl-dev lsb-release libelf-dev bison flex
The next step is to configure your kernel:
$ make oldconfig
This opens a text-based configuration menu. When asked for the Preemption Model, choose the Fully Preemptible Kernel:
Preemption Model 1. No Forced Preemption (Server) (PREEMPT_NONE) 2. Voluntary Kernel Preemption (Desktop) (PREEMPT_VOLUNTARY) 3. Preemptible Kernel (Low-Latency Desktop) (PREEMPT) > 4. Fully Preemptible Kernel (Real-Time) (PREEMPT_RT) (NEW)
We recommend keeping all options at their default values.
Note:
$ vi .config
replacing the line
CONFIG_SYSTEM_TRUSTED_KEYS="debian/canonical-certs.pem"
CONFIG_SYSTEM_REVOCATION_KEYS="debian/canonical-revoked-certs.pem"
CONFIG_DEBUG_INFO_BTF=y
with
CONFIG_SYSTEM_TRUSTED_KEYS=""
CONFIG_SYSTEM_REVOCATION_KEYS=""
CONFIG_DEBUG_INFO_BTF=n
Afterwards, you are ready to compile the kernel. As this is a lengthy process, set the multi threading option -j to the number of your CPU cores:
$ fakeroot make -j4 deb-pkg
Finally, you are ready to install the newly created package. The exact names depend on your environment, but you are looking for headers
and images
packages without the dbg
suffix. To install:
$ sudo dpkg -i ../linux-headers-5.15.70-rt50*.deb ../linux-image-5.15.70-rt50*.deb
Reboot the computer
3. Allow a user to set real-time permissions for its processes
After the PREEMPT_RT
kernel is installed and running, add a group named realtime
and add the user controlling your robot to this group:
$ 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
The limits will be applied after you log out and in again.
----------------------------------------------------------------------------------------------
RT patch: https://www.kernel.org/pub/linux/kernel/projects/rt/
Kernel source: https://www.kernel.org/pub/linux/kernel
1.
$ cd /usr/src/rt_kernal/
$ sudo su
$ xz -cd linux-5.4.182.tar.xz | tar xvf -
$ cd linux-5.4.182
$ xzcat ../patch-5.4.182-rt72.patch.xz | patch -p1
2.
$ cp /boot/config-*-generic .config
3.
$ make menuconfig
4.
$ make oldconfig
$ make modules_install
$ make install
5.
$ sudo vi /etc/default/grub
GRUB_TIMEOUT=10
GRUB_DEFAULT="1>2"
$ update-grub