kernel---ubuntu编译内核

龙晟睿
2023-12-01

编译环境
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04

编译内核版本
linux-4.19.10.tar.gz

编译过程
第一步:解压内核
第二步:执行下面三个命令

sudo make mrproper
mrproper为清除编译过程中产生的所有中间文件

sudo make clean
clean为清除上一次产生的编译中间文件

sudo make menuconfig
在menuconfig中出现选择的图形化界面后,直接按右方向键选择到exit退出,退出提示中选择保存,实现内核的默认配置

第三步:执行configure
./configure --disable-mutile

第四步:编译
sudu make

编译时遇到下列错误
错误1

  • Unable to find the ncurses package.
  • Install ncurses (ncurses-devel or libncurses-dev
  • depending on your distribution)

解决方法:
sudo apt-get install ncurses-dev

错误2
UPD scripts/kconfig/.mconf-cfg
HOSTCC scripts/kconfig/mconf.o
YACC scripts/kconfig/zconf.tab.c
/bin/sh: 1: bison: not found
make[1]: *** [scripts/Makefile.lib:196:scripts/kconfig/zconf.tab.c] 错误 127
make: *** [Makefile:539:menuconfig] 错误 2

解决方法:
sudo apt install bison

错误3
YACC scripts/kconfig/zconf.tab.c
LEX scripts/kconfig/zconf.lex.c
/bin/sh: 1: flex: not found
make[1]: *** [scripts/Makefile.lib:188:scripts/kconfig/zconf.lex.c] 错误 127
make: *** [Makefile:539:menuconfig] 错误 2
解决方法:
sudo apt install flex

错误4
scripts/sign-file.c:25:10: fatal error: openssl/opensslv.h: 没有那个文件或目录
25 | #include <openssl/opensslv.h>
| ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[1]: *** [scripts/Makefile.host:90:scripts/sign-file] 错误 1
make: *** [Makefile:1067:scripts] 错误 2

解决方法:
sudo apt-get install libssl-dev

解决上面4个错误可以执行下面四句
sudo apt-get install libncurses5-dev libssl-dev
sudo apt-get install build-essential openssl
sudo apt-get install zlibc minizip
sudo apt-get install libidn11-dev libidn11

错误5
/include/linux/sched.h: In function ‘rseq_preempt’:
./include/linux/sched.h:1824:1: error: ‘-mindirect-branch’ and ‘-fcf-protection’ are not compatible
1824 | {
| ^
./include/linux/sched.h: In function ‘rseq_migrate’:
./include/linux/sched.h:1831:1: error: ‘-mindirect-branch’ and ‘-fcf-protection’ are not compatible
1831 | {
| ^
./include/linux/sched.h: In function ‘rseq_fork’:
./include/linux/sched.h:1841:1: error: ‘-mindirect-branch’ and ‘-fcf-protection’ are not compatible
1841 | {
| ^
./include/linux/sched.h: In function ‘rseq_execve’:
./include/linux/sched.h:1856:1: error: ‘-mindirect-branch’ and ‘-fcf-protection’ are not compatible
1856 | {
| ^
./include/linux/sched.h: In function ‘rseq_syscall’:
./include/linux/sched.h:1898:1: error: ‘-mindirect-branch’ and ‘-fcf-protection’ are not compatible
1898 | {
分析这个问题,原因当前环境gcc版本是9.0,9.0的gcc在编译内核时bug,参考
https://bugs.launchpad.net/ubuntu/+source/gcc-9/+bug/1830961

ubuntu切换为8.4 gcc,切换方法如下:
1)将ubuntu-toolchain-r/test PPA添加到您的系统
sudo apt install software-properties-common

错误6
CC kernel/memremap.o
CC kernel/rseq.o
AR kernel/built-in.a
make[1]: *** 没有规则可制作目标“debian/canonical-certs.pem”,由“certs/x509_certificate_list” 需求。 停止。
make: *** [Makefile:1052:certs] 错误 2

解决方法:
sudo vim .config
把CONFIG_SYSTEM_TRUSTED_KEYS=“debian/canonical-certs.pem”,修改为CONFIG_SYSTEM_TRUSTED_KEYS=""

2)安装所需的GCC和G ++版本
sudo apt install gcc-8 g+±8

3)设置gcc8为优先
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 80 --slave /usr/bin/g++ g++ /usr/bin/g+±8

最后再次执行sudo make即可

 类似资料: