Preempt RT Kernel

Flash the SD card with the latest Raspbian Lite image using Etcher or your favorite way.

Connect a monitor and a keyboard and boot up the RPi4. It may or may not show the log in prompt. Whenever it stops print text to the monitor you should be able to login with the username pi and the password raspberry.

Next we’ll setup a few things in Raspbian, the space bar selects or deselects items in a list with [ ]. The tab key moves around in the menu. If you’re in another country make adjustments as needed.

sudo raspi-config

Advanced Options > Expand Filesystem

Localisation Options > Change Locale

Select en.US.UTF-8 UTF8

Make sure you deselect en.GB.UTF-8 UTF8 or you will have a British accent

Default locale for the system environment: en.US.UTF-8 UTF8

Localisation Options > Change Timezone
US > your timezone
Localisation Options > Change Wi-fi Country
US
Network Options > WiFi
Enter your SSID and Password if you have WiFi.

Interfacing Options > SSH Enable

Select Finish and Reboot

You have the option at this point to SSH into the RPi4 from another PC.

To find out the IP address log in and issue this command

sudo ifconfig

If you have WiFi enabled and setup use that inet address to SSH into the Rpi4.

From another Linux PC on your LAN you can open a terminal and issue

ssh pi@192.168.x.x (use the inet address you found from above)

Now we’ll download and build the preempt rt kernel

sudo apt update
apt list --upgradable
sudo apt dist-upgrade
sudo apt autoremove
sudo apt install git
git clone --depth=1 https://github.com/raspberrypi/linux -b rpi-4.19.y-rt
sudo apt install bison flex libncurses5-dev libssl-dev bc mc
cd linux
KERNEL=kernel7l
make bcm2711_defconfig
make menuconfig
# save and exit
make -j4 zImage
make -j4 modules
make -j4 dtbs
sudo make modules_install
# should report back DEPMOD  4.19.59-rt23-v7l+

Install the RT PREEMPT Kernel

sudo cp arch/arm/boot/dts/*.dtb /boot/
sudo cp arch/arm/boot/dts/overlays/*.dtb* /boot/overlays/
sudo cp arch/arm/boot/dts/overlays/README /boot/overlays/
sudo cp arch/arm/boot/zImage /boot/$KERNEL.img

Fix some boot options for best latency

sudo nano /boot/cmdline.txt

Add the following to the current line to make one long line

quiet splash lapic noxsave acpi_osi= isolcpus=1,2,3 idle=poll acpi_irq_nobalance noirqbalance vmalloc=32MB clocksource=acpi_pm net.ifnames=0

Ctrl x to exit, save y, enter to write to the file

To get rid of old deb files in apt cache and reboot

sudo apt clean
sudo reboot -n

Log back into the RPi4 after it boots up and check that you have the preempt rt kernel installed.

uname -a
... 4.19.71-rt24-v7l+ #1 SMP PREEMPT RT ...

Updated Sep 07, 2020