I am trying to install a PREEMPT_RT kernel for my ubuntu distribution as this is a requirement for a robot I am working on. But no matter what I do I get errors when compiling the kernel. I've included the error messages in the question, and I have provided links for full terminal outputs. I am not very expreienced with linux, so I have been following setup-guides from the manufacturer with the following steps:

curl -SLO https://www.kernel.org/pub/linux/kernel/v5.x/linux-5.6.19.tar.xz
curl -SLO https://www.kernel.org/pub/linux/kernel/projects/rt/5.6/older/patch-5.6.19-rt12.patch.xz

xz -d linux-5.6.19.tar.xz
xz -d patch-5.6.19-rt12.patch.xz

tar xf linux-5.6.19.tar
cd linux-5.6.19
patch -p1 < ../patch-5.6.19-rt12.patch

make oldconfig

In the configuration I simply select Fully Preemptible Kernel (RT) (PREEMPT_RT_FULL) for the preemption model, and leave all the other settings at their default.

fakeroot make -j4 deb-pkg

dpkg-buildpackage: error: fakeroot -u debian/rules clean subprocess returned exit status 1 make2: *** [scripts/Makefile.package:77: deb-pkg] Error 1 make: *** [Makefile:1429: deb-pkg] Error 2

All terminal output here

If I instead try to use

sudo make -j4 deb-pkg

make3: *** [debian/rules:6: build] Error 2 dpkg-buildpackage: error: debian/rules build subprocess returned exit status 2 make2: *** [scripts/Makefile.package:77: deb-pkg] Error 2 make: *** [Makefile:1429: deb-pkg] Error 2

All termial output here

When that didn't work I tried following the steps given in the answer to this question

curl -SLO https://www.kernel.org/pub/linux/kernel/v5.x/linux-5.6.19.tar.gz
curl -SLO https://www.kernel.org/pub/linux/kernel/projects/rt/5.6/older/patch-5.6.19-rt12.patch.gz
tar xvzf linux-5.6.19.tar.gz
cd linux-5.6.19
gzip -cd ../patch-5.6.19-rt12.patch.gz | patch -p1 --verbose
make menuconfig

patch, menuconfig

make -j4
sudo make modules_install -j4

sudo make modules_install -j4 sed: can't read modules.order: No such file or directory make: *** [Makefile:1316: modinst] Error 2


sudo make modules -j4
sudo make modules_install -j4

When I use the make modules command it compiles for a long time and it terminates successfully, but once again when I run modules_install I get an error message:

cp: cannot stat 'modules.builtin': No such file or directory make: *** [Makefile:1317: modinst] Error 1

I am at a loss for what to try next. I have tried different kernel versions and different operating systems (Ubuntu 18.04 and 20.04), and I get the same error in all of them. The instructions I have been given seems so clear and direct, so I'm wondering if I'm doing something wrong, or if there is some hardware incompatibilites or something of that nature? For reference I am currently running Ubuntu 20.04.02, kernel 5.8.0-53-generic, hardware. Does anyone have any Idea what may cause this issue?

PS: this is my first question on this site, feedback on question format is appreciated (too much/to little/ relevance of information etc.) I just added all the information the terminal gave me, not sure what is or isn't useful


I was able to build the PREEMPT-RT kernel on Ubuntu 20.04 mostly based on this guide as follows:

sudo apt install build-essential git libssl-dev libelf-dev flex bison

Download kernel source and patch for that version:

wget https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.4.143.tar.xz
wget https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/5.4/patch-5.4.143-rt64-rc2.patch.xz

Unpack and apply patches:

tar -xf linux-5.4.143.tar.xz
cd linux-5.4.143
xzcat ../patch-5.4.143-rt64-rc2.patch.xz | patch -p1

Configure, and when asked for Preemption Model select the Fully Preemptible Kernel. Accept the default value for the rest:

cp /boot/config-5.4.0-81-generic .config
make oldconfig

Edit the .config file and change CONFIG_SYSTEM_TRUSTED_KEYS="debian/canonical-certs.pem" to CONFIG_SYSTEM_TRUSTED_KEYS=""

Build kernel:

make -j8 deb-pkg

Install the generated packages, and reboot your system.

sudo dpkg -i ../linux-headers-5.4.143-rt64-rc2_5.4.143-rt64-rc2-1_amd64.deb ../linux-image-5.4.143-rt64-rc2_5.4.143-rt64-rc2-1_amd64.deb ../linux-libc-dev_5.4.143-rt64-rc2-1_amd64.deb

After reboot you should be able to see something like this:

# uname -a
Linux vod 5.4.143-rt64-rc2 #1 SMP PREEMPT_RT Tue Sep 7 20:19:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

The guide suggests a few other steps but I haven't tested them yet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.