Centos7 makes rpm package through kernel source code

Install the software required for compilation

yum install asciidoc audit-libs-devel bash bc binutils binutils-devel bison diffutils elfutils
yum install elfutils-devel elfutils-libelf-devel findutils flex gawk gcc gettext gzip hmaccalc hostname java-devel
yum install m4 make module-init-tools ncurses-devel net-tools newt-devel numactl-devel openssl
yum install patch pciutils-devel perl perl-ExtUtils-Embed pesign python-devel python-docutils redhat-rpm-config
yum install rpm-build sh-utils tar xmlto xz zlib-devel
yum groupinstall "Development Tools"

Create a normal user

useradd ker
passwd ker
su - ker

Need to ensure that there is more than 10G of space in the home directory

Create the required directory for rpm

mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
echo '%_topdir %(echo $HOME)/rpmbuild' > ~/.rpmmacros

Install kernel source code components

Find the source code components of the kernel from these places:

Take kernel-3.10.0-1160 as an example:

rpm -i http://vault.centos.org/7.9.2009/updates/Source/SPackages/kernel-3.10.0-1160.11.1.el7.src.rpm 2>&1 | grep -v exist

Unzip the source code and generate the source code

cd ~/rpmbuild/SPECS
rpmbuild -bp --target=$(uname -m) kernel.spec

Set up the kernel

cd ~/rpmbuild/BUILD/kernel-*/linux-*/
cp configs/kernel-3.10.0-`uname -m`.config .config
或
cp /boot/config-`uname -r` .config

First execute make oldconfig. Now you should execute make menuconfig, make gconfig or make xconfig to customize the kernel settings. When you are done, remember to save your changes.

  • Add the uname -ioutput parameters to the first line of the .config file
sed -i "1i# `uname -i`" .config
  • Now copy the .config file back into the configs/ directory. This is basically just the opposite of the previous copy instruction:
cp .config configs/kernel-3.10.0-`uname -m`.config
  • The last step is to copy everything in the configs/ directory to the ~/rpmbuild/SOURCES/ directory:
cp configs/* ~/rpmbuild/SOURCES

Change the kernel's spec file

cd ~/rpmbuild/SPECS
cp kernel.spec kernel.spec.bak
vi kernel.spec

In line 8, the definition of buildid was originally a comment.
It must be uncommented and assigned a value to avoid conflict with the kernel you currently have installed. This changes the line to look like the following:

%define buildid .xxx

Replace xxx with custom content

Compile the new kernel

cd ~/rpmbuild/SPECS
rpmbuild -bb --target=`uname -m` --without kabichk kernel.spec
或者后台编译
rpmbuild -bb --target=`uname -m` --without kabichk kernel.spec 2> build-err.log | tee build-out.log

You can add some useful options to the rpmbuild command through --with and/or --without these options and related parameters. The main options worth noting include:

--with baseonly
--without up
--without debug
--without debuginfo
--without kabichk

For example, to create only basic kernel components, use:

--with baseonly --without debug --without debuginfo

Install the new kernel

cd ~/rpmbuild/RPMS/`uname -m`/
yum localinstall kernel-*.rpm
或
rpm -ivh kernel-*.rpm

Set to boot the kernel by default

cat /boot/grub2/grub.cfg | grep menuentry
grub2-editenv list
grub2-set-default ''CentOS Linux (3.10.0-1160.el7.local.x86_64) 7 (Core)''
grub2-editenv list
reboot
---
uname -r
3.10.0-1160.el7.local.x86_64

After the attention is grub2-set-defaultset, cat /boot/grub2/grub.cfg | grep menuentrythe boot-up items that are filtered out are set

Guess you like

Origin blog.csdn.net/qq_33235529/article/details/114979560