Kernel/BuildYourOwnKernel - Ubuntu Wikihttps://wiki.ubuntu.com/Kernel/BuildYourOwnKernel
一、当前系统内核版本
root@ubuntu22:~# uname -r
5.15.0-118-generic
二、apt缓存中的内核源码信息
root@ubuntu22:~# apt update
root@ubuntu22:~# apt-cache search linux-source
linux-source - Linux kernel source with Ubuntu patches
linux-source-5.15.0 - Linux kernel source for version 5.15.0 with Ubuntu patches
linux-source-5.19.0 - Linux kernel source for version 5.19.0 with Ubuntu patches
linux-source-6.2.0 - Linux kernel source for version 6.2.0 with Ubuntu patches
linux-source-6.5.0 - Linux kernel source for version 6.5.0 with Ubuntu patches
内核版本 5.15.0、5.19.0、6.2.0、6.5.0 分别对应 Ubuntu 22.04、22.10、23.04、23.10
三、源码下载
1、使用apt命令下载
1.1、apt source
将内核源码下载到当前目录并自动解压,提供了更完整的源代码包,包括 Ubuntu 特定的修改。
(1)apt source linux
安装仓库中最新可用的内核源代码版本。
linux总是可用的,指向最新通用版本。
(2)apt source linux-image-$(uname -r)
获取与当前运行的内核版本完全匹配的源代码,通常只包含必要的文件。
并非所有版本在仓库中都有完全匹配的源代码。
(3)apt source linux-image-unsigned-$(uname -r) (适用于开发)
获取未签名的内核包,适合开发和测试。并非所有版本在仓库中都有完全匹配的源代码。
1.2、apt install
将内核源码下载到/usr/src目录,安装的是一个"原始"的源代码包,可能需要额外的步骤来应用 Ubuntu 特定的补丁。
(1)apt install linux-source
安装仓库中最新可用的内核源代码版本
linux-source 包总是可用的,指向最新版本
(2)apt install linux-source-<version>
安装指定版本的内核源代码
并非所有版本都有对应的 linux-source-<version> 包
5.15.0-118-generic,version=5.15.0,将下载 5.15 系列的通用源码。
如要精确匹配 5.15.0-118-generic 版本,需要额外下载 Ubuntu 特定的补丁。
1.3、apt下载源码
(1)apt source linux
root@ubuntu22:~# apt source linux
Reading package lists... Done
NOTICE: 'linux' packaging is maintained in the 'Git' version control system at:
git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/jammy
Please use:
git clone git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/jammy
to retrieve the latest (possibly unreleas