CentOS-Stream 9更换RT实时内核

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
CentOS-9-Stream.repo 是一个用于配置 CentOS Stream 9 软件仓库的配置文件。它通常位于 `/etc/yum.repos.d/` 目录下。这个文件包含了软件仓库的基本信息,如仓库名称、基础URL、是否启用、是否使用GPG密钥等。 以下是一个典型的 CentOS-9-Stream.repo 配置文件的示例: ```ini [centos-stream-9-baseos] name=CentOS Stream 9 - BaseOS #baseurl=http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/ metalink=https://mirrors.centos.org/metalink?repo=centos-stream-9-baseos&arch=$basearch enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial repo_gpgcheck=0 metadata_expire=7d includepkgs= exclude= [centos-stream-9-appstream] name=CentOS Stream 9 - AppStream #baseurl=http://mirror.centos.org/$contentdir/$releasever/AppStream/$basearch/os/ metalink=https://mirrors.centos.org/metalink?repo=centos-stream-9-appstream&arch=$basearch enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial repo_gpgcheck=0 metadata_expire=7d includepkgs= exclude= ``` 在这个配置文件中: 1. `[centos-stream-9-baseos]` 和 `[centos-stream-9-appstream]` 是软件仓库的标识符。 2. `name` 字段描述了软件仓库的名称。 3. `baseurl` 字段是软件仓库的基础URL,但在这个示例中使用了 `metalink` 字段来自动选择最佳的镜像站点。 4. `enabled` 字段表示是否启用该软件仓库。 5. `gpgcheck` 字段表示是否启用GPG签名检查。 6. `gpgkey` 字段指定了GPG密钥的位置。 7. `repo_gpgcheck` 字段表示是否对仓库元数据进行GPG签名检查。 8. `metadata_expire` 字段表示元数据的过期时间。 9. `includepkgs` 和 `exclude` 字段用于包含或排除特定的软件包。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DA0221

各位看官您往里面瞧一瞧看一看

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值