CentOS

2006/1/18 06:37 PM 更新

カーネルの再構築

Kernelを再構築する方法としては以下の方法がある。
  ・RPMでKernelをアップデート
  ・KernelのソースRPMを入手して再構築
  ・Kernelソースを入手して再構築

Kernel2.6系や最新のKernelにしたい場合などはKernelソースを入手して再構築する必要があるが、 今回はそこまで大きな変更をしたいわけではないので、KernelのソースRPMを使って再構築する。

yumを使ってKernelのソースRPMをインストールする。
# yum -y install kernel-source.i386
Gathering header information file(s) from server(s)
Server: CentOS-3 - Addons
Server: CentOS-3 - Base
Server: CentOS-3 - Extras
Server: CentOS-3 - Updates
Finding updated packages
Downloading needed headers
Resolving dependencies
Dependencies resolved
I will do the following:
[install: kernel-source 2.4.21-27.0.2.EL.i386]
Downloading Packages
Getting kernel-source-2.4.21-27.0.2.EL.i386.rpm
kernel-source-2.4.21-27.0 100% |=========================| 41 MB 00:50
Running test transaction:
Test transaction complete, Success!
kernel-source 100 % done 1/1
Installed: kernel-source 2.4.21-27.0.2.EL.i386
Transaction(s) Complete
Kernelソースがあるディレクトリに移動する。
# cd /usr/src/linux-2.4
以前にKernelを再構築したことがある場合は設定ファイルである.configファイルが作成されているので 再構築前にバックアップをとっておく。
# mv .config .config.BAK
再構築時のオプションを設定する。
  /usr/src/linux-2.4/Makefile
EXTRAVERSION = -27.0.2.EL-050327Rebuild
export INSTALL_PATH=/boot
再構築環境の初期化をする。
※現在の設定のまま再構築したい場合は実行する必要はない。
# make mrproper
システムのアーキテクチャ用ファイルをコピーする。
※ただしこれはデフォルトの設定ファイルなので現在の設定とは異なるものである。
# ls /usr/src/linux-2.4/configs
kernel-2.4.21-athlon-smp.config        kernel-2.4.21-ia32e.config
kernel-2.4.21-athlon.config                kernel-2.4.21-ia64.config
kernel-2.4.21-i386-BOOT.config         kernel-2.4.21-ppc64.config
kernel-2.4.21-i386.config                   kernel-2.4.21-ppc64iseries.config
kernel-2.4.21-i586-smp.config           kernel-2.4.21-ppc64pseries.config
kernel-2.4.21-i586.config                   kernel-2.4.21-s390.config
kernel-2.4.21-i686-hugemem.config  kernel-2.4.21-s390x.config
kernel-2.4.21-i686-smp.config           kernel-2.4.21-x86_64-smp.config
kernel-2.4.21-i686.config                   kernel-2.4.21-x86_64.config

# cp configs/kernel-2.4.21-i686.config .config
現在のKernelの設定を基に再構築したい場合は次のようにする。
今動いているカーネルの設定ファイルをコピー
# cp /boot/config-xx.xx.xx /usr/src/linux-2.4/.config
# make oldconfig
CUI環境でカーネル設定を行う。
# make menuconfig

(省略)

dialog.h:29:20: curses.h: そのようなファイルやディレクトリはありません

(省略)

dialog.h:130: 警告: 配列 `attributes' は一要素を持っているものと見なされます
make[1]: *** [checklist.o] エラー 1
make[1]: 出ます ディレクトリ `/usr/src/linux-2.4.21-27.0.2.EL/scripts/lxdialog'
make: *** [menuconfig] エラー 2

以下のパッケージがインストールされていない場合はこのようなエラーが出る。
  ・ncurses
  ・ncurses-devel

インストールされていない場合はyum経由でインストールする。
# yum -y install ncurses-devel
Gathering header information file(s) from server(s)
Server: CentOS-3 - Addons
Server: CentOS-3 - Base
Server: CentOS-3 - Extras
Server: CentOS-3 - Updates
Finding updated packages
Downloading needed headers
Resolving dependencies
Dependencies resolved
I will do the following:
[install: ncurses-devel 5.3-9.3.i386]
Downloading Packages
Getting ncurses-devel-5.3-9.3.i386.rpm
ncurses-devel-5.3-9.3.i38 100% |=========================| 1.5 MB    00:01
Running test transaction:
Test transaction complete, Success!
ncurses-devel 100 % done 1/1
Installed:  ncurses-devel 5.3-9.3.i386
Transaction(s) Complete

設定したいメニュー項目をそれぞれ設定する。
今回はBridgeモードを有効にするので以下の項目を設定する。
  ・Networking options ---> <M> 802.1d Ethernet Bridging
  ・Networking options ---> IP: Netfilter Configuration ---> <M> Packet filtering

設定が終了したら保存して終了。
Saving your kernel configuration...

*** End of Linux kernel configuration.
*** Check the top-level Makefile for additional configuration.
*** Next, you must run 'make dep'.
設定が終わったらKernelを再構築する。
# make dep                               依存性チェック
# make clean                             ツリーソースの作成
# make bzImage                        カーネルの構築
# make modules                        モジュールの構築
# make modules_install               モジュールのインストール

下記のどちらかを実行
# make install                         カーネルのインストール
# installkernel 2.4.21-27.0.2.EL-050327Rebuild arch/i386/boot/bzImage System.map
Kernelのインストール後、再構築後のカーネルで起動するためGRUBの設定を変更する。
  /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/hde5
#          initrd /initrd-version.img
#boot=/dev/hde
#default=1
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title CentOS (2.4.21-27.0.2.EL-050327Rebuild)
        root (hd0,0)
        kernel /vmlinuz-2.4.21-27.0.2.EL-050327rebuild ro root=LABEL=/
        initrd /initrd-2.4.21-27.0.2.EL-050327rebuild.img
title CentOS-3 (2.4.21-27.0.2.EL)
        root (hd0,0)
        kernel /vmlinuz-2.4.21-27.0.2.EL ro root=LABEL=/
        initrd /initrd-2.4.21-27.0.2.EL.img
OSを再起動し、再構築したKernelで起動する。 起動後、新Kernelで起動しているか確認する。
# uname -a
Linux boris 2.4.21-27.0.2.EL-050327Rebuild #1 Wed Jan 19 02:20:34 GMT 2005 i686 i686 i386 GNU/Linux