我一直在尝试编译自己的内核,在按照BuildYourOwnKernel的说明进行操作时,添加本地版本修饰符时遇到了困难。这是使用 编译内核的“Debian 方式”,fakefoot debian/rules binary-generic
而不是使用 从主线编译make bindeb-pkg
。
按照说明操作后,我实际上成功编译了内核。但是,+test1
我作为本地版本修饰符添加的后缀仅添加到.deb
存档文件中,而不会添加到任何二进制包中。因此,我在安装过程中遇到冲突,因为名称与当前安装的内核匹配。
我正在使用 Ubuntu 22.04 Server。
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.4 LTS
Release: 22.04
Codename: jammy
当前内核:
$ uname -r
5.15.0-113-generic
以下是我遵循的步骤:
1.安装依赖项
sudo apt build-dep linux linux-image-unsigned-$(uname -r)
sudo apt install fakeroot crash kexec-tools kernel-wedge libncurses5 libncurses5-dev binutils-dev
2.下载源码
apt source linux-image-unsigned-$(uname -r)
3. 进入源目录
cd linux-5.15.0
4.修改debian.master/changelog
按照说明:
为了使您的内核比您基于的 Ubuntu 内核“更新”,您应该添加本地版本修饰符。在构建之前,在 debian.master/changelog 文件中的第一个版本号末尾添加类似“+test1”的内容。
+test1
因此,我在第一个版本号末尾添加了以下内容:
$ head -n1 debian.master/changelog
linux (5.15.0-113.123+test1) jammy; urgency=medium
5. 构建内核
fakeroot debian/rules clean
fakeroot debian/rules binary-headers binary-generic
编译完成后你会看到+test1
所有文件都添加了后缀.deb
:
$ tree -L 1 /home/mike
/home/mike
├── linux-5.15.0
├── linux_5.15.0-113.123.diff.gz
├── linux_5.15.0-113.123.dsc
├── linux_5.15.0.orig.tar.gz
├── linux-buildinfo-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb
├── linux-cloud-tools-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb
├── linux-headers-5.15.0-113_5.15.0-113.123+test1_all.deb
├── linux-headers-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb
├── linux-image-unsigned-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb
├── linux-modules-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb
├── linux-modules-extra-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb
├── linux-modules-iwlwifi-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb
└── linux-tools-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb
但问题是+test1
该文件内的任何文件都没有添加后缀.deb
,因此在安装内核时会发生冲突。
$ sudo dpkg -i linux-image-unsigned-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb
dpkg: regarding linux-image-unsigned-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb containing linux-image-unsigned-5.15.0-113-generic:
linux-image-unsigned-5.15.0-113-generic conflicts with linux-image-5.15.0-113-generic
linux-image-5.15.0-113-generic (version 5.15.0-113.123) is present and installed.
dpkg: error processing archive linux-image-unsigned-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb (--install):
conflicting packages - not installing linux-image-unsigned-5.15.0-113-generic
Errors were encountered while processing:
linux-image-unsigned-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb
但是,标题已安装:
$ sudo dpkg -i linux-headers-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb
(Reading database ... 138403 files and directories currently installed.)
Preparing to unpack linux-headers-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb ...
Unpacking linux-headers-5.15.0-113-generic (5.15.0-113.123+test1) over (5.15.0-113.123+test1) ...
Setting up linux-headers-5.15.0-113-generic (5.15.0-113.123+test1) ...
/etc/kernel/header_postinst.d/dkms:
* dkms: running auto installation service for kernel 5.15.0-113-generic
...done.
但请注意,没有目录包含本地版本后缀+test
。它似乎只是覆盖了现有的标题。
$ tree -L 1 /usr/src
/usr/src
├── linux-headers-5.15.0-113-generic
└── python3.10
以下是内容的片段linux-headers-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb
:
$ dpkg -c linux-headers-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb | head -n20
drwxr-xr-x root/root 0 2024-07-07 16:31 ./
drwxr-xr-x root/root 0 2024-07-07 16:27 ./lib/
drwxr-xr-x root/root 0 2024-07-07 16:27 ./lib/modules/
drwxr-xr-x root/root 0 2024-07-07 16:27 ./lib/modules/5.15.0-113-generic/
drwxr-xr-x root/root 0 2024-07-07 16:31 ./usr/
drwxr-xr-x root/root 0 2024-07-07 16:31 ./usr/share/
drwxr-xr-x root/root 0 2024-07-07 16:31 ./usr/share/doc/
drwxr-xr-x root/root 0 2024-07-07 16:31 ./usr/share/doc/linux-headers-5.15.0-113-generic/
-rw-r--r-- root/root 714273 2024-07-07 15:58 ./usr/share/doc/linux-headers-5.15.0-113-generic/changelog.Debian.gz
-rw-r--r-- root/root 1292 2024-07-07 15:58 ./usr/share/doc/linux-headers-5.15.0-113-generic/copyright
drwxr-xr-x root/root 0 2024-07-07 16:27 ./usr/src/
drwxr-xr-x root/root 0 2024-07-07 16:27 ./usr/src/linux-headers-5.15.0-113-generic/
-rw-r--r-- root/root 261963 2024-07-07 16:27 ./usr/src/linux-headers-5.15.0-113-generic/.config
-rw-r--r-- root/root 39 2024-07-07 16:27 ./usr/src/linux-headers-5.15.0-113-generic/.gitignore
-rw-r--r-- root/root 1013 2024-07-07 16:27 ./usr/src/linux-headers-5.15.0-113-generic/.missing-syscalls.d
-rw-r--r-- root/root 1818060 2024-07-07 16:27 ./usr/src/linux-headers-5.15.0-113-generic/Module.symvers
drwxr-xr-x root/root 0 2024-07-07 16:27 ./usr/src/linux-headers-5.15.0-113-generic/arch/
drwxr-xr-x root/root 0 2024-07-07 16:27 ./usr/src/linux-headers-5.15.0-113-generic/arch/x86/
drwxr-xr-x root/root 0 2024-07-07 16:27 ./usr/src/linux-headers-5.15.0-113-generic/arch/x86/entry/
drwxr-xr-x root/root 0 2024-07-07 16:27 ./usr/src/linux-headers-5.15.0-113-generic/arch/x86/entry/syscalls/
以下是内容linux-image-unsigned-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb
:
$ dpkg -c linux-image-unsigned-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb
drwxr-xr-x root/root 0 2024-07-07 16:29 ./
drwxr-xr-x root/root 0 2024-07-07 16:26 ./boot/
-rw------- root/root 11680480 2024-07-07 16:26 ./boot/vmlinuz-5.15.0-113-generic
drwxr-xr-x root/root 0 2024-07-07 16:29 ./usr/
drwxr-xr-x root/root 0 2024-07-07 16:27 ./usr/lib/
drwxr-xr-x root/root 0 2024-07-07 16:27 ./usr/lib/linux/
drwxr-xr-x root/root 0 2024-07-07 16:27 ./usr/lib/linux/triggers/
drwxr-xr-x root/root 0 2024-07-07 16:29 ./usr/share/
drwxr-xr-x root/root 0 2024-07-07 16:29 ./usr/share/doc/
drwxr-xr-x root/root 0 2024-07-07 16:29 ./usr/share/doc/linux-image-unsigned-5.15.0-113-generic/
-rw-r--r-- root/root 714273 2024-07-07 15:58 ./usr/share/doc/linux-image-unsigned-5.15.0-113-generic/changelog.Debian.gz
-rw-r--r-- root/root 1292 2024-07-07 15:58 ./usr/share/doc/linux-image-unsigned-5.15.0-113-generic/copyright
以下是构建过程结束时的一些尾部输出。请注意指示构建包的行,其中包尚未+test1
包含.deb
。
dpkg-deb: building package 'linux-image-unsigned-5.15.0-113-generic' in '../linux-image-unsigned-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb'.
dh_installchangelogs -plinux-modules-5.15.0-113-generic
dh_installdocs -plinux-modules-5.15.0-113-generic
dh_compress -plinux-modules-5.15.0-113-generic
dh_fixperms -plinux-modules-5.15.0-113-generic -X/boot/
dh_shlibdeps -plinux-modules-5.15.0-113-generic
dh_installdeb -plinux-modules-5.15.0-113-generic
dh_installdebconf -plinux-modules-5.15.0-113-generic
flock -w 60 /home/mike/linux-5.15.0/debian/.LOCK dh_gencontrol -plinux-modules-5.15.0-113-generic -- -Vlinux:rprovides='spl-modules, spl-dkms, zfs-modules, zfs-dkms, v4l2loopback-modules, v4l2loopback-dkms, '
dpkg-gencontrol: warning: Depends field of package linux-modules-5.15.0-113-generic: substitution variable ${shlibs:Depends} used, but is not defined
dpkg-gencontrol: warning: Built-Using field of package linux-modules-5.15.0-113-generic: substitution variable ${linux:BuiltUsing} used, but is not defined
dh_md5sums -plinux-modules-5.15.0-113-generic
dh_builddeb -plinux-modules-5.15.0-113-generic
dpkg-deb: building package 'linux-modules-5.15.0-113-generic' in '../linux-modules-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb'.
if [ -f debian.master/control.d/generic.inclusion-list ] ; then \
dh_installchangelogs -plinux-modules-extra-5.15.0-113-generic; \
dh_installdocs -plinux-modules-extra-5.15.0-113-generic; \
dh_compress -plinux-modules-extra-5.15.0-113-generic; \
dh_fixperms -plinux-modules-extra-5.15.0-113-generic -X/boot/; \
dh_shlibdeps -plinux-modules-extra-5.15.0-113-generic ; \
dh_installdeb -plinux-modules-extra-5.15.0-113-generic; \
dh_installdebconf -plinux-modules-extra-5.15.0-113-generic; \
flock -w 60 /home/mike/linux-5.15.0/debian/.LOCK dh_gencontrol -plinux-modules-extra-5.15.0-113-generic -- -Vlinux:rprovides='spl-modules, spl-dkms, zfs-modules, zfs-dkms, v4l2loopback-modules, v4l2loopback-dkms, ' ; \
dh_md5sums -plinux-modules-extra-5.15.0-113-generic; \
dh_builddeb -plinux-modules-extra-5.15.0-113-generic; \
fi
dpkg-gencontrol: warning: Depends field of package linux-modules-extra-5.15.0-113-generic: substitution variable ${shlibs:Depends} used, but is not defined
dpkg-deb: building package 'linux-modules-extra-5.15.0-113-generic' in '../linux-modules-extra-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb'.
dh_installchangelogs -plinux-modules-iwlwifi-5.15.0-113-generic
dh_installdocs -plinux-modules-iwlwifi-5.15.0-113-generic
dh_compress -plinux-modules-iwlwifi-5.15.0-113-generic
dh_fixperms -plinux-modules-iwlwifi-5.15.0-113-generic -X/boot/
dh_shlibdeps -plinux-modules-iwlwifi-5.15.0-113-generic
dh_installdeb -plinux-modules-iwlwifi-5.15.0-113-generic
dh_installdebconf -plinux-modules-iwlwifi-5.15.0-113-generic
flock -w 60 /home/mike/linux-5.15.0/debian/.LOCK dh_gencontrol -plinux-modules-iwlwifi-5.15.0-113-generic -- -Vlinux:rprovides='spl-modules, spl-dkms, zfs-modules, zfs-dkms, v4l2loopback-modules, v4l2loopback-dkms, '
dpkg-gencontrol: warning: Built-Using field of package linux-modules-iwlwifi-5.15.0-113-generic: substitution variable ${linux:BuiltUsing} used, but is not defined
dh_md5sums -plinux-modules-iwlwifi-5.15.0-113-generic
dh_builddeb -plinux-modules-iwlwifi-5.15.0-113-generic;
dpkg-deb: building package 'linux-modules-iwlwifi-5.15.0-113-generic' in '../linux-modules-iwlwifi-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb'.
dh_installchangelogs -plinux-buildinfo-5.15.0-113-generic
dh_installdocs -plinux-buildinfo-5.15.0-113-generic
dh_compress -plinux-buildinfo-5.15.0-113-generic
dh_fixperms -plinux-buildinfo-5.15.0-113-generic -X/boot/
dh_shlibdeps -plinux-buildinfo-5.15.0-113-generic
dh_installdeb -plinux-buildinfo-5.15.0-113-generic
dh_installdebconf -plinux-buildinfo-5.15.0-113-generic
flock -w 60 /home/mike/linux-5.15.0/debian/.LOCK dh_gencontrol -plinux-buildinfo-5.15.0-113-generic -- -Vlinux:rprovides='spl-modules, spl-dkms, zfs-modules, zfs-dkms, v4l2loopback-modules, v4l2loopback-dkms, '
dpkg-gencontrol: warning: Depends field of package linux-buildinfo-5.15.0-113-generic: substitution variable ${shlibs:Depends} used, but is not defined
dpkg-gencontrol: warning: Built-Using field of package linux-buildinfo-5.15.0-113-generic: substitution variable ${linux:BuiltUsing} used, but is not defined
dh_md5sums -plinux-buildinfo-5.15.0-113-generic
dh_builddeb -plinux-buildinfo-5.15.0-113-generic
dpkg-deb: building package 'linux-buildinfo-5.15.0-113-generic' in '../linux-buildinfo-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb'.
dh_installchangelogs -plinux-headers-5.15.0-113-generic
dh_installdocs -plinux-headers-5.15.0-113-generic
dh_compress -plinux-headers-5.15.0-113-generic
dh_fixperms -plinux-headers-5.15.0-113-generic -X/boot/
dh_shlibdeps -plinux-headers-5.15.0-113-generic
dh_installdeb -plinux-headers-5.15.0-113-generic
dh_installdebconf -plinux-headers-5.15.0-113-generic
flock -w 60 /home/mike/linux-5.15.0/debian/.LOCK dh_gencontrol -plinux-headers-5.15.0-113-generic -- -Vlinux:rprovides='spl-modules, spl-dkms, zfs-modules, zfs-dkms, v4l2loopback-modules, v4l2loopback-dkms, '
dh_md5sums -plinux-headers-5.15.0-113-generic
dh_builddeb -plinux-headers-5.15.0-113-generic
dpkg-deb: building package 'linux-headers-5.15.0-113-generic' in '../linux-headers-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb'.
dh_installchangelogs -plinux-tools-5.15.0-113-generic
dh_installdocs -plinux-tools-5.15.0-113-generic
dh_compress -plinux-tools-5.15.0-113-generic
dh_fixperms -plinux-tools-5.15.0-113-generic -X/boot/
dh_shlibdeps -plinux-tools-5.15.0-113-generic
dh_installdeb -plinux-tools-5.15.0-113-generic
dh_installdebconf -plinux-tools-5.15.0-113-generic
flock -w 60 /home/mike/linux-5.15.0/debian/.LOCK dh_gencontrol -plinux-tools-5.15.0-113-generic -- -Vlinux:rprovides='spl-modules, spl-dkms, zfs-modules, zfs-dkms, v4l2loopback-modules, v4l2loopback-dkms, '
dh_md5sums -plinux-tools-5.15.0-113-generic
dh_builddeb -plinux-tools-5.15.0-113-generic
dpkg-deb: building package 'linux-tools-5.15.0-113-generic' in '../linux-tools-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb'.
dh_installchangelogs -plinux-cloud-tools-5.15.0-113-generic
dh_installdocs -plinux-cloud-tools-5.15.0-113-generic
dh_compress -plinux-cloud-tools-5.15.0-113-generic
dh_fixperms -plinux-cloud-tools-5.15.0-113-generic -X/boot/
dh_shlibdeps -plinux-cloud-tools-5.15.0-113-generic
dh_installdeb -plinux-cloud-tools-5.15.0-113-generic
dh_installdebconf -plinux-cloud-tools-5.15.0-113-generic
flock -w 60 /home/mike/linux-5.15.0/debian/.LOCK dh_gencontrol -plinux-cloud-tools-5.15.0-113-generic -- -Vlinux:rprovides='spl-modules, spl-dkms, zfs-modules, zfs-dkms, v4l2loopback-modules, v4l2loopback-dkms, '
dh_md5sums -plinux-cloud-tools-5.15.0-113-generic
dh_builddeb -plinux-cloud-tools-5.15.0-113-generic
dpkg-deb: building package 'linux-cloud-tools-5.15.0-113-generic' in '../linux-cloud-tools-5.15.0-113-generic_5.15.0-113.123+test1_amd64.deb'.
发生什么了?
- 这是一个错误吗?
- 这是故意的吗?我没有正确理解这个过程?
- 或者我做错了什么?
我参考的教程指出:
我最初的理解是编辑第一行
debian.master/changelog
如下:但是,我认为我将本地版本修饰符放在了错误的位置。当我将其添加到 ABI 编号末尾而不是上传编号之后时,.deb 存档和所有软件包都会相应地命名。
内核命名方案
为了解释内核命名方案的不同部分, Ubuntu wiki 中的问题“特定的 Ubuntu 内核版本号是什么意思?”解释了:
阅读源代码
为了更好地理解这个过程,我阅读了各种源代码文件,从中读取内核版本
debian.master/changelog
并将其分解为各个部分并分配给变量。然后使用这些变量来命名和构建二进制包。要注意的第一个定义来自
debian/debian.env
:接下来,源包名称将是 中的第一个标记
debian.master/changelog
。这是在 的第 7 行定义的debian/rules.d/0-common-vars.mk
:第 13 行
debian/rules.d/0-common-vars.mk
:第 82 行
debian/rules.d/0-common-vars.mk
:第 84 行
debian/rules.d/0-common-vars.mk
:第 141 行
debian/rules.d/0-common-vars.mk
:第 57 行
debian/rules.d/2-binary-arch.mk
:第 582 行
debian/rules.d/2-binary-arch.mk
:第 600 行
debian/rules.d/2-binary-arch.mk
:此行调用
dh_all
,这是一个从 的第 550 行开始的定义指令debian/rules.d/2.binary-arch.mk
:最后一行调用
dh_builddeb
,构建 Debian 二进制包。(有关更多信息,请参阅man dh_builddeb。)无论如何,要查看其中一些关键变量的值,您可以
debian/rules printenv
从内核源目录运行:最后说明
我找不到很多关于这个特定主题的信息,详细说明了添加本地版本修改器。我发现的唯一一个基本上做了我在这里概述的同样事情的来源是 GitHub 存储库build-ubuntu-kernel 。在他们的构建脚本中,以下部分修改了 ABI 编号
debian.master/changelog
: