Email: zcatt@163.com
Blog http://zcatt.blog.chinaunix.net
声明
仅限学习交流,禁止商业用途。转载需注明出处。
版本记录
Date Ver Note
2011-06-09 0.1 Draft. zcatt, Beijing
环境: fedora 12, kernel 2.6.31.5
在执行完 all , modules和modules_install后,
- make all modules modules_install
可以使用安装kernel到boot了. 注意install过程需要mkinitrd这个package, 应当yum install安装先.
- make install
在kernel脚本arch/x86/boot/Makefile中, 是这样定义install target的. 就是调用install.sh
- install:
- sh $(srctree)/$(src)/install.sh $(KERNELRELEASE) $(obj)/bzImage \
- System.map "$(INSTALL_PATH)"
而arch/x86/boot/install.sh如下. 继而调用/sbin/installkernel
- #!/bin/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)
- #
-
- verify () {
- if [ ! -f "$1" ]; then
- echo "" 1>&2
- echo " *** Missing file: $1" 1>&2
- echo ' *** You need to run "make" before "make install".' 1>&2
- echo "" 1>&2
- exit 1
- fi
- }
-
- # Make sure the files actually exist
- verify "$2"
- verify "$3"
-
- # User may have a custom install script
-
- if [ -x ~/bin/${CROSS_COMPILE}installkernel ]; then exec ~/bin/${CROSS_COMPILE}installkernel "$@"; fi
- if [ -x /sbin/${CROSS_COMPILE}installkernel ]; then exec /sbin/${CROSS_COMPILE}installkernel "$@"; fi
-
- # Default install - same as make zlilo
-
- 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
-
- if [ -x /sbin/lilo ]; then
- /sbin/lilo
- elif [ -x /etc/lilo/install ]; then
- /etc/lilo/install
- else
- sync
- echo "Cannot find LILO."
- fi
installkernel会将arch/x86/boot/bzImage拷贝到/boot/vmLinuz-$KERNEL_VERSION, 而arch/x86/boot/System.map拷贝到/boot/System.map-$KERNEL_VERSION. 并建立softlink.
随后installkernel会调用
/sbin/new-kernel-pkg --mkinitrd --depmod --install $KERNEL_VERSION
/sbin/new-kernel-pkg --rpmposttrans $KERNEL_VERSION
完成对grub的配置. new-kernel-pkg中使用的是grubby这个工具. 配置的内容体现在/boot/grub/grub.conf中. 我机器上的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/mapper/vg_zfkernel-lv_root
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=1
timeout=6
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Fedora (2.6.31.mykernel)
root (hd0,0)
kernel /vmlinuz-2.6.31.mykernel ro root=/dev/mapper/vg_zfkernel-lv_root LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us rhgb quiet
initrd /initrd-2.6.31.mykernel.img
title Fedora (2.6.31.5-127.fc12.i686.PAE)
root (hd0,0)
kernel /vmlinuz-2.6.31.5-127.fc12.i686.PAE ro root=/dev/mapper/vg_zfkernel-lv_root LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us rhgb quiet
initrd /initramfs-2.6.31.5-127.fc12.i686.PAE.img