这是针对 Ubuntu 19.10 及更高版本的,我修补了 Linux 5.4.5 rt 内核补丁,因为 Linux 5.3(Ubuntu 19.10 的基础)没有 rt 内核补丁。
0. 创建一个工作目录
# Make dir and move to working directory
$ mkdir ~/kernel && cd ~/kernel
Run Code Online (Sandbox Code Playgroud)
1.下载内核和补丁
从https://www.kernel.org/下载内核和 rt 补丁。你可以在下面得到这些:
(内核) https://www.kernel.org/pub/linux/kernel/
(rt 补丁) https://www.kernel.org/pub/linux/kernel/projects/rt/
注意rt patch和kernel的版本要一致。我使用了linux-5.4.5.tar.gz和patch-5.4.5-rt3.patch.gz。
如果您在 ~/kernel 上下载这些,请跳过下面并继续执行第 2 步。
# Move these zip file to ~/kernel
$ cd ~/Download
$ mv linux-5.4.5.tar.gz patch-5.4.5-rt3.patch.gz ~/kernel/.
Run Code Online (Sandbox Code Playgroud)
2.提取内核源码并打补丁rt内核
# Extract kernel sources
$ cd ~/kernel
$ tar xvzf linux-5.4.5.tar.gz
# Patch rt kernel
$ cd linux-5.4.5
$ gzip -cd ../patch-5.4.5-rt3.patch.gz | patch -p1 --verbose {}
Run Code Online (Sandbox Code Playgroud)
3. 安装需要的包
对于使用 menuconfig GUI,libncurses-dev是必需的。flex并且bison在编译内核时会用到。
# For using gui
$ sudo apt install libncurses-dev libssl-dev
# For compiling kernel
$ sudo apt install flex bison
Run Code Online (Sandbox Code Playgroud)
4. 为 RT 配置内核
$ make menuconfig
Run Code Online (Sandbox Code Playgroud)
并进入 menuconfig GUI。
# Make preemptible kernel setup
General setup ---> [Enter]
Preemption Model (Voluntary Kernel Preemption (Desktop)) [Enter]
Fully Preemptible Kernel (RT) [Enter] #Select
# Select <SAVE> and <EXIT>
# Check .config file is made properly
Run Code Online (Sandbox Code Playgroud)
请注意,Check for stack overflows不再有GUI 配置选项。您可以通过搜索“溢出”来检查它。在图形菜单上键入/和overflow。
5.编译内核
$ make -j20
$ sudo make modules_install -j20
$ sudo make install -j20
Run Code Online (Sandbox Code Playgroud)
6. 使内核图像更轻
正如@mrRo8o7 之前所说,大initrd图像可能会发生内核恐慌。因此,您可以通过以下方式解决此问题:
# Strip unneeded symbols of object files
$ cd /lib/modules/5.4.5-rt3 # or your new kernel
$ sudo find . -name *.ko -exec strip --strip-unneeded {} +
# Change the compression format
$ sudo vi /etc/initramfs-tools/initramfs.conf
# Modify COMPRESS=lz4 to COMPRESS=xz (line 53)
COMPRESS=xz
[:wq]
Run Code Online (Sandbox Code Playgroud)
然后更新initramfs
$ sudo update-initramfs -u
Run Code Online (Sandbox Code Playgroud)
7.验证和更新grub
验证该目录并更新 grub。
# Make sure that initrd.img-5.4.5-rt3, vmlinuz-5.4.5-rt3, and config-5.4.5-rt3 are generated in /boot
$ cd /boot
$ ls
# Update grub
$ sudo update-grub
Run Code Online (Sandbox Code Playgroud)
8. 重启并验证
$ sudo reboot
# After the reboot
$ uname -a
Run Code Online (Sandbox Code Playgroud)
然后你可以检查你的新内核版本
Linux [PROMPT] 5.4.5-rt3 …
Run Code Online (Sandbox Code Playgroud)
步骤0-建立工作目录
制作工作目录
#Move to working directory
mkdir ~/kernel && cd ~/kernel
Run Code Online (Sandbox Code Playgroud)
第1步-下载内核和补丁
转到https://www.kernel.org/pub/linux/kernel/并将所需的内核版本下载到〜/ kernel。同样,请访问https://www.kernel.org/pub/linux/kernel/projects/rt/并下载与已下载内核版本相同的RT补丁。我使用的内核和补丁是linux-4.9.115.tar.gz和patch-4.9.155-rt93.patch.gz。
第2步-解压缩内核
tar -xzvf linux-4.9.115.tar.gz
Run Code Online (Sandbox Code Playgroud)
第3步-修补内核
#Move to kernel source directory
cd linux-4.9.115
gzip -cd ../patch-4.9.115-rt93.patch.gz | patch -p1 --verbose
Run Code Online (Sandbox Code Playgroud)
步骤4-启用实时处理 此步骤需要libncurses-dev
sudo apt-get install libncurses-dev libssl-dev
Run Code Online (Sandbox Code Playgroud)
下一条命令将在终端中启动图形菜单,以生成配置文件。
make menuconfig
Run Code Online (Sandbox Code Playgroud)
转到该位置并进行相应的更改
##Graphical Menu##
Processor type and features ---> [Enter]
Preemption Model (Voluntary Kernel Preemption (Desktop)) [Enter]
Fully Preemptible Kernel (RT) [Enter] #Select
[Esc][Esc]
Kernel hacking --> [Enter]
Memory Debugging [Enter]
Check for stack overflows #Already deselected - do not select
[Esc][Esc]
[Right Arrow][Right Arrow]
<Save> [Enter]
.config
<Okay> [Enter]
<Exit> [Enter]
[Esc][Esc]
[Right Arrow]
<Exit> [Enter]
Run Code Online (Sandbox Code Playgroud)
第5步-编译内核
make -j20
sudo make modules_install -j20
sudo make install -j20
Run Code Online (Sandbox Code Playgroud)
第6步-验证和更新 验证是否在/ boot目录中生成了initrd.img-4.9.115-rt93,vmlinuz-4.9.115-rt93和config-4.9.115-rt93并更新了grub。
cd /boot
ls
sudo update-grub
Run Code Online (Sandbox Code Playgroud)
验证是否有包含文本“menuentry‘的Ubuntu,Linux的4.9.115-rt93’”一menuentry的/boot/grub/grub.cfg文件
要在grub中更改默认内核,请将GRUB_DEFAULT值编辑为/etc/default/grub所需的内核。
注意: 0是第一个菜单项
7-重新启动并验证
sudo reboot
Run Code Online (Sandbox Code Playgroud)
系统重启后,打开终端并用于uname -a检查内核版本,它应如下所示
Linux abhay-home 4.9.115-rt93 #1 SMP PREEMPT RT Mon May 13 03:32:57 EDT 2019 x86_64 x86_64 x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)
注意: “ SMP PREEMPT RT”验证您的系统正在运行实时内核。
| 归档时间: |
|
| 查看次数: |
8515 次 |
| 最近记录: |