Kbuilder
kbuilder は、公式にサポートされている 4 つのカーネルのうちの 1 つを、独自のオプションのパッチや設定を加えて、別のパッケージ名でローカルにビルドすることができる bash スクリプトです。
例えば、linux-lts カーネルのソースを取得し、カーネルをインテルプロセッサに最適化するパッチを適用し、そのカーネルを linux-lts-intel-optimized としてインストールすることができます。
インストール
kbuilder の取得には以下の方法があります:
- kbuilderAUR パッケージをインストールする。
- github リポジトリから最新の開発版をインストールする。
カーネルのビルド
デフォルトのバニラ linux カーネルソースを取得し、デフォルトの名前 linux-kbuilder-custom でパッケージをビルドします:
$ kbuilder build
ビルドの過程で、kbuilder は PKGBUILD に bash シェルを注入します。このシェルは build() が呼ばれる直前に実行され、パッチの追加やカーネル設定の変更をインタラクティブに行うことができます。シェルから抜けるとビルドは継続されます。
ビルドしたパッケージをインストールする:
$ kbuilder install
Build variables
Although kbuilder does not have a configuration file, you can control the build process with environment variables.
KBUILDER_SOURCE_PKGshould be set as 'linux', 'linux-lts', 'linux-zen' or 'linux-hardened'. kbuilder will fetch and build the kernel specified with this variable. Defaults to 'linux'. For more information about the official kernels, see kernel.
KBUILDER_PKG_NAME_APPENDcan be set as any string. It will be appended to the end of the kernel version and the kernel package. Defaults to 'kbuilder-custom'.
KBUILDER_BUILD_JOBSshould be set as an integer. kbuilder will replace themake allline in the PKGBUILD withmake -jX all, where X is the integer specified.
Example usage:
$ KBUILDER_BUILD_JOBS=4 KBUILDER_PKG_NAME_APPEND="my-custom-patch" KBUILDER_SOURCE_PKG="linux-zen" kbuilder build
フック
kbuilderは、/etc/kbuilder/hooks/ 内のフックを検索し、build() が呼び出される直前に、run-parts を使用してそれらを実行します。run-parts コマンドは、フラグ--regex "kbuilder-hook-*"で実行されます。
例えば以下のようなフックがあります:
/etc/kbuilder/hooks/05-kbuilder-hook-cpu-optimize.sh
#!/bin/bash
#
# kbuilder hook for applying graysky2's kernel compiler patch:
# https://github.com/graysky2/kernel_compiler_patch
#
SOURCE="https://raw.githubusercontent.com/graysky2/kernel_compiler_patch/master"
PATCH="more-uarches-for-kernel-5.17+.patch"
HOOK_NAME="cpu-optimize-hook"
curl -o $PATCH $SOURCE/$PATCH || { echo "$HOOK_NAME failed when fetching $PATCH from $SOURCE" ; exit 1 ; }
patch -Np1 -i "$PATCH" || { echo "$HOOK_NAME failed when applying $PATCH" ; exit 1 ; }
フックを作成するには、ファイル名を xx-kbuilder-hook-hookname の形式に従って作成し、実行可能属性にします。その後、xxの値に従って順次実行されます。