1.内核编译
##安装包准备 github https://github.com/chromiumer/ops-files/releases/tag/v1.0
gmp-6.1.0.tar.bz2
mpfr-3.1.6.tar.bz2
mpc-1.0.3.tar.gz
gcc-11.2.0.tar.gz
linux-5.15.4.tar.xz
##1.1 gmp-6.1.0.tar.bz2
tar -xvf gmp-6.1.0.tar.bz2; cd gmp-6.1.0
./configure --prefix=/usr/local/gmp-6.1.0
make && make install
##1.2 mpfr-3.1.6.tar.bz2
tar -xvf mpfr-3.1.6.tar.bz2; cd mpfr-3.1.6
./configure --prefix=/usr/local/mpfr-3.1.6 --with-gmp=/usr/local/gmp-6.1.0
make && make install
##1.3 mpc-1.0.3.tar.gz
tar -xvf mpc-1.0.3.tar.gz; cd mpc-1.0.3
./configure --prefix=/usr/local/mpc-1.0.3 --with-gmp=/usr/local/gmp-6.1.0 --with-mpfr=/usr/local/mpfr-3.1.6
make && make install
##1.4 gcc-11.2.0.tar.gz mirror sites https://www.gnu.org/software/gcc/mirrors.html
tar -xvf gcc-11.2.0.tar.gz; cd gcc-11.2.0
./configure --with-gmp=/usr/local/gmp-6.1.0 --with-mpfr=/usr/local/mpfr-3.1.6 --with-mpc=/usr/local/mpc-1.0.3 --disable-multilib
make && make install
##1.5 linux-5.15.4.tar.xz 使用原有配置模板 .config
tar -xvf linux-5.15.4.tar.xz -C /usr/local/src/
cd /usr/local/src/linux-5.15.4
cp /boot/config-3.10.0-1160.45.1.el7.x86_64 .config
##1.6 内核编译 待完善
make menuconfig
General setup ---> Local version - append to kernel release ---> -2022.03.09.by.007
make -j 8 ## 4c8g 耗时2.56小时
make modules_install ##copy to /lib/modules 耗时5分钟
make install
##1.7 设置新内核启动
cat /boot/grub2/grub.cfg |grep ^menuentry
grub2-set-default 'CentOS Linux (5.15.4-20211122.by.007) 7 (Core)'
#或
grub2-set-default 0 #0表示 /boot/grub2/grub.cfg 文件中排在第一位的 menuentry 段
grub2-editenv list
##1.8重新生成grub2配置文件
grub2-mkconfig -o /boot/grub2/grub.cfg
grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
reboot
2.生成rpm包
##生成rpm内核文件包
cd /usr/local/src/linux-5.15.4
make -j 8 rpm-pkg
##删除debug信息,减少包大小 约3小时
make -j 8 INSTALL_MOD_STRIP=1 rpm-pkg
209M Nov 23 13:21 /root/rpmbuild/RPMS/x86_64/kernel-5.15.4_20211122.by.007-2.x86_64.rpm
161M Nov 23 13:25 /root/rpmbuild/RPMS/x86_64/kernel-devel-5.15.4_20211122.by.007-2.x86_64.rpm
1.4M Nov 23 13:21 /root/rpmbuild/RPMS/x86_64/kernel-headers-5.15.4_20211122.by.007-2.x86_64.rpm
##主机升级内核
yum localinstall kernel-*
3.空间优化(/boot)
##2.1删除旧内核
rpm -qa| grep kernel| grep -v -E "tools|devel|headers"|sort -n
rpm -e kernel-3.10.0-1160.42.2.el7.x86_64
##2.2 /lib/modules目录清理
43M /lib/modules/3.10.0-1160.45.1.el7.x86_64
3.1G /lib/modules/5.15.4-20211122.by.007