当前位置: 首页 > article >正文

CentOS-Stream 9更换RT实时内核

文章目录

  • 1 安装环境
    • 1.1 Centos9原生内核示意
  • 2 下载实时内核
  • 3 CentOS更换阿里YUM源
    • 3.1 更换源
    • 3.2 添加文件内容
      • 3.2.1 centos.repo
      • 3.2.2 centos-addons.repo
    • 3.3 yum源生效
  • 4 安装epel-release
  • 5 安装必要库和软件
  • 6 配置内核
    • 6.1 更改内核文件权限
    • 6.2 使用tar命令解压内核源码文件
    • 6.3 修改`Kconfig.preempt`文件
    • 6.4 进入kernel源码目录,并配置
      • 6.4.1 内核配置步骤
      • 6.4.2 修改`.config`文件
  • 7 构建-安装
  • 8 配置启动项
    • 8.1 更新GRUB配置
    • 8.2 设置默认启动内核
  • 9 重启系统
  • 10 验证新内核

1 安装环境

1.1 Centos9原生内核示意

uname -r
# 5.14.0-547.el9.x86_64

查看CentOS防火墙状态

systemctl status firewalld # 查看防火墙状态
systemctl stop firewalld # 停止防火墙
systemctl start firewalld # 启动防火墙
systemctl enable firewalld # 启用防火墙开机自启动
systemctl disable firewalld # 禁用防火墙开机自启动

关闭防火墙并禁止开机启动

systemctl stop firewalld # 停止防火墙
systemctl disable firewalld # 禁用防火墙开机自启动

2 下载实时内核

Note:下载链接已提供

下载内核直接点击linux-stable-rt-5.15.177-rt83-rebase.tar.gz

3 CentOS更换阿里YUM源

3.1 更换源

# 备份 centos.repo
sudo mv /etc/yum.repos.d/centos.repo /etc/yum.repos.d/centos.repo.backup
# 备份 centos-addons.repo
sudo mv /etc/yum.repos.d/centos-addons.repo /etc/yum.repos.d/centos-addons.repo.backup

3.2 添加文件内容

新建/etc/yum.repos.d/centos.repo 文件和 /etc/yum.repos.d/centos-addons.repo文件

3.2.1 centos.repo

[baseos]
name=CentOS Stream $releasever - BaseOS
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/BaseOS/$basearch/os/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1

[baseos-debug]
name=CentOS Stream $releasever - BaseOS - Debug
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/BaseOS/$basearch/debug/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[baseos-source]
name=CentOS Stream $releasever - BaseOS - Source
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/BaseOS/source/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[appstream]
name=CentOS Stream $releasever - AppStream
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/AppStream/$basearch/os/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1

[appstream-debug]
name=CentOS Stream $releasever - AppStream - Debug
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/AppStream/$basearch/debug/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[appstream-source]
name=CentOS Stream $releasever - AppStream - Source
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/AppStream/$basearch/debug/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[crb]
name=CentOS Stream $releasever - CRB
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/CRB/$basearch/os/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=0

[crb-debug]
name=CentOS Stream $releasever - CRB - Debug
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/CRB/$basearch/debug/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[crb-source]
name=CentOS Stream $releasever - CRB - Source
baseurl=https://mirrors.aliyun.com/centos-stream/$stream/CRB/source/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

3.2.2 centos-addons.repo

[highavailability]
name=CentOS Stream $releasever - HighAvailability
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/HighAvailability/$basearch/os/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=0

[highavailability-debug]
name=CentOS Stream $releasever - HighAvailability - Debug
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/HighAvailability/$basearch/debug/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[highavailability-source]
name=CentOS Stream $releasever - HighAvailability - Source
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/HighAvailability/source/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[nfv]
name=CentOS Stream $releasever - NFV
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/NFV/$basearch/os/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=0

[nfv-debug]
name=CentOS Stream $releasever - NFV - Debug
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/NFV/$basearch/debug/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[nfv-source]
name=CentOS Stream $releasever - NFV - Source
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/NFV/source/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[rt]
name=CentOS Stream $releasever - RT
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/RT/$basearch/os/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=0

[rt-debug]
name=CentOS Stream $releasever - RT - Debug
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/RT/$basearch/debug/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[rt-source]
name=CentOS Stream $releasever - RT - Source
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/RT/source/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[resilientstorage]
name=CentOS Stream $releasever - ResilientStorage
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/ResilientStorage/$basearch/os/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=0

[resilientstorage-debug]
name=CentOS Stream $releasever - ResilientStorage - Debug
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/ResilientStorage/$basearch/debug/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[resilientstorage-source]
name=CentOS Stream $releasever - ResilientStorage - Source
baseurl=http://mirrors.aliyun.com/centos-stream/$stream/ResilientStorage/source/tree/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

[extras-common]
name=CentOS Stream $releasever - Extras packages
baseurl=http://mirrors.aliyun.com/centos-stream/SIGs/$stream/extras/$basearch/extras-common/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Extras-SHA512
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
countme=1
enabled=1

[extras-common-source]
name=CentOS Stream $releasever - Extras packages - Source
baseurl=http://mirrors.aliyun.com/centos-stream/SIGs/$stream/extras/source/extras-common/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Extras-SHA512
gpgcheck=1
repo_gpgcheck=0
metadata_expire=6h
enabled=0

3.3 yum源生效

yum clean all
yum makecache
sudo yum update

4 安装epel-release

sudo yum install epel-release

5 安装必要库和软件

sudo yum install ncurses-devel bison flex elfutils-libelf-devel openssl-devel -y
sudo yum install bc wget git -y

6 配置内核

6.1 更改内核文件权限

sudo chmod 777 linux-stable-rt-5.15.177-rt83-rebase.tar.gz

6.2 使用tar命令解压内核源码文件

tar -zxvf linux-stable-rt-5.15.177-rt83-rebase.tar.gz

6.3 修改Kconfig.preempt文件

cd linux-stable-rt-5.15.177-rt83-rebase
cd ./kernel
gedit Kconfig.preempt

原始内容

# SPDX-License-Identifier: GPL-2.0-only

config HAVE_PREEMPT_LAZY
	bool

config PREEMPT_LAZY
	def_bool y if HAVE_PREEMPT_LAZY && PREEMPT_RT

choice
	prompt "Preemption Model"
	default PREEMPT_NONE

config PREEMPT_NONE
	bool "No Forced Preemption (Server)"
	help
	  This is the traditional Linux preemption model, geared towards
	  throughput. It will still provide good latencies most of the
	  time, but there are no guarantees and occasional longer delays
	  are possible.

	  Select this option if you are building a kernel for a server or
	  scientific/computation system, or if you want to maximize the
	  raw processing power of the kernel, irrespective of scheduling
	  latencies.

config PREEMPT_VOLUNTARY
	bool "Voluntary Kernel Preemption (Desktop)"
	depends on !ARCH_NO_PREEMPT
	help
	  This option reduces the latency of the kernel by adding more
	  "explicit preemption points" to the kernel code. These new
	  preemption points have been selected to reduce the maximum
	  latency of rescheduling, providing faster application reactions,
	  at the cost of slightly lower throughput.

	  This allows reaction to interactive events by allowing a
	  low priority process to voluntarily preempt itself even if it
	  is in kernel mode executing a system call. This allows
	  applications to run more 'smoothly' even when the system is
	  under load.

	  Select this if you are building a kernel for a desktop system.

config PREEMPT
	bool "Preemptible Kernel (Low-Latency Desktop)"
	depends on !ARCH_NO_PREEMPT
	select PREEMPTION
	select UNINLINE_SPIN_UNLOCK if !ARCH_INLINE_SPIN_UNLOCK
	select PREEMPT_DYNAMIC if HAVE_PREEMPT_DYNAMIC
	help
	  This option reduces the latency of the kernel by making
	  all kernel code (that is not executing in a critical section)
	  preemptible.  This allows reaction to interactive events by
	  permitting a low priority process to be preempted involuntarily
	  even if it is in kernel mode executing a system call and would
	  otherwise not be about to reach a natural preemption point.
	  This allows applications to run more 'smoothly' even when the
	  system is under load, at the cost of slightly lower throughput
	  and a slight runtime overhead to kernel code.

	  Select this if you are building a kernel for a desktop or
	  embedded system with latency requirements in the milliseconds
	  range.

config PREEMPT_RT
	bool "Fully Preemptible Kernel (Real-Time)"
	depends on EXPERT && ARCH_SUPPORTS_RT
	select PREEMPTION
	help
	  This option turns the kernel into a real-time kernel by replacing
	  various locking primitives (spinlocks, rwlocks, etc.) with
	  preemptible priority-inheritance aware variants, enforcing
	  interrupt threading and introducing mechanisms to break up long
	  non-preemptible sections. This makes the kernel, except for very
	  low level and critical code paths (entry code, scheduler, low
	  level interrupt handling) fully preemptible and brings most
	  execution contexts under scheduler control.

	  Select this if you are building a kernel for systems which
	  require real-time guarantees.

endchoice

config PREEMPT_COUNT
       bool

config PREEMPTION
       bool
       select PREEMPT_COUNT

config PREEMPT_DYNAMIC
	bool
	help
	  This option allows to define the preemption model on the kernel
	  command line parameter and thus override the default preemption
	  model defined during compile time.

	  The feature is primarily interesting for Linux distributions which
	  provide a pre-built kernel binary to reduce the number of kernel
	  flavors they offer while still offering different usecases.

	  The runtime overhead is negligible with HAVE_STATIC_CALL_INLINE enabled
	  but if runtime patching is not available for the specific architecture
	  then the potential overhead should be considered.

	  Interesting if you want the same pre-built kernel should be used for
	  both Server and Desktop workloads.

config SCHED_CORE
	bool "Core Scheduling for SMT"
	depends on SCHED_SMT
	help
	  This option permits Core Scheduling, a means of coordinated task
	  selection across SMT siblings. When enabled -- see
	  prctl(PR_SCHED_CORE) -- task selection ensures that all SMT siblings
	  will execute a task from the same 'core group', forcing idle when no
	  matching task is found.

	  Use of this feature includes:
	   - mitigation of some (not all) SMT side channels;
	   - limiting SMT interference to improve determinism and/or performance.

	  SCHED_CORE is default disabled. When it is enabled and unused,
	  which is the likely usage by Linux distributions, there should
	  be no measurable impact on performance.


修改后内容

# SPDX-License-Identifier: GPL-2.0-only

config HAVE_PREEMPT_LAZY
	bool

config PREEMPT_LAZY
	def_bool y if HAVE_PREEMPT_LAZY && PREEMPT_RT

choice
	prompt "Preemption Model"
	default PREEMPT_NONE

config PREEMPT_NONE
	bool "No Forced Preemption (Server)"
	help
	  This is the traditional Linux preemption model, geared towards
	  throughput. It will still provide good latencies most of the
	  time, but there are no guarantees and occasional longer delays
	  are possible.

	  Select this option if you are building a kernel for a server or
	  scientific/computation system, or if you want to maximize the
	  raw processing power of the kernel, irrespective of scheduling
	  latencies.

config PREEMPT_VOLUNTARY
	bool "Voluntary Kernel Preemption (Desktop)"
	depends on !ARCH_NO_PREEMPT
	help
	  This option reduces the latency of the kernel by adding more
	  "explicit preemption points" to the kernel code. These new
	  preemption points have been selected to reduce the maximum
	  latency of rescheduling, providing faster application reactions,
	  at the cost of slightly lower throughput.

	  This allows reaction to interactive events by allowing a
	  low priority process to voluntarily preempt itself even if it
	  is in kernel mode executing a system call. This allows
	  applications to run more 'smoothly' even when the system is
	  under load.

	  Select this if you are building a kernel for a desktop system.

config PREEMPT
	bool "Preemptible Kernel (Low-Latency Desktop)"
	depends on !ARCH_NO_PREEMPT
	select PREEMPTION
	select UNINLINE_SPIN_UNLOCK if !ARCH_INLINE_SPIN_UNLOCK
	select PREEMPT_DYNAMIC if HAVE_PREEMPT_DYNAMIC
	help
	  This option reduces the latency of the kernel by making
	  all kernel code (that is not executing in a critical section)
	  preemptible.  This allows reaction to interactive events by
	  permitting a low priority process to be preempted involuntarily
	  even if it is in kernel mode executing a system call and would
	  otherwise not be about to reach a natural preemption point.
	  This allows applications to run more 'smoothly' even when the
	  system is under load, at the cost of slightly lower throughput
	  and a slight runtime overhead to kernel code.

	  Select this if you are building a kernel for a desktop or
	  embedded system with latency requirements in the milliseconds
	  range.

config PREEMPT_RT
	bool "Fully Preemptible Kernel (Real-Time)"
	# depends on EXPERT && ARCH_SUPPORTS_RT
	depends on !ARCH_NO_PREEMPT
	select PREEMPTION
	help
	  This option turns the kernel into a real-time kernel by replacing
	  various locking primitives (spinlocks, rwlocks, etc.) with
	  preemptible priority-inheritance aware variants, enforcing
	  interrupt threading and introducing mechanisms to break up long
	  non-preemptible sections. This makes the kernel, except for very
	  low level and critical code paths (entry code, scheduler, low
	  level interrupt handling) fully preemptible and brings most
	  execution contexts under scheduler control.

	  Select this if you are building a kernel for systems which
	  require real-time guarantees.

endchoice

config PREEMPT_COUNT
       bool

config PREEMPTION
       bool
       select PREEMPT_COUNT

config PREEMPT_DYNAMIC
	bool
	help
	  This option allows to define the preemption model on the kernel
	  command line parameter and thus override the default preemption
	  model defined during compile time.

	  The feature is primarily interesting for Linux distributions which
	  provide a pre-built kernel binary to reduce the number of kernel
	  flavors they offer while still offering different usecases.

	  The runtime overhead is negligible with HAVE_STATIC_CALL_INLINE enabled
	  but if runtime patching is not available for the specific architecture
	  then the potential overhead should be considered.

	  Interesting if you want the same pre-built kernel should be used for
	  both Server and Desktop workloads.

config SCHED_CORE
	bool "Core Scheduling for SMT"
	depends on SCHED_SMT
	help
	  This option permits Core Scheduling, a means of coordinated task
	  selection across SMT siblings. When enabled -- see
	  prctl(PR_SCHED_CORE) -- task selection ensures that all SMT siblings
	  will execute a task from the same 'core group', forcing idle when no
	  matching task is found.

	  Use of this feature includes:
	   - mitigation of some (not all) SMT side channels;
	   - limiting SMT interference to improve determinism and/or performance.

	  SCHED_CORE is default disabled. When it is enabled and unused,
	  which is the likely usage by Linux distributions, there should
	  be no measurable impact on performance.


6.4 进入kernel源码目录,并配置

cd ..
make menuconfig # 打开内核选择终端用户界面

“上下键”选择项,“回车”进入,“左右键”选择“Select、Exit、Save、Load”

请添加图片描述

6.4.1 内核配置步骤

请添加图片描述

按“enter”键

按“上”、“下”键选择Preemption Model

请添加图片描述

按“enter”键,按“上”、“下”键,选择Fully Preemptible Kernel (Real-Time)

请添加图片描述

按下“空格键”(表示选中Fully Preemptible Kernel (Real-Time),会直接跳回上级菜单,可以重新进入查看是
否选中)

请添加图片描述

按“上”、“下”键,选择Timers subsystem

请添加图片描述

按“enter”键进入,配置如下图

请添加图片描述

按“左”、“右”键,选择“Exit”,一直退出到如下界面

请添加图片描述

按“上”、“下”键,选择Kernel hacking

请添加图片描述

按“enter”键进入

请添加图片描述

按"上"、“下”键选择Compile-time checks and compiler options并按“enter”进入,配置如下图

请添加图片描述

"Exit"退出到上一级,配置如下图

请添加图片描述

一直“exit”退出配置界面,保存配置按“Yes”

请添加图片描述

6.4.2 修改.config文件

gedit .config # 打开配置文件

在打开的文件中按下Ctrl + F唤起搜索栏,将文件中的如下配置项修改为如下内容

CONFIG_SYSTEM_TRUSTED_KEYS=""
CONFIG_PCIEASPM_POWERSAVE=n
CONFIG_PCIEASPM_PERFORMANCE=y

7 构建-安装

make -j24 ## 编译,j几看电脑配置了,可以在terminal输入nproc查看处理器数目然后乘2
sudo make modules_install -j24
sudo make install -j12 ##安装

8 配置启动项

8.1 更新GRUB配置

更新GRUB启动菜单

sudo grub2-mkconfig -o /1 boot/grub2/grub.cfg

8.2 设置默认启动内核

将新安装的内核设置为默认启动项

sudo grub2-set-default 0

9 重启系统

sudo reboot

10 验证新内核

uname -r
# 5.15.177-rt83

http://www.kler.cn/a/544488.html

相关文章:

  • webpack研究,解决了什么问题
  • 第二十二章 P - R 开头的术语
  • 文心一言与gpt,核心原理对比
  • React源码揭秘 | scheduler 并发更新原理
  • 《五福临门》后期鉴赏(三)
  • C# ASP.NET的发展历程
  • 「软件设计模式」工厂方法模式 vs 抽象工厂模式
  • 操作系统之文件系统
  • Python+selenium基于PO模式的Web自动化测试框架
  • 蓝桥杯之并查集
  • 鸿蒙Harmony打包脚本使用整理
  • 在生成器表达式中调用 tuple() 函数,会返回元组,是因为 tuple() 会消耗整个生成器,将所有元素转换成元组。
  • KubeSphere 和 K8s 高可用集群离线部署全攻略
  • linux内网部署deepseek大模型(ollama+anythingllm)
  • 小程序canvas2d实现横版全屏和竖版逐字的签名组件(字帖式米字格签名组件)
  • 10bit VS 8bit 视频:色彩深度的较量,谁才是视觉盛宴的王者?
  • JS逆向-最新版某音a_bogus
  • C语言之循环结构:直到型循环
  • 【算法学习】DFS与BFS
  • 【prompt示例】智能客服+智能质检业务模版