最終更新:2022-10-12 (水) 11:07:12 (562d)  

Linuxカーネル/ビルド
Top / Linuxカーネル / ビルド

初めて

注意

  • 新しくダウンロードし解凍したカーネルソースは、/usr/srcに置かないでください。
    /usr/srcに置くよう指示する人もいますが、その指示に耳を傾けてはいけません。
  • カーネルのREADMEファイルでは、次のように説明しています。
    「...カーネルのtarballを、自分が権限を持つディレクトリ(たとえば自分のホームディレクトリ)に置いてください

Linux Kernel Newbies

EXTRAVERSION

  • 自分でコンパイルしたカーネルにオリジナルの拡張バージョンを付けたい場合はMakefileを開いて4行目
    EXTRAVERSION = 
  • の後に任意の文字列を追加すればOK

概要

まずはクリーン

ビルド

  • カーネルのあるディレクトリでmake *configして.config(カーネルの設定ファイル)を生成
  • その後makeするとカーネルがビルドされる
    cd /usr/src/linux
    make menuconfig
    make
    make install

出力フォルダを指定

  • cd /usr/src/linux-4.X
    make O=/home/name/build/kernel menuconfig
    make O=/home/name/build/kernel
    sudo make O=/home/name/build/kernel modules_install install

処理のステップ

  • 1) Configuration of the kernel => produce .config
  • 2) Store kernel version in include/linux/version.h
  • 3) Symlink include/asm to include/asm-$(ARCH)
  • 4) Updating all other prerequisites to the target prepare:
  • 5) Recursively descend down in all directories listed in init-* core* drivers-* net-* libs-* and build all targets.
  • 6) All object files are then linked and the resulting file vmlinux is located at the root of the obj tree.
    • The very first objects linked are listed in head-y, assigned by arch/$(ARCH)/Makefile.
  • 7) Finally, the architecture-specific part does any required post processing and builds the final bootimage.
    • This includes building boot records
    • Preparing initrd images and the like

Linuxカーネル/make

.config

CentOS,Fedora

  • 標準だとソースコードを含むパッケージが用意されていないのでrpmから抽出する
    yum install rpmdevtools yum-utils
    rpmdev-setuptree
    yumdownloader --source kernel
    yum-builddep kernel-<version>.src.rpm
    rpm -Uvh kernel-<version>.src.rpm
    cd ~/rpmbuild/SPECS
    rpmbuild -bp --target=$(uname -m) kernel.spec
    cp configs/kernel-<version>.config .config
    make oldconfig

コマンド

参考

ディストリビューション別ドキュメント

CentOS Wiki

Fedora Project Wiki

Ubuntu Documentation

Debian Wiki

Linux 2.6

関連

Linux/カーネルモジュール/ビルド

参考