1,系统版本说明:ARM 鲲鹏920
cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"
2, 将source.list中的deb-src打开
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiversedeb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiversedeb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiversedeb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiversedeb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-security main restricted universe multiversedeb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-security main restricted universe multiversedeb http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiversedeb-src http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiverse# 预发布软件源,不建议启用
# deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse
# # deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse
3, 安装编译所需文件和软件
sudo apt-get update
sudo apt install -y make dpkg dpkg-dev libncurses5-dev libssl-dev libpciaccess0 ncurses-dev flex bison libelf-dev libssl-dev dwarves zstdsudo apt build-dep linux #需要第一步
4, 下载内核源码
//查看系统可获得的内核源码
apt search linux-source
//下载系统源码文件(下载内核版本为4.15.0)
apt install linux-source-4.15.0=4.15.0-88.88
//解压源码
cd /usr/src/linux-source-4.15.0
tar -xjvf linux-source-4.15.0或者: apt install linux-source
5, 编译内核源码
//解压源码
cd /usr/src/linux-source-4.15.0
tar -xjvf linux-source-4.15.0
拷贝/boot/config-xxx ,到当前内核源码中
make menuconfig //直接保存、退出,生成配置文件.config
make -j64 //编译
make modules //编译模块
make modules_install //安装模块
make install //安装内核
cd /boot/grub
sudo update-grub2 //更新启动项
reboot
6,编译出错问题
root@Fish:/usr/src/linux-hwe-5.4-headers-5.4.0-42# make
scripts/kconfig/conf --syncconfig Kconfig
HOSTCC scripts/selinux/genheaders/genheaders
scripts/selinux/genheaders/genheaders.c:18:10: fatal error: classmap.h: No such file or directory
18 | #include "classmap.h"
| ^~~~~~~~~~~~
compilation terminated.
make[3]: *** [scripts/Makefile.host:107: scripts/selinux/genheaders/genheaders] Error 1
make[2]: *** [scripts/Makefile.build:522: scripts/selinux/genheaders] Error 2
make[1]: *** [scripts/Makefile.build:522: scripts/selinux] Error 2
make: *** [Makefile:1131: scripts] Error 2
原因就是因为使用了header的源码,这个源码时不完整的