采用 make-kpkg 方法编译内核image 和 header 文件。
在 Ampere ARM 服务器、 调整PCIe RC驱动相关代码、和AMDGPU 驱动相关内容,为生产部署便捷,
给运维组同事直接提供内核头文件.deb 和 kernel.deb 安装包,本篇记录使用 make-kpkg 过程。
1>. 安装 kernel-package 工具
ARM服务器使用 ubuntu 20 服务版系统,安装必要编译环境依赖包。
sudo apt-get install kernel-package build-essential libncurses5-dev libncurses-dev
sudo apt-get install gcc make bison flex libssl-dev
2>. 下载内核源码
使用下面国内镜像地址下载对应本版的内核.
https://mirror.bjtu.edu.cn/kernel/linux/kernel/
3>. 配置内核
使用目标主机默认版本的 config 文件作为基础,在根据研发需求修订自己内容,进入内核源码文件夹下,
cp /boot/config-5.4.0-162-generic ./.config
make menuconfig
3.1>. 创建编译内核模块使用的build目录:
如果/lib/modules/$(uname -r)/没有build目录,是无法编译内核模块的,需要手动创建链接文件:
sudo ln -s /usr/src/linux-headers-$(uname -r)/ /lib/modules/$(uname -r)/build
4>. 编译内核和头文件
帮助说明
make-kpkg --help
usage: make-kpkg [options] target [target ...]
where options are:
--help This message.
--revision number The debian revision number. ([0-9][a-zA-Z.~+0-9]) (Must
start with a digit)
--append-to-version foo
--append_to_version foo an additional kernel sub-version. ([-a-z.+0-9])
Does not require editing the kernel Makefile
over rides env var APPEND_TO_VERSION.
requires a make-kpkg clean
--added-modules foo
--added_modules foo Comma/space separated list of add on modules
affected by the modules_<blah> targets
--arch foo architecture
--cross-compile
--cross_compile target string
--subarch bar Set the subarch for the image being compiled
(have to be on a compatible machine).
--arch-in-name
--arch_in_name Embed the subarch in the image package name
--stem foo Call the packages foo-* instead of kernel-*
--initrd Create a image package suitable for initrd.
-j jobs Sec CONCURRENCY_LEVEL to -I<jobs> for this action.
--jobs jobs Set CONCURRENCY_LEVEL to -I<jobs> for this action.
--pgpsign name An ID used to sign the changes file using pgp.
--config target Change the type of configure done from the default
oldconfig.
--targets Lists the known targets.
--noexec Pass a -n option to the make process
--overlay dir An overlay directory to (re))place file in ./debian
--verbose Pass a V=1 option to the make process
--uimage Create a kernel using uImage rather than zImage
or bzImage
--rootcmd method A command that provides a means of gaining
superuser access (for example, `sudo' or
`fakeroot') as needed by dpkg-buildpackages'
-r option. Does not work for targets binary,
binary-indep, and binary-arch.
--us This option is passed to dpkg-buildpackage, and
directs that package not to sign the
source. This is only relevant for the
buildpackage target.
--uc This option is passed to dpkg-buildpackage, and
directs that package not to sign the
changelog. This is only relevant for the
buildpackage target.
4.1> 编译命令
sudo make-kpkg --initrd --append-to-version -sunway-230809 --revision 001 kernel_image modules_image kernel_headers -j 40
解决错误
At main.c:158:
- SSL error:02001002:system library:fopen:No such file or directory: bss_file.c:175
- SSL error:2006D080:BIO routines:BIO_new_file:no such file: bss_file.c:178 sign-file: certs/signing_key.pem: No such file or directory
DEPMOD 4.10.0-20-generic
步骤1.建立x509.genkey文件,内容如下:
[ req ]
default_bits = 4096
distinguished_name = req_distinguished_name
prompt = no
string_mask = utf8only
x509_extensions = myexts
[ req_distinguished_name ]
CN = Modules
[ myexts ]
basicConstraints=critical,CA:FALSE
keyUsage=digitalSignature
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid
步骤2 执行:
openssl req -new -nodes -utf8 -sha512 -days 36500 -batch -x509 -config x509.genkey -outform DER -out signing_key.x509 -keyout signing_key.pem
会生成signing_key.pem signing_key.x509 文件
步骤3:移动到指定的位置
mv signing_key.pem signing_key.x509 `find /usr/src/*-generic/certs`
4.2> 编译结果
:~/Data/ljb/linux-5.11.22$ ls -l ../
total 188356
drwxrwxr-x 25 yuxun yuxun 4096 Sep 22 19:12 linux-5.11.22
-rw-rw-r-- 1 yuxun yuxun 117681288 Sep 19 19:55 linux-5.11.22.tar.xz
-rw-r--r-- 1 root root 10634416 Sep 22 19:14 linux-headers-5.11.22-sw-230922_01_arm64.deb
-rw-r--r-- 1 root root 64547652 Sep 22 19:12 linux-image-5.11.22-sw-230922_01_arm64.deb
5>. 安装内核和头文件
编译后的内核头文件和镜像,可以在需要升级的目标平台进行内核升级
sudo dpkg -i linux-headers-6.2.0-sunway-230808_002_arm64.deb linux-image-6.2.0-sunway-230808_002_arm64.deb
至此、制作定制版本的内核系统、就完成了。