```
Linux in itself is not real time capable. With the additional PREEMPT_RT patch it gains real-time capabilities. The sources have to be downloaded first. After unpacking and patching, the kernel configuration has to be adapted. Then, the kernel can be built and started.
1. Getting the sources
First, the kernel version should be chosen. After this, take a look if the PREEMPT_RT patch is available for this particular version.
Check current kernel version
$ uname -a
Download PREEMPT_RT patch
https://www.kernel.org/pub/linux/kernel/projects/rt/
Choose a patch that is close to the current kernel version (not necessarily the same as the current version)
Download kernel
http://www.kernel.org/pub/linux/kernel/
Download the kernel according to the downloaded patch version, and the kernel version should be consistent with the patch.
This example is based on the Linux kernel version linux-3.18.69 and PREEMPT_RT patch version patch-3.18.69-rt75.patch.
2. Patch the Linux kernel
After downloading, unpack the archives and patch the Linux kernel.
Created a folder
$ sudo mkdir /usr/src/rt-preempt-linux
Unpack the downloaded kernel and patch, first put the unzipped patch into the extracted kernel folder, and then put the kernel folder into the rt-preempt-linux folder you just created. Then run the following command to patch.
$ cd /usr/src/rt-preempt-linux/linux-3.18.69
$ sudo patch -p1 < patch-3.18.69-rt75.patch
3. Configuring the kernel
Continue executing instructions in the path /usr/src/rt-preempt-linux/linux-3.18.69.
Delete the remaining .o files and other dependent files in the directory:
$ sudo make mrproper
A config file matching the current kernel version can be found in the boot folder, for example: config-3.16.0-30-generic. Copy it to the current directory /usr/src/rt-preempt-linux/linux-3.18.69.
$ sudo cp /boot/config-3.16.0-30-generic.config
Install a necessary kit
$ sudo apt-get install libncurses5-dev
Enter the menu configuration interface, the window must be large enough.
$ sudo make menuconfig
In "Processor type and features"
(1) Select "Complete Preemption (Real-Time)" in "Preemption Mode" (Depending on the version, you may also select "Fully Preemptible Kernel (RT)" in "Preemption Model")
(2) Select "Thread Softirqs" and "Thread Hardirqs" (If you can't find these two options, you don't need to set it directly to the next step)
Go back to the previous level and go to "Device Drivers" and remove "Staging Drivers"
4. Building the kernel
The compilation process below is time consuming and takes about 2 hours.
Still executing instructions in the path /usr/src/rt-preempt-linux/linux-3.18.69
$ sudo make -jn
(n is the job book to be derived. In practice, one or two jobs are usually derived on each processor. For example, $make -j4 can be used on a dual-core processor.)
$ sudo make modules_install
$ sudo make install
$ cd /boot
$ sudo mkinitramfs -k -o initrd.img-3.18.69-rt 3.18.69-rt75
Finally, you can choose to use the patched kernel. If you can't find the corresponding option after rebooting, modify /boot/grub/grub.cfg. The modification method can be checked online.
reference:
https://www.jianshu.com/p/8787e45a9e01
http://blog.csdn.net/zzsfqiuyigui/article/details/7621665
http://blog.csdn.net/deng_sai/article/details/38080603
http://blog.csdn.net/fjt19900921/article/details/8316481
```