Install compilers required for building the kernel:
$ sudo apt install build-essential git libssl-dev libelf-dev
$ Download and patchVerify on kernel.org the patches available and pick the most appropriate kernel version:
$ VER=5.4.61
$ VER_RT=5.4.61-rt37Download the kernel and the rt patch:
$ wget https://kernel.org/pub/linux/kernel/v5.x/linux-$VER.tar.gz
$ wget https://kernel.org/pub/linux/kernel/projects/rt/5.4/patch-$VER_RT.patch.gzExtract the archive and apply the patch:
$ tar xzvf linux-$VER.tar.gz
$ cd linux-$VER
$ gzcat ../patch-$VER_RT.patch.gz | patch -p1Copy over your old config and use that to configure your new kernel:
$ cp /boot/config-`uname -r` .config
$ make oldconfigwhen asked for Preemption Model, select the option “Fully Preemptible Kernel” and accept the default value for the rest.
Alternatively, you could use the graphical interface to configure it using menuconfig. Note that menuconfig requires flex and bison dependencies:
$ sudo apt install flex bison
$ make menuconfigsearch for PREEMPT_RT and set it to “Fully Preemptible Kernel (RT)”.
Build the kernel as a debian package using make command
$ make -j8 deb-pkg
$ sudo dpkg -i ../linux-headers-$VER_RT_$VER_RT-1_amd64.deb ../linux-image-$VER_RT_$VER_RT-1_amd64.deb ../linux-libc-dev_$VER_RT-1_amd64.debReboot your system and check the kernel. It should show PREEMPT_RT
$ uname -a
Linux bmwin864 5.4.61-rt37 #1 SMP PREEMPT_RT Fri Sep 11 17:09:05 CEST 2020 x86_64 x86_64 x86_64 GNU/Linux