操作系统内核源码编译
- 查询当前内核的版本号和OS镜像来源。
[root@localhost ~]# uname -a Linux localhost.localdomain 4.14.0-115.el7a.0.1.aarch64 #1 SMP Sun Nov 25 20:54:21 UTC 2018 aarch64 aarch64 aarch64 GNU/Linux [root@localhost ~]# cat /etc/os-release NAME="CentOS Linux" VERSION="7 (AltArch)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (AltArch)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7"
当前操作系统发行厂商为:CentOS-7。内核版本号: 4.14.0-115.el7a.0.1
- 从官方http://vault.centos.org/7.6.1810/os/Source/SPackages/ 下载部分源码rpm包kernel-alt-4.14.0-115.el7a.0.1.src.rpm。
- 编译内核之前,必须安装编译内核基本工具链。如果遇到如下报错:
error: Failed build dependencies: xmlto is needed by kernel-alt-4.14.0-115.el7.0.1.aarch64 asciidoc is needed by kernel-alt-4.14.0-115.el7.0.1.aarch64 newt-devel is needed by kernel-alt-4.14.0-115.el7.0.1.aarch64 pciutils-devel is needed by kernel-alt-4.14.0-115.el7.0.1.aarch64
可以使用如下命令解决:
yum install –y xmlto asciidoc newt-devel pciutils-devel
通常要求的工具链:
sudo yum install rpm-build redhat-rpm-config asciidoc hmaccalc perl-ExtUtils-Embed pesign xmlto sudo yum install audit-libs-devel binutils-devel elfutils-devel elfutils-libelf-devel sudo yum install ncurses-devel newt-devel numactl-devel pciutils-devel python-devel zlib-devel
- 编译之前确保mockbuild用户和mockbuild所属的组有效。
groupadd mockbuild useradd mockbuild -g mockbuild
- 安装rpm包。此rpm包实际为rpmbuild构建工程。
rpm -ivh kernel-alt-4.14.0-115.el7a.0.1.src.rpm
安装完成,rpm构建工程自动部署在以下目录:
/root/rpmbuild/SPECS
/root/rpmbuild/SOURCES
- rpmbuild构建,会自动下载全量内核代码(包括补丁合入)
cd /root/rpmbuild/SPECS rpmbuild -bp --target=$(uname -m) kernel-alt.spec
- 构建完成后,可以获取到全量内核源码,路径为:
cd /root/rpmbuild/BUILD/kernel-alt-4.14.0-115.el7a/linux-4.14.0-115.el7.0.1.aarch64
- 内核编译。
make -j 64
- (可选)安装驱动。
make modules_install
- (可选)安装内核。
make install
- (可选)重启服务器,选择对应的内核。