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 helpCleaning targets:clean           - Remove most generated files but keep the config andenough build support to build external modulesmrproper        - Remove all generated files + config + various backup filesdistclean       - mrproper + remove editor backup and patch filesConfiguration targets:config          - Update current config utilising a line-oriented programnconfig         - Update current config utilising a ncurses menu based programmenuconfig      - Update current config utilising a menu based programxconfig         - Update current config utilising a Qt based front-endgconfig         - Update current config utilising a GTK+ based front-endoldconfig       - Update current config utilising a provided .config as baselocalmodconfig  - Update current config disabling modules not loadedexcept those preserved by LMC_KEEP environment variablelocalyesconfig  - Update current config converting local mods to coreexcept those preserved by LMC_KEEP environment variabledefconfig       - New config with default from ARCH supplied defconfigsavedefconfig   - Save current config as ./defconfig (minimal config)allnoconfig     - New config where all options are answered with noallyesconfig    - New config where all options are accepted with yesallmodconfig    - New config selecting modules when possiblealldefconfig    - New config with all symbols set to defaultrandconfig      - New config with random answer to all optionsyes2modconfig   - Change answers from yes to mod if possiblemod2yesconfig   - Change answers from mod to yes if possiblemod2noconfig    - Change answers from mod to no if possiblelistnewconfig   - List new optionshelpnewconfig   - List new options and help textolddefconfig    - Same as oldconfig but sets new symbols to theirdefault value without promptingtinyconfig      - Configure the tiniest possible kerneltestconfig      - 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 modulesmodules_install - Install all modules to INSTALL_MOD_PATH (default: /)dir/            - Build all files in dir and belowdir/file.[ois]  - Build specified target onlydir/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 linkmodules_prepare - Set up for building external modulestags/TAGS       - Generate tags file for editorscscope          - Generate cscope indexgtags           - Generate GNU GLOBAL indexkernelrelease   - 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 hogsversioncheck    - Sanity check on version.h usageincludecheck    - Check for duplicate included header filesexport_report   - List the usages of all exported symbolsheaderdep       - Detect inclusion cycles in headerscoccicheck      - Check with Coccinelleclang-analyzer  - Check with clang static analyzerclang-tidy      - Check with clang-tidyTools:nsdeps          - Generate missing symbol namespace dependenciesKernel selftest:kselftest         - Build and run kernel selftestBuild, install, and boot kernel beforerunning kselftest on itRun as root for full coveragekselftest-all     - Build kernel selftestkselftest-install - Build and install kernel selftestkselftest-clean   - Remove all generated kselftest fileskselftest-merge   - Merge all the config dependencies ofkselftest to existing .config.Rust targets:rustavailable   - Checks whether the Rust toolchain isavailable and, if not, explains why.rustfmt         - Reformat all the Rust code in the kernelrustfmtcheck    - Checks if all the Rust code in the kernelis 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 onlydir/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 fileUserspace tools targets:use "make tools/help"or  "cd tools; make help"Kernel packaging:rpm-pkg             - Build both source and binary RPM kernel packagesbinrpm-pkg          - Build only the binary kernel RPM packagedeb-pkg             - Build both source and binary deb kernel packagesbindeb-pkg          - Build only the binary kernel deb packagesnap-pkg            - Build only the binary kernel snap package(will connect to external hosts)dir-pkg             - Build the kernel as a plain directory structuretar-pkg             - Build the kernel as an uncompressed tarballtargz-pkg           - Build the kernel as a gzip compressed tarballtarbz2-pkg          - Build the kernel as a bzip2 compressed tarballtarxz-pkg           - Build the kernel as a xz compressed tarballtarzst-pkg          - Build the kernel as a zstd compressed tarballperf-tar-src-pkg    - Build perf-6.1.55.tar source tarballperf-targz-src-pkg  - Build perf-6.1.55.tar.gz source tarballperf-tarbz2-src-pkg - Build perf-6.1.55.tar.bz2 source tarballperf-tarxz-src-pkg  - Build perf-6.1.55.tar.xz source tarballperf-tarzst-src-pkg - Build perf-6.1.55.tar.zst source tarballDocumentation targets:Linux kernel internal documentation in different formats from ReST:htmldocs        - HTMLlatexdocs       - LaTeXpdfdocs         - PDFepubdocs        - EPUBxmldocs         - XMLlinkcheckdocs   - check for broken external links(will connect to external hosts)refcheckdocs    - check for references to non-existing files underDocumentationcleandocs       - clean all generated filesmake SPHINXDIRS="s1 s2" [target] Generate only docs of folder s1, s2valid 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 xtensamake SPHINX_CONF={conf-file} [target] use *additional* sphinx-buildconfiguration. 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/outputArchitecture 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 lilofdimage               - 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 kernelFDINITRD=file initrd for the booted kernelkvm_guest.config      - Enable Kconfig items for running this kernel as a KVM guestxen.config            - Enable Kconfig items for running this kernel as a Xen guestx86_debug.config      - Enable tip tree debugging options for testingi386_defconfig              - Build for i386x86_64_defconfig            - Build for x86_64make V=0|1 [targets] 0 => quiet build (default), 1 => verbose buildmake V=2   [targets] 2 => give reason for rebuild of targetmake O=dir [targets] Locate all output files in "dir", including .configmake C=1   [targets] Check re-compiled c source with $CHECK(sparse by default)make C=2   [targets] Force check of all c source with $CHECKmake RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sectionsmake W=n   [targets] Enable extra build checks, n=1,2,3 where1: warnings which may be relevant and do not occur too often2: warnings which occur quite often but may still be relevant3: more obscure warnings, can most likely be ignorede: warnings are being treated as errorsMultiple levels can be combined with W=12 or W=123Execute "make" or "make all" to build all targets marked with [*]For further info see the ./README file

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

前端面试题5(前端常见的加密方式)

前端常见的加密方式 在前端进行数据加密主要是为了保护用户的隐私和提升数据传输的安全性。前端数据加密可以采用多种方法,以下是一些常见的加密技术和方法: 1. HTTPS 虽然不是直接的前端加密技术,但HTTPS是保障前端与后端数据传输安全的基…

关于MCU-Cortex M7的存储结构(flash与SRAM)

MCU并没有DDR,所以他把代码存储在flash上,临时变量和栈运行在SRAM上。之所以这么做是因为MCU的cpu频率很低,都是几十MHZ到一二百MHZ,flash的读取速度能够满足cpu 的取指需求,但flash 的写入速度很慢,所以引…

刚办理的手机号被停用,你可能遇到这些问题了!

很多朋友都会遇到手机号被停用的情况,那么你知道你的手机号为什么会被停用吗?接下来,关于手机号被停用的问题,跟着小编一块来了解一下吧。 ​停机的两种形态: 1、第一个是局方停机,即语音、短信和流量都不…

xmind2testcase工具将测试用例从Xmind转为CSV导入禅道

使用xmind编写测试用例,使用xmind2testcase工具将测试用例从Xmind转为CSV导入禅道,便于管理。 1.工具准备 第一步:安装python 第二步:安装xmind2testcase工具 运行-cmd-打开命令提示符弹窗,输入安装命令 安装命令&…

意图数据集HWU、Banking预处理

当谈到意图数据集时,HWU、Banking和Clinc是三个常见的数据集。以下是关于这三个数据集的介绍: 目录 一、数据集介绍 HWU数据集 Banking数据集 Clinc数据集 二、数据集预处理 数据处理 数据存储 数据类别分析 句子长度统计 一、数据集介绍 HW…

嵌入式硬件电路常用设计软件

目录 1. Cadence Allegro 2. PADS 3. Altium Designer 4. Multisim 5. Protues 1. Cadence Allegro 功能: Cadence Allegro是Cadence公司推出的先进PCB(Printed Circuit Board,印刷电路板)设计布线工具,也是目前…

华为HCIP Datacom H12-821 卷26

1.单选题 在VRRP中,同一备份组的设备在进行VRRP报文认证时,以下哪一参数不会影响Master设备和Backup设备认证协商结果 A、认证字 B、优先级 C、认证方式 D、VRRP版本 正确答案: B 解析: 优先级只会影响谁是主谁是备&…

AI产品经理能力模型的重点素质:人文素养和灵魂境界

在AI产品经理的能力模型中,我最想提的差异化关键点,就是“人文素养和灵魂境界”。 1 为什么“人文素养和灵魂境界”非常重要? 一、“人文素养和灵魂境界”如何影响AI产品设计? 例1:面对一个具体的AI场景&#xff0…

25考研,数二全程跟的张宇老师请问660(做了一半)880和张宇1000题应该怎么选择?

跟张宇老师,也可以做其他的题集,不一定非要做1000题 我当初考研复习的时候,也听了张宇老师的课程,但是我并没有做1000题 因为1000题对于我来说太难了。做了一章之后,就换成其他的题目了。 对于大家来说,…

【机器学习实战】Baseline精读笔记

比赛用到的库 numpy:提供(多维)数组操作 pandas:提供数据结构、数据分析 catboost:用于机器学习的库,特别是分类和回归任务 sklearn.model_selection:包含模型选择的多种方法,如交…

Android 监听网络状态变化(无切换中间态版)

需求: 获取当前的网络状态与类型(WIFI、数据流量)监听网络状态真正变化监听网络类型发生变化 业务场景: 用户打开 App 时、使用过程中,出现无网络时,显示 Toast 提示。但当 wifi、数据流量 互相切换的过…

ppt接单渠道大公开‼️

PPT 接单主要分两种:PPT 模板投稿和PPT 定制接单,我们先从简单的 PPT 模板投稿说起。 PPT 模板投稿 利用业余时间,做一些 PPT 模板上传到平台,只要有人下载你的模板,你就有收入。如果模板质量高,简直就是一…

【设计模式】观察者模式(定义 | 特点 | Demo入门讲解)

文章目录 定义结构Demo | 代码Subject目标类Observer抽象观察者观察者1 | CPU监听器观察者2 | 内存监听器客户端 | Client 优点适合场景 定义 所谓观察者模式就是你是被观察的那个对象,你爸爸妈妈就是观察者,一天24h盯着你,一旦你不听话&…

【BUUCTF-PWN】7-[第五空间2019 决赛]PWN5

参考:BUU pwn [第五空间2019 决赛]PWN5 //格式化字符串漏洞 - Nemuzuki - 博客园 (cnblogs.com) 格式化字符串漏洞原理详解_printf 任意内存读取-CSDN博客 32位小端排序,有栈溢出保护 运行效果: 查看main函数 存在格式化字符串漏洞 输…

SQL二次注入原理分析

二次注入在测试的时候比较少见,或者说很难被测出来,因为测的时候首先要去找注入的位置,其次是去判断第一次执行的SQL语句,然后还要去判断第二次进行调用的 SQL 语句。而关键问题就出在第二次的调用上面。 下面以一个常用过滤方法…

macos下搭建minikube dashboard的启动

背景 最近在复习一下k8s环境相关的知识,需要在自己电脑上搭建一个minikube的环境供自己使用。但是因为docker的镜像仓库最近被墙了,因此在执行minikube dashboard的时候,拉不到相应的镜像,就导致页面看不到相应的一些信息因此本文…

【PYG】dataloader和densedataloader

DenseDataLoader 是专门用于处理稠密图数据的,而 DataLoader 通常用于处理稀疏图数据。两者的主要区别在于它们的输入数据格式和处理方式。DenseDataLoader 适合处理固定大小的邻接矩阵和节点特征矩阵的数据,而 DataLoader 更加灵活,可以处理…

flask中解决图片不显示的问题(很细微的点)

我在编写flask项目的时候,在编写html的时候,发现不管我的图片路径如何变化,其就是显示不出来。如下图我框中的地方。 我尝试过使用浏览器打开,是可以的。 一旦运行这个flask项目,就无法显示了。 我查阅资料后。发现…

简易版async/await

参考:https://juejin.cn/post/7007031572238958629?searchId20240704101813568E9B5B1013C881A239#heading-15 总结一下async/await的知识点 1、 await只能在async函数中使用,不然会报错 2、 async函数返回的是一个Promise对象,有无值看有…

泛微开发修炼之旅--29用计划任务定时发送邮件提醒

文章链接:29用计划任务定时发送邮件提醒