Building a Kernel Patch
Download URLs
URLs of the kernel source RPM package (for example, kernel-3.10.0-957.el7.src.rpm):
The version of the RPM package of the kernel source code must be the same as the kernel version of the OS.
Official Red Hat website: https://access.redhat.com/downloads/
CentOS website: https://vault.centos.org/7.6.1810/os/Source/SPackages/
Procedure
- Install and decompress the source package.
- Run the following command to install the source package:
rpm -ivh kernel-3.10.0-957.el7.src.rpm
- Run the following command to go to the /root/rpmbuild/SOURCES directory:
cd /root/rpmbuild/SOURCES/
- Run the following commands to decompress the source package:
xz -d linux-3.10.0-957.el7.tar.xz
tar xvf linux-3.10.0-957.el7.tar
- Run the following command to install the source package:
- Modify kernel code.
- Run the following command to go to the /root/rpmbuild/SOURCES/linux-3.10.0-957.el7 directory:
cd /root/rpmbuild/SOURCES/linux-3.10.0-957.el7
- Run the vi command to modify functions in the drivers/firmware/dmi_scan.c and include/linux/dmi.h files. Modify the following content. For details, see https://lore.kernel.org/lkml/1448575344-19107-1-git-send-email-jordan_hargrave@dell.com/#Z30drivers:firmware:dmi_scan.c.
The plus sign (+) in front of a code line indicates that the line is newly added, and the minus sign (-) in front of a code line indicates that the line is deleted.
- Run the following command to go to the /root/rpmbuild/SOURCES/linux-3.10.0-957.el7 directory:
- Compress the kernel code.
- Run the following command to go to the directory where the linux-3.10.0-957.el7 folder is stored:
cd /root/rpmbuild/SOURCES
- Run the following commands to compress the source file:
tar -cf linux-3.10.0-957.el7.tar linux-3.10.0-957.el7
xz -z linux-3.10.0-957.el7.tar
- Delete the source folder.
rm -rf linux-3.10.0-957.el7
- Run the following command to go to the directory where the linux-3.10.0-957.el7 folder is stored:
- Build the source package.
- Run the following command to go to the /root/rpmbuild/SPECS/ directory:
cd ../SPECS/
- Run the following command to build the source package:
rpmbuild -ba kernel.spec
The generated RPM package is stored in the /root/rpmbuild/RPMS/x86_64 directory.
- Run the following command to go to the /root/rpmbuild/SPECS/ directory:
- Uninstall the original kernel RPM package from the OS and install the newly generated kernel RPM package.
- Run the following command to query the original kernel RPM package on the OS:
rpm -qa |grep kernel
See the following figure:
- Run the following command to uninstall the original kernel RPM package on the OS:
rpm -e File_name
See the following figure:
Retain the brt-addon-kerneloops-2.1.11-60.el7.centos.x86_64 file.
- Run the following commands to install the RPM packages compiled in 4, including kernel, kernel-devel, kernel-headers, kernel-tools-libs and kernel-tools.
rpm -Uvh kernel-3.10.0-957.el7.x86_64.rpm
rpm -Uvh kernel-devel-3.10.0-957.el7.x86_64.rpm
rpm -Uvh kernel-headers-3.10.0-957.el7.x86_64.rpm
rpm -Uvh kernel-tools-libs-3.10.0-957.el7.x86_64.rpm
rpm -Uvh kernel-tools-3.10.0-957.el7.x86_64.rpm
See the following figure:
- Run the following command to query the original kernel RPM package on the OS:
Troubleshooting
If an error is reported when the rpmbuild command is run, add the required dependencies.
Error message:
error: Failed build dependencies: xmlto is needed by kernel-3.10.0-957.el7.x86_64 asciidoc is needed by kernel-3.10.0-957.el7.x86_64 hmaccalc is needed by kernel-3.10.0-957.el7.x86_64 pesign >= 0.109-4 is needed by kernel-3.10.0-957.el7.x86_64 elfutils-devel is needed by kernel-3.10.0-957.el7.x86_64 zlib-devel is needed by kernel-3.10.0-957.el7.x86_64 binutils-devel is needed by kernel-3.10.0-957.el7.x86_64 newt-devel is needed by kernel-3.10.0-957.el7.x86_64 python-devel is needed by kernel-3.10.0-957.el7.x86_64 perl(ExtUtils::Embed) is needed by kernel-3.10.0-957.el7.x86_64 audit-libs-devel is needed by kernel-3.10.0-957.el7.x86_64 numactl-devel is needed by kernel-3.10.0-957.el7.x86_64 pciutils-devel is needed by kernel-3.10.0-957.el7.x86_64
Build the following dependencies:
rpm -ivh zlib-devel-1.2.7-13.el7.x86_64.rpm rpm -ivh boost-regex-1.53.0-18.el7.x86_64.rpm rpm -ivh source-highlight-3.1.6-6.el7.x86_64.rpm rpm -ivh asciidoc-8.6.8-5.el7.noarch.rpm rpm -ivh hmaccalc-0.9.13-4.el7.x86_64.rpm rpm -ivh opensc-0.13.0-9.el7.x86_64.rpm rpm -ivh pesign-0.109-6.el7.x86_64.rpm rpm -ivh elfutils-libelf-devel-0.158-3.el7.x86_64.rpm rpm -ivh elfutils-devel-0.158-3.el7.x86_64.rpm rpm -ivh binutils-devel-2.23.52.0.1-16.el7.x86_64.rpm rpm -ivh newt-0.52.15-4.el7.x86_64.rpm rpm -ivh slang-devel-2.2.4-11.el7.x86_64.rpm rpm -ivh newt-devel-0.52.15-4.el7.x86_64.rpm rpm -ivh python-devel-2.7.5-16.el7.x86_64.rpm rpm -ivh perl-ExtUtils-Embed-1.30-283.el7.noarch.rpm rpm -ivh audit-libs-devel-2.3.3-4.el7.x86_64.rpm rpm -ivh numactl-devel-2.0.9-2.el7.x86_64.rpm rpm -ivh pciutils-3.2.1-4.el7.x86_64.rpm rpm -ivh pciutils-devel-3.2.1-4.el7.x86_64.rpm rpm -ivh xmlto-0.0.25-7.el7.x86_64.rpm –nodeps