Manjaro內核編譯


本文通過MetaWeblog自動發布,原文及更新鏈接:https://extendswind.top/posts/technical/manjaro_kernel_compile

重新編譯內核可以修改編譯時的參數,使內核在運行時更高效的支持本地硬件。Manjaro團隊在gitlab上放了Manjaro內核的編譯文件,稍加修改即可使用自己的選項編譯。

主要參考論壇中Manjaro團隊的philm的回答 https://forum.manjaro.org/t/how-to-compile-the-mainline-kernel-the-manjaro-way/51700/35

Gitlab 倉庫

philm提到了manjaro在gitlab上編譯內核的倉庫。https://gitlab.manjaro.org/packages/core/linux56.git 后面使用不同的linux版本號。

倉庫文件介紹

倉庫中不同后綴文件的作用

  • files ending with .patch should be clear. These are adjustments we think will fit for our distro best.
  • files starting with config are our modified settings on how we configure the kernel on our end.
  • files starting with linux are specific files to post configure the system. They are used either by pacman or mkinitcpio, which configures the initramfs image.
  • files ending with .hook are used by pacman to pre- or post-configure the kernel.

主要的腳本文件為PKGBUILD,指定了包中包含的文件,需要執行的操作等。

內核編譯參數的設置在config.x86_64文件中,需要改變的參數可以在這里修改。(PKGBUILD中新建了.config文件並將config.x86_64文件的內如cat進入)

主要編譯過程

So here is a quick tutorial to compile your own kernel on Manjaro:

first you have to clone our package repo for linux417 via git clone https://gitlab.manjaro.org/packages/core/linux417.git

then change into that directory and execute makepkg -s. This will compile the kernel as I had configured it. You may want to stop the time.

If you however want to use our tools, you may install manjaro-tools-pkg and only change into the directory where you cloned the git-repo. No need to change into the linux417 folder. You simply may use then buildpkg -p linux417. This will create a new chroot on which the package gets compiled in a separate system to avoid any issues with other systems. Only used if you want to redistribute your package to somebody else.

大概流程為:

  1. git clone對應的倉庫
  2. 修改編譯參數config.x86_64
  3. makepkg編譯內核

國內可能存在git下載代碼非常慢的問題,可以通過網頁端或其它鏡像站下載代碼文件到指定目錄,然后修改PKGBUILD文件,將source=(后的鏈接替換成下載后的文件名。如果內核代碼或其它文件(config.x86_64)修改過,還需要將sha256sums=(后的對應位置改為'SKIP'或者計算后的值。

為了避免編譯器版本等造成的環境問題,manjaro還提供了manjaro-tool-pkg,在倉庫所在的目錄運行buildpkg -p linux56會新安裝一個新的環境然后chroot使用獨立的環境構建。

最好給新編譯的內核一個重新的命名,否則在安裝時會覆蓋同名稱的官方內核。需要改命令的地方不止在PKGBUILD,具體在哪也懶得找了…

[optional] give your kernel a different name so it can be easily installed alongside existing ones. For that, you have to replace every instance of -MANJARO with a name of your choice, this in every file, not only in PKGBUILD! You could use a simple ‘find and replace’ in your text editor, or use the sed command, e.g. sed -i -e “s|-MANJARO|-CUSTOM|” PKGBUILD. You also have to edit various other names, like

修改內核參數

zcat /proc/config.gz > .config 導出當前內核的配置。

在linux內核代碼目錄通過make可以得到內核的設置參數或設置界面:

  • make localmodconfig 獲取當前的內核參數,這種方法能夠得到一個非常精簡的內核,但沒有加載過的內核模塊都不會被編譯。(在我的筆記本上內核大小成了之前的25%,但是睡眠出問題)
  • make nconfig: 新的命令行 ncurses 界面
  • make xconfig: 用戶友好的圖形界面,需要安裝 packagekit-qt4[斷開的鏈接:package not found]。建議沒有經驗的用戶使用此方法。
  • make gconfig: 和 xconfig 類似的圖形界面,使用 gtk.

運行后會生成一個新的.config文件,將文件覆蓋config.x86_64后,直接makepkg即可。

一些內核參數可以參考gentoo的wiki:

https://wiki.gentoo.org/wiki/Handbook:X86/Installation/Kernel


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM