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

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

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 为什么要进行垃圾回收器的调优
  • ggplot2绘图点的形状不够用怎么办?
  • django基于个人BMI的健康饮食食谱推荐系统-计算机毕业设计源码26624
  • [Debugger]调试Arm设备
  • nginx配置代理
  • 基于FPGA的千兆以太网设计(1)----大白话解释什么是以太网
  • 每日新闻 7月9日 星期二
  • uniapp开发android调试工具
  • 【前端】使用chrom浏览器Network,查看前后台数据传输请求
  • 系统架构的基础:定义、原则与发展历程
  • C语言 输出n阶魔方阵
  • 语法糖:代码中的甜品
  • 世上最懂交易原理的是佛学
  • VS2019运行报错 应输入预处理器指令
  • 通信网络机房服务器搬迁方案要求
  • IE9 : DOM Exception: INVALID_CHARACTER_ERR (5)
  • [iOS]Core Data浅析一 -- 启用Core Data
  • 0基础学习移动端适配
  • angular组件开发
  • Hexo+码云+git快速搭建免费的静态Blog
  • Hibernate最全面试题
  • jQuery(一)
  • Laravel 菜鸟晋级之路
  • pdf文件如何在线转换为jpg图片
  • Protobuf3语言指南
  • React-redux的原理以及使用
  • Vue.js-Day01
  • XForms - 更强大的Form
  • 闭包,sync使用细节
  • 离散点最小(凸)包围边界查找
  • 前端自动化解决方案
  • 使用 QuickBI 搭建酷炫可视化分析
  • 事件委托的小应用
  • 手机app有了短信验证码还有没必要有图片验证码?
  • 小而合理的前端理论:rscss和rsjs
  • - 语言经验 - 《c++的高性能内存管理库tcmalloc和jemalloc》
  • 自定义函数
  • linux 淘宝开源监控工具tsar
  • Mac 上flink的安装与启动
  • 机器人开始自主学习,是人类福祉,还是定时炸弹? ...
  • 摩拜创始人胡玮炜也彻底离开了,共享单车行业还有未来吗? ...
  • ​Java并发新构件之Exchanger
  • # Panda3d 碰撞检测系统介绍
  • #宝哥教你#查看jquery绑定的事件函数
  • #多叉树深度遍历_结合深度学习的视频编码方法--帧内预测
  • (arch)linux 转换文件编码格式
  • (html5)在移动端input输入搜索项后 输入法下面为什么不想百度那样出现前往? 而我的出现的是换行...
  • (windows2012共享文件夹和防火墙设置
  • (笔记)M1使用hombrew安装qemu
  • (论文阅读22/100)Learning a Deep Compact Image Representation for Visual Tracking
  • (十六)一篇文章学会Java的常用API
  • (学习日记)2024.03.12:UCOSIII第十四节:时基列表
  • (一)RocketMQ初步认识
  • (译)2019年前端性能优化清单 — 下篇
  • (转)Android学习笔记 --- android任务栈和启动模式