I’ve been setting up ROS 2 for one of my recent robotics projects that I am expecting will have important deterministic requirements. Surprisingly, while Dashing Diademata is the first LTS version with Ubuntu 18.04 as Tier 1, there isn’t much documentation on getting your operating system ready for real-time stuff, so I thought I might as well document my process. So as of writing this post, I am working with Ubuntu 18.04.2 which comes with the kernel version 4.18.0-15-generic.
Download Compatible Kernel and Patch
The idea is to modify your Linux kernel with a version where PREEMPT_RT is supported. According to the Linux Foundation Page, as of this post, the stable version is 4.19-rt. So, we want to obtain this stable version, as well as the corresponding Linux kernel.
To keep things a bit more manageable, let’s first create a kernel folder in your home folder and download, extract, and patch everything in there. First, let’s download the latest patch.
|
wget http://cdn.kernel.org/pub/linux/kernel/projects/rt/4.19/patch-4.19.50-rt22.patch.gz |
Edit: As of August 4, 2019, the above link no longer works as a new version has come out. To exactly replicate this post, run instead the following:
|
wget http://cdn.kernel.org/pub/linux/kernel/projects/rt/4.19/older/patch-4.19.50-rt22.patch.gz |
Then, from the Linux kernel page, also download the corresponding kernel version.
|
wget https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/linux-4.19.50.tar.gz |
Because recent Debian versions surprisingly do not include bison or flex in build-essential, you need to install those two to copy your old config file over.
|
sudo apt-get install bison flex |
Once all the files have been downloaded and packages have been installed, let’s unpack the kernel and rename it so that it matches the patch name.
|
tar -xvf linux-4.19.50.tar.gz mv linux-4.19.50 linux-4.19.50-rt22 gunzip patch-4.19.50-rt22.patch |
Patch Kernel
Now, inside the kernel folder linux-4.19.50-rt22, patch the kernel.
|
patch -p1 < ../patch-4.19.50-rt22.patch |
Next, we copy over the current OS configuration files, install some tools, and proceed with enable the preemptible kernel.
|
cp /boot/config-4.18.0-15-generic .config yes '' | make oldconfig sudo apt install libncurses5-dev build-essential libssl-dev ccache make menuconfig |
Now comes the step that has been slightly modified from previous versions because of the relocation of the option to select the Fully Preemptible Kernel (RT). Under General setup exists Preemptible Model. Select the Fully Preemptible Kernel (RT). (Note that this is NOT under Processor type and features)
Make and Install RT Kernel
Exit out of menuconfig and let’s make and install the kernel. Note that this process can take a while depending on the computer you are working on.
|
make sudo make modules_install sudo make install |
Once everything is done, reboot your computer. Your new kernel should show as 4.19.50-rt22.