Unbuntu16.04 安装实时内核之RT-PREEMP补丁

Unbuntu16.04 安装实时内核:

搭建前置条件:Linux系统Ubuntu16.04 (可根据自身使用环境选择ubuntu版本,安装步骤都几乎一致)

  • 下载内核与内核对应的rt-preempt补丁(内核补丁需要和内核版本对应,安装时一定要注意)

下载自己想要的版本,本文以Linux-4.18.16.tar.gz为例子

内核下载路径:https://mirrors.edge.kernel.org/pub/linux/kernel/v4.x/

版本:patch-4.18.16.rt9.patch.gz

preempt补丁下载:https://mirrors.edge.kernel.org/pub/linux/kernel/projects/rt/4.18/

  • 安装内核编译必备工具

cd ~/

sudo apt-get build-dep linux

//可能缺少目标源url,可通过修改源文件添加url源

sudo vim /etc/apt/sources.list

​
deb-src http://archive.ubuntu.com/ubuntu trusty main restricted

#Added by software-properties

deb-src http://gb.archive.ubuntu.com/ubuntu/ trusty restricted main universe multiverse

#Added by software-properties

deb-src http://gb.archive.ubuntu.com/ubuntu/ trusty-updates restricted main universe multiverse

#Added by software-properties

deb-src http://gb.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse

#Added by software-properties

deb-src http://security.ubuntu.com/ubuntu trusty-security restricted main universe multiverse

#Added by software-properties

deb-src http://gb.archive.ubuntu.com/ubuntu/ trusty-proposed restricted main universe multiverse

#Added by software-properties

​

添加以上内容即可

sudo apt-get install libncurses-dev flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf fakeroot

sudo apt-get install kernel-package

  • 创建编译内核工作路径并打补丁

cd ~/

mkdir ./kernel

cd ./kernel //同时拷贝内核版本与补丁到该路径

tar -zxvf Linux-4.18.16.tar.gz

gunzip patch-4.18.16.rt9.patch.gz

cd Linux-4.18.16

pacth -p1 < ../patch-4.18.16.rt9.patch
  • 编译内核

    • 保留原始 .config

      yes '' | make oldconfig /

    • 修改编译配置

make menuconfig

(1) Enable CONFIG_PREEMPT_RT //使能实时操作系统

-> Processor type and features

-> Preemption Model (Fully Preemptible Kernel (Real-Time))

(X) Fully Preemptible Kernel (Real-Time)

(2) Enable CONFIG_HIGH_RES_TIMERS //使能高精度定时器

-> General setup

-> Timers subsystem

[*] High Resolution Timer Support

(3) Enable CONFIG_NO_HZ_FULL //忽略在空闲或只有一个可运行任务的CPU上调度时钟信号

-> General setup

-> Timers subsystem

-> Timer tick handling (Full dynticks system (tickless))

(X) Full dynticks system (tickless)

(4) Set CONFIG_HZ_1000 //设置时钟频率

-> Processor type and features

-> Timer frequency (1000 HZ)

(X) 1000 HZ

(5) Set CPU_FREQ_DEFAULT_GOV_PERFORMANCE [=y]

-> Power management and ACPI options

-> CPU Frequency scaling

-> CPU Frequency scaling (CPU_FREQ [=y])

-> Default CPUFreq governor ( [=y])

(X) performance

保存配置并退出menuconfig

  • 编译内核deb安装包(方式一)
sudo make-kpkg -j `nproc` --initrd kernel_image kernel_headers

//根据自身系统CPU 核数决定编译速度(20min-60min左右)

编译完成后在上级目录生成2个deb文件

  • 安装实时内核
cd ../

sudo dpkg -i *.deb

sudo update-grub
  • 直接编译并更新内核(方式二)

make -j `nproc`

make modules_install -j `nproc`

make install

update-grub
  • 重启PC(启动时高级选项中选择Linux-4.18.16

reboot

查看实时内核

uname -a //有以下关键配置说明代表成功

    ... SMP PREEMPT Sat Feb ...

 

你可能感兴趣的:(Linux研究篇,linux,ubuntu)