# apt-cache search linux-source
linux-source - Linux kernel source with Ubuntu patches
linux-source-5.4.0 - Linux kernel source for version 5.4.0 with Ubuntu patches
linux-hwe-5.8-source-5.8.0 - Linux kernel source for version 5.8.0 with Ubuntu patches
# apt install linux-source-5.4.0
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
kernel-package libqt3-dev
The following NEW packages will be installed:
linux-source-5.4.0
0 upgraded, 1 newly installed, 0 to remove and 38 not upgraded.
Need to get 135 MB of archives.
After this operation, 150 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 linux-source-5.4.0 all 5.4.0-52.57 [135 MB]
Fetched 135 MB in 27s (5,015 kB/s)
Selecting previously unselected package linux-source-5.4.0.
(Reading database ... 81402 files and directories currently installed.)
Preparing to unpack .../linux-source-5.4.0_5.4.0-52.57_all.deb ...
Unpacking linux-source-5.4.0 (5.4.0-52.57) ...
Setting up linux-source-5.4.0 (5.4.0-52.57) ...
源码安装至 /usr/src/ 目录下。
$ ls -hl
total 4.0K
drwxr-xr-x 4 root root 4.0K Nov 9 13:22 linux-source-5.4.0
lrwxrwxrwx 1 root root 45 Oct 15 10:28 linux-source-5.4.0.tar.bz2 -> linux-source-5.4.0/linux-source-5.4.0.tar.bz2
$ tar -jxvf linux-source-5.4.0.tar.bz2
$ cd linux-source-5.4.0
$ make scripts # 可选
$ cp -v /boot/config-$(uname -r) .config # make defconfig 或者 make menuconfig
$ make headers_install
$ make M=samples/bpf # 如果配置出错,可以使用 make oldconfig && make prepare 修复
WARNING: Symbol version dump ./Module.symvers
is missing; modules will have no dependencies and modversions.
Building modules, stage 2.
MODPOST 0 modules
/bin/sh: 1: scripts/mod/modpost: not found
make[1]: *** [scripts/Makefile.modpost:94: __modpost] Error 127
make: *** [Makefile:1670: modules] Error 2
可以通过 make scripts 来补全脚本:
$ make scripts
3.3.2 ”asm/x.h” 头文件缺少
./include/linux/spinlock.h:60:10: fatal error: 'asm/mmiowb.h' file not found
#include <asm/mmiowb.h>
^~~~~~~~~~~~~~
1 error generated.
CC samples/bpf/syscall_nrs.s
In file included from ./include/uapi/linux/unistd.h:8,
from samples/bpf/syscall_nrs.c:2:
./arch/x86/include/asm/unistd.h:19:12: fatal error: asm/unistd_64_x32.h: No such file or directory
19 | # include <asm/unistd_64_x32.h>
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[1]: *** [scripts/Makefile.build:99: samples/bpf/syscall_nrs.s] Error 1
make: *** [Makefile:1757: samples/bpf] Error 2
linux-headers-5.4.0-52 Header files related to Linux kernel version 5.4.0
linux-headers-5.4.0-52-generic Linux kernel headers for version 5.4.0 on x86/x86_64