カーネルのコンパイル

前提環境

パーティションマウントポイント
/dev/sda1/boot
/dev/sdb5/

準備

make installでカーネルがインストールできるように設定する。

arch/x86/boot/install.shを元にして/sbin/installkernelを作成する。

#!/bin/sh
#
# arch/i386/boot/install.sh
#
# This file is subject to the terms and conditions of the GNU General Public
# License.  See the file "COPYING" in the main directory of this archive
# for more details.
#
# Copyright (C) 1995 by Linus Torvalds
#
# Adapted from code in arch/i386/boot/Makefile by H. Peter Anvin
#
# "make install" script for i386 architecture
#
# Arguments:
#   $1 - kernel version
#   $2 - kernel image file
#   $3 - kernel map file
#   $4 - default install path (blank if root directory)
#
set -x

if [ -f $4/vmlinuz ]; then
	mv $4/vmlinuz $4/vmlinuz.old
fi

if [ -f $4/System.map ]; then
	mv $4/System.map $4/System.old
fi

cat $2 > $4/vmlinuz
cp $3 $4/System.map

/boot/grub/menu.lstにひとつ前にコンパイルしたカーネルから起動するエントリを登録する。

# For booting Linux
title Linux x86_64 (sdb5)
root (hd0,0)
kernel /vmlinuz root=/dev/sdb5 apm=power-off

# For booting Linux Backup
title  Linux       (sdb5) Previous Compiled 
root (hd0,0)
kernel /vmlinuz.old root=/dev/sdb5 apm=power-off

Makefileを編集する。コンパイルオプションとカーネルのインストール先の指定など。

MAKE = make --jobs=2
KBUILD_VERBOSE = 1

カーネルのバックアップ

大きくバージョンアップするとか設定をいろいろ変えてみたい時などは明示的に現在のカーネルを保存しておく。

# cd /boot
# cp vmlinuz vmlinuz-x86_64-2.6.24.7
# cp System.map System.map-x86_64-2.6.24.7

/boot/grub/menu.lst にエントリを追加

title Linux x86_64 (sdb5) 2.6.24.7
root (hd0,0)
kernel /vmlinuz-x86_64-2.6.24.7 root=/dev/sdb5 apm=power-off

カーネルのコンパイル

基本パターン

make
sudo make install && sudo make modules_install