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.pswp.cn/web/39949.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/39949.shtml
英文地址,請注明出處:http://en.pswp.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用計劃任務定時發送郵件提醒