GNU/Linux - 如何编译kernel

使用 make 命令构建 Linux 内核涉及多个步骤。下面是整个过程的基本概述:

1. 获取内核源代码

    * 从 kernel.org 或你的发行版软件仓库下载内核源代码。

    * 将源代码解压缩到一个目录中。

2. 配置内核

    * 切换到内核源代码目录。

    * 可选择清理源代码树:make clean。

    * 使用以下方法之一配置内核:

        * 使用默认配置:make defconfig 或 make oldconfig。

        * 自定义配置:make menuconfig(基于文本)、make xconfig(基于 Qt)或 make gconfig(基于 GTK)。

3. 构建内核

    * 运行 make 来构建内核。可选择使用 -j 标志指定并行编译的线程数,后跟线程数(例如,make -j4 表示 4 个线程。)

    * 此步骤可能需要一些时间,具体取决于硬件和所选配置选项。

确保在开始编译前安装了必要的开发工具和依赖项(gcc、make、用于 menuconfig/xconfig/gconfig 的 libncurses-dev 等)。


Building the Linux kernel using the make command involves several steps. Here’s a basic overview of the process:

  1. Get the Kernel Source:

    • Download the kernel source code from kernel.org or your distribution’s repositories.

    • Extract the source code to a directory.

  2. Configure the Kernel:

    • Change to the kernel source directory.

    • Optionally, clean the source tree: make clean.

    • Configure the kernel using one of the following methods:

      • Use the default configuration: make defconfig or make oldconfig.

      • Customize the configuration: make menuconfig (text-based), make xconfig (Qt-based), or make gconfig (GTK-based).

  3. Build the Kernel:

    • Run make to build the kernel. Optionally, you can specify the number of threads for parallel compilation using -j flag followed by the number of threads (e.g., make -j4 for 4 threads. j means job).

    • This step might take some time depending on your hardware and the configuration options chosen.

Ensure you have the necessary development tools and dependencies installed (gcc, make, libncurses-dev for menuconfig/xconfig/gconfig, etc.) before starting the build process.


补充说明:

1,执行make defconfig,会将当前默认的配置写入.config文件,如果没有就创建。

2,make menuconfig,退出时提示是否保存,会保存到.config文件,如果没有就创建。

3,make时使用的就是.config配置文件,如果此文件发生变化,旧内容保存到.config.old,新内容保存到.config

4, make oldconfig会载入.config.old的内容到.config文件。


在Kernel源码根目录下运行make help:


 

$ make help

Cleaning targets:

  clean           - Remove most generated files but keep the config and

                    enough build support to build external modules

  mrproper        - Remove all generated files + config + various backup files

  distclean       - mrproper + remove editor backup and patch files



Configuration targets:

  config          - Update current config utilising a line-oriented program

  nconfig         - Update current config utilising a ncurses menu based program

  menuconfig      - Update current config utilising a menu based program

  xconfig         - Update current config utilising a Qt based front-end

  gconfig         - Update current config utilising a GTK+ based front-end

  oldconfig       - Update current config utilising a provided .config as base

  localmodconfig  - Update current config disabling modules not loaded

                    except those preserved by LMC_KEEP environment variable

  localyesconfig  - Update current config converting local mods to core

                    except those preserved by LMC_KEEP environment variable

  defconfig       - New config with default from ARCH supplied defconfig

  savedefconfig   - Save current config as ./defconfig (minimal config)

  allnoconfig     - New config where all options are answered with no

  allyesconfig    - New config where all options are accepted with yes

  allmodconfig    - New config selecting modules when possible

  alldefconfig    - New config with all symbols set to default

  randconfig      - New config with random answer to all options

  yes2modconfig   - Change answers from yes to mod if possible

  mod2yesconfig   - Change answers from mod to yes if possible

  mod2noconfig    - Change answers from mod to no if possible

  listnewconfig   - List new options

  helpnewconfig   - List new options and help text

  olddefconfig    - Same as oldconfig but sets new symbols to their

                    default value without prompting

  tinyconfig      - Configure the tiniest possible kernel

  testconfig      - Run Kconfig unit tests (requires python3 and pytest)



Other generic targets:

  all             - Build all targets marked with [*]

* vmlinux         - Build the bare kernel

* modules         - Build all modules

  modules_install - Install all modules to INSTALL_MOD_PATH (default: /)

  dir/            - Build all files in dir and below

  dir/file.[ois]  - Build specified target only

  dir/file.ll     - Build the LLVM assembly file

                    (requires compiler support for LLVM assembly generation)

  dir/file.lst    - Build specified mixed source/assembly target only

                    (requires a recent binutils and recent build (System.map))

  dir/file.ko     - Build module including final link

  modules_prepare - Set up for building external modules

  tags/TAGS       - Generate tags file for editors

  cscope          - Generate cscope index

  gtags           - Generate GNU GLOBAL index

  kernelrelease   - Output the release version string (use with make -s)

  kernelversion   - Output the version stored in Makefile (use with make -s)

  image_name      - Output the image name (use with make -s)

  headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH

                    (default: ./usr)



Static analysers:

  checkstack      - Generate a list of stack hogs

  versioncheck    - Sanity check on version.h usage

  includecheck    - Check for duplicate included header files

  export_report   - List the usages of all exported symbols

  headerdep       - Detect inclusion cycles in headers

  coccicheck      - Check with Coccinelle

  clang-analyzer  - Check with clang static analyzer

  clang-tidy      - Check with clang-tidy



Tools:

  nsdeps          - Generate missing symbol namespace dependencies



Kernel selftest:

  kselftest         - Build and run kernel selftest

                      Build, install, and boot kernel before

                      running kselftest on it

                      Run as root for full coverage

  kselftest-all     - Build kernel selftest

  kselftest-install - Build and install kernel selftest

  kselftest-clean   - Remove all generated kselftest files

  kselftest-merge   - Merge all the config dependencies of

                      kselftest to existing .config.



Rust targets:

  rustavailable   - Checks whether the Rust toolchain is

                    available and, if not, explains why.

  rustfmt         - Reformat all the Rust code in the kernel

  rustfmtcheck    - Checks if all the Rust code in the kernel

                    is formatted, printing a diff otherwise.

  rustdoc         - Generate Rust documentation

                    (requires kernel .config)

  rusttest        - Runs the Rust tests

                    (requires kernel .config; downloads external repos)

  rust-analyzer   - Generate rust-project.json rust-analyzer support file

                    (requires kernel .config)

  dir/file.[os]   - Build specified target only

  dir/file.rsi    - Build macro expanded source, similar to C preprocessing.

                    Run with RUSTFMT=n to skip reformatting if needed.

                    The output is not intended to be compilable.

  dir/file.ll     - Build the LLVM assembly file



Userspace tools targets:

  use "make tools/help"

  or  "cd tools; make help"



Kernel packaging:

  rpm-pkg             - Build both source and binary RPM kernel packages

  binrpm-pkg          - Build only the binary kernel RPM package

  deb-pkg             - Build both source and binary deb kernel packages

  bindeb-pkg          - Build only the binary kernel deb package

  snap-pkg            - Build only the binary kernel snap package

                        (will connect to external hosts)

  dir-pkg             - Build the kernel as a plain directory structure

  tar-pkg             - Build the kernel as an uncompressed tarball

  targz-pkg           - Build the kernel as a gzip compressed tarball

  tarbz2-pkg          - Build the kernel as a bzip2 compressed tarball

  tarxz-pkg           - Build the kernel as a xz compressed tarball

  tarzst-pkg          - Build the kernel as a zstd compressed tarball

  perf-tar-src-pkg    - Build perf-6.1.55.tar source tarball

  perf-targz-src-pkg  - Build perf-6.1.55.tar.gz source tarball

  perf-tarbz2-src-pkg - Build perf-6.1.55.tar.bz2 source tarball

  perf-tarxz-src-pkg  - Build perf-6.1.55.tar.xz source tarball

  perf-tarzst-src-pkg - Build perf-6.1.55.tar.zst source tarball



Documentation targets:

Linux kernel internal documentation in different formats from ReST:

  htmldocs        - HTML

  latexdocs       - LaTeX

  pdfdocs         - PDF

  epubdocs        - EPUB

  xmldocs         - XML

  linkcheckdocs   - check for broken external links

                    (will connect to external hosts)

  refcheckdocs    - check for references to non-existing files under

                    Documentation

  cleandocs       - clean all generated files



  make SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2

  valid values for SPHINXDIRS are: PCI RCU accounting admin-guide arc arm arm64 block bpf cdrom core-api cpu-freq crypto dev-tools devicetree doc-guide driver-api fault-injection fb filesystems firmware-guide fpga gpu hid hwmon i2c ia64 iio infiniband input isdn kbuild kernel-hacking leds livepatch locking loongarch m68k maintainer mhi mips misc-devices mm netlabel networking nios2 openrisc parisc pcmcia peci power powerpc process riscv rust s390 scheduler scsi security sh sound sparc spi staging target timers tools trace translations usb userspace-api virt w1 watchdog x86 xtensa



  make SPHINX_CONF={conf-file} [target] use *additional* sphinx-build

  configuration. This is e.g. useful to build with nit-picking config.



  make DOCS_THEME={sphinx-theme} selects a different Sphinx theme.



  make DOCS_CSS={a .css file} adds a DOCS_CSS override file for html/epub output.



  Default location for the generated documents is Documentation/output



Architecture specific targets (x86):

* bzImage               - Compressed kernel image (arch/x86/boot/bzImage)

  install               - Install kernel using (your) ~/bin/installkernel or

                          (distribution) /sbin/installkernel or install to

                          $(INSTALL_PATH) and run lilo



  fdimage               - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)

  fdimage144            - Create 1.4MB boot floppy image (arch/x86/boot/fdimage)

  fdimage288            - Create 2.8MB boot floppy image (arch/x86/boot/fdimage)

  hdimage               - Create a BIOS/EFI hard disk image (arch/x86/boot/hdimage)

  isoimage              - Create a boot CD-ROM image (arch/x86/boot/image.iso)

                          bzdisk/fdimage*/hdimage/isoimage also accept:

                          FDARGS="..."  arguments for the booted kernel

                          FDINITRD=file initrd for the booted kernel



  kvm_guest.config      - Enable Kconfig items for running this kernel as a KVM guest

  xen.config            - Enable Kconfig items for running this kernel as a Xen guest

  x86_debug.config      - Enable tip tree debugging options for testing



  i386_defconfig              - Build for i386

  x86_64_defconfig            - Build for x86_64



  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build

  make V=2   [targets] 2 => give reason for rebuild of target

  make O=dir [targets] Locate all output files in "dir", including .config

  make C=1   [targets] Check re-compiled c source with $CHECK

                       (sparse by default)

  make C=2   [targets] Force check of all c source with $CHECK

  make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections

  make W=n   [targets] Enable extra build checks, n=1,2,3 where

                1: warnings which may be relevant and do not occur too often

                2: warnings which occur quite often but may still be relevant

                3: more obscure warnings, can most likely be ignored

                e: warnings are being treated as errors

                Multiple levels can be combined with W=12 or W=123



Execute "make" or "make all" to build all targets marked with [*]

For further info see the ./README file

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

AGI系列(7)Reflection 在 AI agent 中的应用实例

斯坦福大学教授吴恩达一直非常推崇AI Agent,之前他提出过AI Agent的四种工作模式,分别是Reflection(反思)、Tool use(工具使用)、Planning(规划)和Multi-agent collaboration(多智能体协同)。 近日,他又开源了一个翻译 AI Agent, 他认为 AI 智能体机器翻译对改进传…

阿里巴巴Arthas分析调优JVM实战及常量池详解

目录 一、阿里巴巴Arthas详解 Arthas使用场景 Arthas命令 Arthas使用 二、GC日志详解 如何分析GC日志 CMS G1 GC日志分析工具 三、JVM参数汇总查看命令 四、Class常量池与运行时常量池 字面量 符号引用 五、字符串常量池 字符串常量池的设计思想 三种字符串操作…

掌握电路交换与分组交换:计算机网络的核心技术

计算机网络是现代信息社会的基石,而交换技术是实现网络通信的核心。本文将详细介绍两种典型的交换方式:电路交换和分组交换,帮助基础小白快速掌握这两种技术的基本概念和区别。 什么是电路交换? 电路交换(Circuit Swi…

技术革新引领钢材质量智能化检测新纪元,基于YOLOv5全系列【n/s/m/l/x】参数模型开发构建钢材工业生产场景下钢材缺陷智能检测识别系统

随着人工智能(AI)技术的迅猛发展,其应用领域不断拓宽,正深刻改变着传统产业的运作模式。在钢材生产这一基础工业领域,AI的引入正为钢材的质量检测带来革命性的变革。 在传统的钢材生产流程中,质量检测是确…

【C++】二叉搜索树的模拟实现

前言:今天我们学习相对来说比前面轻松一点的内容,二叉搜索树,在之前我们学习过二叉树今天的内容对于我们就会比较简单一点了,一起加油。 💖 博主CSDN主页:卫卫卫的个人主页 💞 👉 专栏分类:高质…

从零开始学量化~Ptrade使用教程——安装与登录

PTrade交易系统是一款高净值和机构投资者专业投资软件,为用户提供普通交易、篮子交易、日内回转交易、算法交易、量化投研/回测/实盘等各种交易工具,满足用户的各种交易需求和交易场景,帮助用户提高交易效率。 运行环境及安装 操作系统&…

计算机的错误计算(二十一)

摘要 两个不相等数相减,差为0: ? 在计算机的错误计算(十九)中,高中生小明发现本应为0的算式结果不为0. 今天他又发现对本不为0的算式,计算机的输出为0. 在 Python 中计算 : 则输出为0. 若用 C…

必备的 Adobe XD 辅助工具

想要高效便捷的使用 Adobe XD, Adobe XD 插件是必不可少的, Adobe XD 的插件非常多,但 90%都是英文,并且良莠不齐。在这儿挑选 9 个好用的 Adobe XD 插件给大家,这里是我整理的一些实用 Adobe XD 插件,让你…

3-2 梯度与反向传播

3-2 梯度与反向传播 主目录点这里 梯度的含义 可以看到红色区域的变化率较大,梯度较大;绿色区域的变化率较小,梯度较小。 在二维情况下,梯度向量的方向指向函数增长最快的方向,而其大小表示增长的速率。 梯度的计算 …

UE5 07-给物体添加一个拖尾粒子

添加一个(旧版粒子系统)cascade粒子系统组件 ,在模板中选择一个开发学习初始包里的粒子

Elasticsearch:Ingest architectures - 摄取架构

我们提供各种采集架构,以满足各种用例和网络配置的需求。 要将数据采集到 Elasticsearch,请使用最符合你的需求和用例的选项。对于许多用户和用例来说,最简单的方法是使用 Elastic Agent 采集数据并将其发送到 Elasticsearch。Elastic Agent…

Mybatis框架的集成使用

1_框架概述 框架是一个半成品,已经对基础的代码进行了封装并提供相应的API,开发者在使用框架时直接调用封装好的api可以省去很多代码编写,从而提高工作效率和开发速度,框架是一种经过校验、具有一定功能的半成品软件. 经过校验:指…

零基础学习MySQL---库的相关操作

顾得泉:个人主页 个人专栏:《Linux操作系统》 《C从入门到精通》 《LeedCode刷题》 键盘敲烂,年薪百万! 一、创建数据库 1.语法 CREATE DATABASE [IF NOT EXISTS] db_name [create_specification [, create_specification] .…

使用selenium定位input标签下的下拉框

先来看一下页面效果&#xff1a;是一个可输入的下拉列表 再来看一下下拉框的实现方式&#xff1a; 是用<ul>和<li>方式来实现的下拉框&#xff0c;不是select类型的&#xff0c;所以不能用传统的select定位方法。 在着手定位元素前一定一定要先弄清楚下拉列表…

CocoaPodsCmake

https://juejin.cn/post/7257048145233838141?searchId20240531171431E5868B41DC7B7016CCBA https://guides.cocoapods.org CocoaPods CocoaPods的作用 帮助程序员通过命令管理第三方库及更新&#xff0c;以达到扩展项目的目的。 CocoaPods的使用 在已有的工程目录下新增…

JAVA:文件防重设计指南

1、简述 在现代应用程序中&#xff0c;处理文件上传是一个常见的需求。为了保证文件存储的高效性和一致性&#xff0c;避免重复存储相同的文件是一个重要的优化点。本文将介绍一种基于哈希值的文件防重设计&#xff0c;并详细列出实现步骤。 2、设计原理 文件防重的基本思路…

智能家居安防系统教学解决方案

前言 随着科技的不断进步和智能家居概念的深入人心&#xff0c;智能家居安防系统作为智能家居领域的重要组成部分&#xff0c;其重要性日益凸显。智能家居安防系统不仅能够提供环境和人员的监测功能&#xff0c;还能够采取措施降低或避免人员伤亡及财产损失。因此&#xff0c;…

leetcode216.组合总和III、40.组合总和II、39.组合总和

216.组合总和III 找出所有相加之和为 n 的 k 个数的组合&#xff0c;且满足下列条件&#xff1a; 只使用数字1到9 每个数字 最多使用一次 返回 所有可能的有效组合的列表 。该列表不能包含相同的组合两次&#xff0c;组合可以以任何顺序返回。 示例 1: 输入: k 3, n 7 输出…

百日筑基第十一天-看看SpringBoot

百日筑基第十一天-看看SpringBoot 创建项目 Spring 官方提供了 Spring Initializr 的方式来创建 Spring Boot 项目。网址如下&#xff1a; https://start.spring.io/ 打开后的界面如下&#xff1a; 可以将 Spring Initializr 看作是 Spring Boot 项目的初始化向导&#xff…

实训学习错误总结2

1、 "timestamp": "2024-07-04T08:43:07.15400:00", "status": 405, "error": "Method Not Allowed", "path": "/wuzi/insert" 简单的来说就是使用的方法与注释不匹配。 规定的是&#xff1a;Get&a…