当前位置: 首页 > news >正文

Ubuntu 22.04 源码下载、编译

Kernel/BuildYourOwnKernel - Ubuntu Wikiicon-default.png?t=O83Ahttps://wiki.ubuntu.com/Kernel/BuildYourOwnKernel

一、查询当前系统内核版本

root@ubuntu22:~# uname -r
5.15.0-118-generic

二、查询本地软件包数据库中的内核源码信息

root@ubuntu22:~# apt search linux-source
Sorting... Done
Full Text Search... Done
linux-source/jammy-updates,jammy-security,now 5.15.0.119.119 all [installed]Linux kernel source with Ubuntu patcheslinux-source-5.15.0/jammy-updates,jammy-security,now 5.15.0-119.129 all [installed,automatic]Linux kernel source for version 5.15.0 with Ubuntu patcheslinux-source-5.19.0/jammy-updates,jammy-security 5.19.0-50.50 allLinux kernel source for version 5.19.0 with Ubuntu patcheslinux-source-6.2.0/jammy-updates,jammy-security 6.2.0-39.40~22.04.1 allLinux kernel source for version 6.2.0 with Ubuntu patcheslinux-source-6.5.0/jammy-updates 6.5.0-45.45~22.04.1 allLinux kernel source for version 6.5.0 with Ubuntu patches

三、源码下载

1、apt source

将内核源码下载到当前目录并自动解压,提供了更完整的源代码包,包括 Ubuntu 特定的修改。
(1)apt source linux
安装仓库中最新可用的内核源代码版本。
linux总是可用的,指向最新通用版本。
(2)apt source linux-image-$(uname -r)
获取与当前运行的内核版本完全匹配的源代码,通常只包含必要的文件。
并非所有版本在仓库中都有完全匹配的源代码。

(3)apt source linux-image-unsigned-$(uname -r)  (适用于开发)

获取未签名的内核包,适合开发和测试。并非所有版本在仓库中都有完全匹配的源代码。

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 特定的补丁。

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 unreleased) updates to the package.
eed to get 206 MB of source archives.
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main linux 5.15.0-121.131 (dsc) [7,799 B]
Get:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main linux 5.15.0-121.131 (tar) [195 MB]
Get:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main linux 5.15.0-121.131 (diff) [10.5 MB]                    
Fetched 206 MB in 49s (4,168 kB/s)                                                                                           
dpkg-source: info: extracting linux in linux-5.15.0
dpkg-source: info: unpacking linux_5.15.0.orig.tar.gz
dpkg-source: info: applying linux_5.15.0-121.131.diff.gzroot@ubuntu22:~# ll
total 200708
drwxr-xr-x  3 root root      4096 Sep 13 06:32 ./
drwx------  6 root root      4096 Sep 13 06:23 ../
drwxr-xr-x 28 root root      4096 Sep 13 06:32 linux-5.15.0/
-rw-r--r--  1 root root  10533549 Aug 12 13:17 linux_5.15.0-121.131.diff.gz
-rw-r--r--  1 root root      7799 Aug 12 13:17 linux_5.15.0-121.131.dsc
-rw-r--r--  1 root root 194969557 Nov 18  2021 linux_5.15.0.orig.tar.gzroot@ubuntu22:~# cat linux-5.15.0/Makefile
...
VERSION = 5
PATCHLEVEL = 15
SUBLEVEL = 163
EXTRAVERSION =
NAME = Trick or Treat
...

(2)apt source linux-image-$(uname -r)

root@ubuntu22:~# apt source linux-image-$(uname -r)
Reading package lists... Done
Picking 'linux-signed' as source package instead of 'linux-image-5.15.0-118-generic'
Need to get 26.4 kB of source archives.
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main linux-signed 5.15.0-121.131 (dsc) [2,370 B]
Get:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main linux-signed 5.15.0-121.131 (tar) [24.1 kB]
Fetched 26.4 kB in 1s (51.3 kB/s)       
dpkg-source: info: extracting linux-signed in linux-signed-5.15.0
dpkg-source: info: unpacking linux-signed_5.15.0-121.131.tar.xzroot@ubuntu22:~# ll
total 40
drwxr-xr-x 3 root root  4096 Sep 13 06:49 ./
drwx------ 6 root root  4096 Sep 13 06:44 ../
drwxr-xr-x 3 root root  4096 May 27 13:50 linux-signed-5.15.0/
-rw-r--r-- 1 root root  2370 Aug 12 13:17 linux-signed_5.15.0-121.131.dsc
-rw-r--r-- 1 root root 24076 Aug 12 13:17 linux-signed_5.15.0-121.131.tar.xzroot@ubuntu22:~# ll linux-signed-5.15.0/
total 24
drwxr-xr-x 3 root root 4096 May 27 13:50 ./
drwxr-xr-x 3 root root 4096 Sep 13 06:49 ../
drwxr-xr-x 6 root root 4096 Aug  9 08:16 debian/
-rwxr-xr-x 1 root root 6988 May 23 15:13 download-signed*
-rwxr-xr-x 1 root root  450 May 23 15:13 download-unsigned*root@ubuntu22:~# ll linux-signed-5.15.0/debian/
total 180
drwxr-xr-x 6 root root   4096 Aug  9 08:16 ./
drwxr-xr-x 3 root root   4096 May 27 13:50 ../
drwxr-xr-x 3 root root   4096 Aug  1 13:01 ancillary/
-rw-r--r-- 1 root root 121300 Aug  9 08:16 changelog
-rw-r--r-- 1 root root      2 Apr 25 14:35 compat
-rw-r--r-- 1 root root   1949 Aug  9 08:16 control
-rw-r--r-- 1 root root    277 Aug  6 13:11 control.stub
-rw-r--r-- 1 root root   1456 Nov 14  2023 copyright
-rw-r--r-- 1 root root    163 Aug  6 13:11 package.config
-rwxr-xr-x 1 root root   5693 Aug  6 13:11 rules*
drwxr-xr-x 3 root root   4096 Aug  6 13:11 scripts/
-rw-r--r-- 1 root root     12 Aug  6 13:11 signed-version
drwxr-xr-x 2 root root   4096 Nov 14  2023 source/
drwxr-xr-x 2 root root   4096 Aug  6 13:11 templates/
-rw-r--r-- 1 root root     21 Aug  9 07:41 tracking-bug

(3)apt source linux-image-unsigned-$(uname -r)

root@ubuntu22:~# apt source linux-image-unsigned-$(uname -r)
Reading package lists... Done
Picking 'linux' as source package instead of 'linux-image-unsigned-5.15.0-118-generic'
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 unreleased) updates to the package.
Need to get 206 MB of source archives.
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main linux 5.15.0-121.131 (dsc) [7,799 B]
Get:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main linux 5.15.0-121.131 (tar) [195 MB]
Get:3 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main linux 5.15.0-121.131 (diff) [10.5 MB]
Fetched 206 MB in 2min 21s (1,455 kB/s)                                                                                      
dpkg-source: info: extracting linux in linux-5.15.0
dpkg-source: info: unpacking linux_5.15.0.orig.tar.gz
dpkg-source: info: applying linux_5.15.0-121.131.diff.gz

(4)apt install linux-source

# cd /usr/src# ll
total 16
drwxr-xr-x  4 root root 4096 Aug 20 08:12 ./
drwxr-xr-x 14 root root 4096 Aug  9  2022 ../
drwxr-xr-x 25 root root 4096 Aug 20 08:12 linux-headers-5.15.0-118/
drwxr-xr-x  7 root root 4096 Aug 20 08:12 linux-headers-5.15.0-118-generic/# apt install linux-source
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:linux-source-5.15.0
Suggested packages:libncurses-dev | ncurses-dev kernel-package libqt3-dev
The following NEW packages will be installed:linux-source linux-source-5.15.0
0 upgraded, 2 newly installed, 0 to remove and 112 not upgraded.
Need to get 153 MB of archives.
After this operation, 161 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main amd64 linux-source-5.15.0 all 5.15.0-121.131 [153 MB]
Get:2 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main amd64 linux-source all 5.15.0.121.121 [2,310 B]          
Fetched 153 MB in 1min 23s (1,834 kB/s)# ll
total 20
drwxr-xr-x  5 root root 4096 Sep 13 03:45 ./
drwxr-xr-x 14 root root 4096 Aug  9  2022 ../
drwxr-xr-x 25 root root 4096 Aug 20 08:12 linux-headers-5.15.0-118/
drwxr-xr-x  7 root root 4096 Aug 20 08:12 linux-headers-5.15.0-118-generic/
drwxr-xr-x  4 root root 4096 Sep 13 03:45 linux-source-5.15.0/
lrwxrwxrwx  1 root root   47 Aug  9 08:15 linux-source-5.15.0.tar.bz2 -> linux-source-5.15.0/linux-source-5.15.0.tar.bz2# ll linux-source-5.15.0
total 149944
drwxr-xr-x  4 root root      4096 Sep 13 03:45 ./
drwxr-xr-x  5 root root      4096 Sep 13 03:45 ../
drwxr-xr-x 15 root root      4096 Sep 13 03:45 debian/
drwxr-xr-x  7 root root      4096 Sep 13 03:45 debian.master/
-rw-r--r--  1 root root 153523863 Aug  9 08:15 linux-source-5.15.0.tar.bz2

(5)apt install linux-source-5.15.0

# apt install linux-source-5.15.0
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:libncurses-dev | ncurses-dev kernel-package libqt3-dev
The following NEW packages will be installed:linux-source-5.15.0
0 upgraded, 1 newly installed, 0 to remove and 112 not upgraded.
Need to get 153 MB of archives.
After this operation, 161 MB of additional disk space will be used.
Get:1 http://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates/main amd64 linux-source-5.15.0 all 5.15.0-121.131 [153 MB]
Fetched 153 MB in 1min 4s (2,401 kB/s) # ll
total 20
drwxr-xr-x  5 root root 4096 Sep 13 07:29 ./
drwxr-xr-x 14 root root 4096 Aug  9  2022 ../
drwxr-xr-x 25 root root 4096 Aug 20 08:12 linux-headers-5.15.0-118/
drwxr-xr-x  7 root root 4096 Aug 20 08:12 linux-headers-5.15.0-118-generic/
drwxr-xr-x  4 root root 4096 Sep 13 07:29 linux-source-5.15.0/
lrwxrwxrwx  1 root root   47 Aug  9 08:15 linux-source-5.15.0.tar.bz2 -> linux-source-5.15.0/linux-source-5.15.0.tar.bz2c# ll linux-source-5.15.0
total 149944
drwxr-xr-x  4 root root      4096 Sep 13 07:29 ./
drwxr-xr-x  5 root root      4096 Sep 13 07:29 ../
drwxr-xr-x 15 root root      4096 Sep 13 07:29 debian/
drwxr-xr-x  7 root root      4096 Sep 13 07:29 debian.master/
-rw-r--r--  1 root root 153523863 Aug  9 08:15 linux-source-5.15.0.tar.bz2

4、launchpad下载源码 (适用于开发)

Ubuntu 官方使用的代码托管和协作平台,可以浏览下载 Ubuntu 内核源码
https://code.launchpad.net/ubuntu/+source/linux

ubuntu22.04

git clone https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/jammy

git tag
最接近5.15.0-118-generic的版本为 Ubuntu-5.15.0-118.128

git checkout Ubuntu-5.15.0-118.128

只clone指定标签的最新代码(无其它标签)(有没有single-branch参数结果都一样)

git clone --branch Ubuntu-5.15.0-118.128 --depth 1 --single-branch https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/jammy

5、Ubuntu内核官方git库

https://kernel.ubuntu.com/git/

实际下载地址 code.launchpad.net

四、编译

1、构建环境

安装一些软件包。

$ sudo apt build-dep linux linux-image-unsigned-$(uname -r)

可能还需要以下附加包,依赖于具体的系统版本。

sudo apt install libncurses-dev gawk flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf llvm

2、下载源码

本文使用 apt source linux-image-unsigned-$(uname -r) 下载源码

$ apt source linux-image-unsigned-$(uname -r)$ ll
total 200712
drwxrwxr-x  3 zhang zhang      4096 Sep 21 05:55 ./
drwxr-x---  8 zhang zhang      4096 Sep 21 05:52 ../
drwxr-xr-x 28 root  root       4096 Sep 21 05:55 linux-5.15.0/
-rw-r--r--  1 root  root   10538925 Sep 16 20:13 linux_5.15.0-122.132.diff.gz
-rw-r--r--  1 root  root       7799 Sep 16 20:13 linux_5.15.0-122.132.dsc
-rw-r--r--  1 root  root  194969557 Nov 18  2021 linux_5.15.0.orig.tar.gz$ head -n 5  linux-5.15.0/Makefile 
# SPDX-License-Identifier: GPL-2.0
VERSION = 5
PATCHLEVEL = 15
SUBLEVEL = 163
EXTRAVERSION =

3、修改配置

$ chmod a+x debian/rules
$ chmod a+x debian/scripts/*
$ chmod a+x debian/scripts/misc/*
$ fakeroot debian/rules clean
$ # you need to go through each (Y, Exit, Y, Exit..) or get a complaint about config later
$ fakeroot debian/rules editconfigs
问题:
fakeroot debian/rules editconfigs 报错:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmp.f7cP7kt5Xl/arm64-config.flavour.generic'
解决:
TODO(不执行editconfigs命令,直接下一步构建内核,也能构建成功)

4、构建内核

$ fakeroot debian/rules clean$ # quicker build:
$ fakeroot debian/rules binary-headers binary-generic binary-perarch$ # if you need linux-tools or lowlatency kernel, run instead:
$ fakeroot debian/rules binary

5、安装内核

$ sudo dpkg -i linux*5.15.0-122.132*.deb
$ sudo reboot

6、构建包含调式符号的内核

$ sudo apt install pkg-config-dbgsym
$ fakeroot debian/rules clean
$ fakeroot debian/rules binary-headers binary-generic binary-perarch skipdbg=false


 

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 【数据结构C语言】【入门】【首次万字详细解析】入门阶段数据结构可能用到的C语言知识,一章让你看懂数据结构!!!!!!!
  • 计算机组成原理之计算机系统的工作原理
  • 第一次安装Pytorch
  • Golang | Leetcode Golang题解之第421题数组中两个数的最大异或值
  • MySql主从复制原理
  • docker 升级步骤
  • C++ prime plus-7-編程練習
  • VMware虚拟机因磁盘空间不足黑屏无法登录
  • matlab绘制二维云图,划分区域,并显示每个区域的均值
  • KVM环境下制作ubuntu qcow2格式镜像
  • 基于SpringBoot的漫画网设计与实现
  • 人工智能快速发展下的极端风险管理
  • 力扣中等 33.搜索旋转排序数组
  • C语言 | Leetcode C语言题解之第415题字符串相加
  • proteus仿真学习(1)
  • (十五)java多线程之并发集合ArrayBlockingQueue
  • [笔记] php常见简单功能及函数
  • canvas 高仿 Apple Watch 表盘
  • eclipse(luna)创建web工程
  • es6--symbol
  • Java 网络编程(2):UDP 的使用
  • Java|序列化异常StreamCorruptedException的解决方法
  • Java多态
  • Java反射-动态类加载和重新加载
  • Linux中的硬链接与软链接
  • mysql中InnoDB引擎中页的概念
  • puppeteer stop redirect 的正确姿势及 net::ERR_FAILED 的解决
  • SSH 免密登录
  • UEditor初始化失败(实例已存在,但视图未渲染出来,单页化)
  • Yii源码解读-服务定位器(Service Locator)
  • 理解IaaS, PaaS, SaaS等云模型 (Cloud Models)
  • 让你的分享飞起来——极光推出社会化分享组件
  • 手机app有了短信验证码还有没必要有图片验证码?
  • 小程序测试方案初探
  • 2017年360最后一道编程题
  • 微龛半导体获数千万Pre-A轮融资,投资方为国中创投 ...
  • ​十个常见的 Python 脚本 (详细介绍 + 代码举例)
  • # linux 中使用 visudo 命令,怎么保存退出?
  • ### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException
  • #etcd#安装时出错
  • #使用清华镜像源 安装/更新 指定版本tensorflow
  • $.proxy和$.extend
  • (03)光刻——半导体电路的绘制
  • (Matlab)基于蝙蝠算法实现电力系统经济调度
  • (poj1.2.1)1970(筛选法模拟)
  • (附源码)spring boot网络空间安全实验教学示范中心网站 毕业设计 111454
  • (回溯) LeetCode 46. 全排列
  • (三)终结任务
  • (实战)静默dbca安装创建数据库 --参数说明+举例
  • (四)软件性能测试
  • (五十)第 7 章 图(有向图的十字链表存储)
  • (学习日记)2024.03.12:UCOSIII第十四节:时基列表
  • (转)使用VMware vSphere标准交换机设置网络连接
  • .[backups@airmail.cc].faust勒索病毒的最新威胁:如何恢复您的数据?
  • .NET Framework 3.5安装教程