操作系统:CentOS Linux 7 (Core)
内核版本:3.10.0-1160.el7.x86_64
目标版本:5.10
gcc版本:8.5.0
本次升级内核版本的目的是开启BTF,支持Grafana Beyla的功能使用。
下载软件包
wget "https://mirrors.aliyun.com/linux-kernel/v5.x/linux-5.10.tar.gz"
wget "https://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-8.5.0/gcc-8.5.0.tar.gz"
安装依赖
yum -y install python3 glibc-devel.x86_64 libelf-dev, libelf-devel or elfutils-libelf-devel openssl-devel gmp-devel.x86_64 libmpc-devel.x86_64 mpfr-devel.x86_64 mpfr.x86_64 bison build-essential flex make automake gcc gcc-c++ kernel-devel glibc*.i686 libgcc*.i686 texi2html texinfo*
编译安装gcc
tar -xzf gcc-8.5.0.tar.gz
cd gcc-8.5.0
# 仅支持64位 --disable-multilib
./configure --prefix=/usr/local/gcc-8.5.0 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++
mkae -j 6 && make install
# 配置环境变量
cat > /etc/profile <<EOF
export PATH=/usr/local/gcc-8.5.0/bin:$PATH
EOF
gcc -v
编译安装pahole
yum install -y rpm-build cmake elfutils-devel
wget "ftp://ftp.icm.edu.pl/vol/rzm7/linux-centos-vault/8.3.2011/PowerTools/Source/SPackages/dwarves-1.17-1.el8.src.rpm"
rpmbuild --rebuild dwarves-1.17-1.el8.src.rp
# ---------------------------- 忽略下面报错-----------------------------------------
+ %ldconfig_scriptlets -n libdwarves1
/var/tmp/rpm-tmp.FUC7o5: line 37: fg: no job control
error: Bad exit status from /var/tmp/rpm-tmp.FUC7o5 (%install)
RPM build errors:
dwarves-1.17-1.el8.src.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
user mockbuild does not exist - using root
group mockbuild does not exist - using root
user mockbuild does not exist - using root
group mockbuild does not exist - using root
Bad exit status from /var/tmp/rpm-tmp.FUC7o5 (%install)
# ---------------------------- 忽略上述报错-----------------------------------------
cd /root/rpmbuild/BUILD
make -j 6 && make install
pahole --version
编译安装linux内核
tar -xzf linux-5.10.tar.gz
cd linux-5.10
# 拷贝当前的内核配置
cp /boot/config-3.10.0-862.el7.x86_64 .config
# 启用BTF
vi .config
CONFIG_DEBUG_INFO_BTF=y
# 注释
vi Makefile
#KBUILD_CFLAGS += -Werror=date-time
# 编译安装pahole,参考问题处理
# 编译
make -j 6
make modules_install install
启用升级后的内核
# 查看启动顺序
awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg
CentOS Linux (5.10.0) 7 (Core)
CentOS Linux (3.10.0-1160.el7.x86_64) 7 (Core)
CentOS Linux (0-rescue-a6900084d04d42bf987ee870cef93d98) 7 (Core)
# 设置启动顺序
grub2-set-default 0
# 重启服务器后生效
reboot
最后确认下BTF
# 查看文件是否存在
ls /sys/kernel/btf/vmlinux
问题处理
gcc版本
gcc版本低造成编译失败,如下报错,解决方法是编译安装gcc8
You are building kernel with non-retpoline compiler.
WRAP arch/x86/include/generated/uapi/asm/ioctl.h
Please update your compiler.
make[1]: *** [checkbin] Error 1
pahole不可用
没有可用的pahole造成编译失败,如下报错
BTF: .tmp_vmlinux.btf: pahole (pahole) is not available
Failed to generate BTF for vmlinux
Try to disable CONFIG_DEBUG_INFO_BTF
make[1]: *** [vmlinux] Error 1
make: *** [__sub-make] Error 2
解决方法是安装dwarves
yum -y install dwarves
yum安装版本低还是编译失败
BTF: .tmp_vmlinux.btf: pahole version v1.9 is too old, need at least v1.16
Failed to generate BTF for vmlinux
Try to disable CONFIG_DEBUG_INFO_BTF
make[1]: *** [vmlinux] Error 1
make: *** [__sub-make] Error 2
编译安装dwarves v1.17
下载站点:RPM Search dwarves
yum install -y rpm-build cmake elfutils-devel
wget "ftp://ftp.icm.edu.pl/vol/rzm7/linux-centos-vault/8.3.2011/PowerTools/Source/SPackages/dwarves-1.17-1.el8.src.rpm"
rpmbuild --rebuild dwarves-1.17-1.el8.src.rp
# ---------------------------- 忽略下面报错-----------------------------------------
+ %ldconfig_scriptlets -n libdwarves1
/var/tmp/rpm-tmp.FUC7o5: line 37: fg: no job control
error: Bad exit status from /var/tmp/rpm-tmp.FUC7o5 (%install)
RPM build errors:
dwarves-1.17-1.el8.src.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
user mockbuild does not exist - using root
group mockbuild does not exist - using root
user mockbuild does not exist - using root
group mockbuild does not exist - using root
Bad exit status from /var/tmp/rpm-tmp.FUC7o5 (%install)
# ---------------------------- 忽略上述报错-----------------------------------------
cd /root/rpmbuild/BUILD
make -j 6 && make install
pahole --version