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
不执行该命令

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


 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/145962.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

使用Maven创建一个Java项目并在repository中使用

JDK环境&#xff1a;1.8.0_371 Maven环境 &#xff1a;Apache Maven 3.6.3 配置完成jdk和mvn后&#xff0c;进入到指定文件夹下执行如下语句&#xff1a; mvn archetype:generate -DgroupIdtop.chengrongyu -DartifactIdCyberSpace -DarchetypeArtifactIdmaven-archetype-quic…

(20)Shell脚本的书写

linux中的shell脚本&#xff0c;其实是系统中真正的命令。Shell语言写的程序不需编译.定义各种参数和变量、使用条件命令、控制结构以及其他高级特性。 一、shell脚本基本元素 1.1变量 定义&#xff1a;定义一个名称&#xff0c;将参数赋予给这个名称。就叫变量。变量名可以…

C++【类和对象】(一)

文章目录 前言1.类的定义1.1类定义格式1.2 访问限定符1.3 类域 2. 实例化2.1 实例化的概念2.2 对象大小 3.this指针结语 前言 在前文我们讲解了C基础语法知识。本文将会讲解C的类和对象。 1.类的定义 1.1类定义格式 class name {}&#xff1b;class为定义类的关键字&#x…

Linux进阶命令-rsync

作者介绍&#xff1a;简历上没有一个精通的运维工程师。希望大家多多关注作者&#xff0c;下面的思维导图也是预计更新的内容和当前进度(不定时更新)。 经过上一章Linux日志的讲解&#xff0c;我们对Linux系统自带的日志服务已经有了一些了解。我们接下来将讲解一些进阶命令&am…

erlang学习:Linux常用命令2

目录操作命令 对目录进行基本操作 相关cd切换目录之类的就直接省去了&#xff0c;以下操作中都会用到 查看当前目录下的所有目录和文件 ls 列表查看当前目录下的所有目录和文件&#xff08;列表查看&#xff0c;显示更多信息&#xff09; ls -l 或 ll 在当前目录下创建一个…

高性能并发计数器的比较

参考文档&#xff1a;https://baijiahao.baidu.com/s?id1742540809477784106&wfrspider&forpc 一、常用的并发计数方法 1、synchronized synchronized早期是一个重量级锁&#xff0c;因为线程竞争锁会引起操作系统用户态和内核态切换&#xff0c;浪费资源&#xff…

Element Plus中button按钮相关大全

一、基本用法 使用 type、plain、round 和 circle 来定义按钮的样式。 样式代码如下&#xff1a; <template><div class"mb-4"><el-button>Default</el-button><el-button type"primary">Primary</el-button><el…

C语言常见字符串函数模拟实现一

strlen模拟实现 重点&#xff1a;1.字符串已经\0作为结束标志&#xff0c;strlen返回的是字符串\0前面出现的字符个数&#xff08;不包含\0&#xff09; 2.参数指向的字符串必须要以\0结束。 3.注意函数的返回值是size_t&#xff0c;是无符号的&#xff0c;加减是无法对比的。…

卡西欧相机SD卡格式化后数据恢复指南

在数字摄影时代&#xff0c;卡西欧相机以其卓越的性能和便携性成为了众多摄影爱好者的首选。然而&#xff0c;随着拍摄量的增加&#xff0c;SD卡中的数据管理变得尤为重要。不幸的是&#xff0c;有时我们可能会因为操作失误或系统故障而将SD卡格式化&#xff0c;导致珍贵的照片…

数据类型转换中存在的问题分析

隐式类型转换&#xff08;implicit type conversion&#xff09; 隐式类型转换&#xff08;implicit type conversion&#xff09;包括整型提升&#xff08;integer promotion&#xff09;和标准算数转换&#xff08;usual arithmetic conversions&#xff09; 遵循较大范围优…

堡垒机(Bastion Host)概述

Bastion Host 堡垒机 一、什么是堡垒机&#xff1f; A bastion host is a computer specially designed to mitigate cyberattacks and manage access rights to an internal network. 堡垒机Bastion Host是一种专门设计用于缓解网络攻击并管理内部网络访问权限的计算机。 在…

肖扬新书《微权力下的项目管理》读书笔记2

一个核心思想&#xff1a;“借力” 合格的项目经理是不热衷于培养人的。项目经理的工作场景和职能经理的工作场景往往有很 大不同。职能经理的工作方式通常适用于常态化工作&#xff0c;要有足够的时间去培养人&#xff0c;先把人培 养起来&#xff0c;然后再干事&#xff0c;可…

加油卡APP定制搭建,让加油更便捷!

在汽车时代中&#xff0c;汽车的数量不断增加&#xff0c;加油已经成为了大众生活中不可缺少的一部分。同时&#xff0c;加油卡的出现也为大众的汽车加油提供了更多的优惠方式&#xff0c;为大众节省经济开支&#xff0c;为车主带来便利&#xff1b;同时加油卡的发展也提高了加…

2024年华为杯研赛(E题)数学建模竞赛解题思路|完整代码论文集合

我是Tina表姐&#xff0c;毕业于中国人民大学&#xff0c;对数学建模的热爱让我在这一领域深耕多年。我的建模思路已经帮助了百余位学习者和参赛者在数学建模的道路上取得了显著的进步和成就。现在&#xff0c;我将这份宝贵的经验和知识凝练成一份全面的解题思路与代码论文集合…

如何远程访问局域网内的电脑?局域网内远程桌面怎么实现?揭秘4种干货技巧

想象一下&#xff0c;你正在办公室A&#xff0c;而你想访问办公室B里的某台电脑&#xff0c;却不想起身到另一楼层甚至是另一个房间。 如何不动身就能控制局域网内的另一台电脑呢&#xff1f; 这并不是科幻&#xff0c;而是完全可以通过远程桌面技术来实现。 今天&#xff0…

学习Java(一)类和对象

package demo.ceshi;public class Puppy {private int age;private String name;//构造器public Puppy( String name){this.name name;System.out.println("公主的名字叫&#xff1a;"name);}//设置age的值public void setAge(int age){this.age age;System.out.pr…

智慧仓储-AI销量预测

1、预测系统技术选型 基础层&#xff1a; Hbase、ClickHouse、Hdfs 用来做数据存储 框架层&#xff1a; 以 Spark RDD、Spark SQL、Hive 为主&#xff0c; MapReduce 程序占一小部分&#xff0c;是原先遗留下来的&#xff0c;目前正逐步替换成 Spark RDD。 选择 Spark 除了对…

rsyslogd 内存占用很高解决方案

在Kubernetes&#xff08;K8S&#xff09;集群中&#xff0c;监控日志是非常重要的&#xff0c;而rsyslogd是Linux系统中用于处理系统和应用程序日志的守护进程。有时候rsyslogd可能会占用较高的内存&#xff0c;这时候我们就需要对其进行优化和调整。 阿里云虚拟服务器&…

创客中国AIGC专题赛冠军天鹜科技:AI蛋白质设计引领者

“落霞与孤鹜齐飞,秋水共长天一色——这句出自《滕王阁序》的诗句,是我作为江西人熟记于心的佳句。它描绘的天地壮丽景色常浮现于我的脑海,正是这种豁达与壮观,启发我们将公司命名为‘天鹜科技’,我们希望将源自自然的蛋白质与现代科技的创新精神相结合,打造蛋白质设计与应用的…

16_Python的迭代器

在Python中&#xff0c;迭代是一个非常重要的概念。迭代通常指的是按照某种顺序逐个访问容器中的元素的行为。如使用for循环遍历取值的过程。 可迭代对象&#xff08;Iterable&#xff09; 可迭代对象是任何可以返回一个迭代器的对象。简单来说&#xff0c;它是可以逐一返回其…