LINUX内核的配置与编译、安装

平台为VM RHEL 5.1 SERVER,所用的内核为linux-2.6.25

可以到上下载相应的内核版本。

解压压缩包,并进入内核目录。下面是具体的步骤:

1、  找到你要参考的配置文件,如:/boot/config-2.6.18-53.e15

[root@localhost linux-2.6.25]# cp /boot/config-2.6.18-53.el5 /home/suruiqin/linux-2.6.25/.config

也可使用默认的配置文件

2、配置内核

[root@localhost linux-2.6.25]#make menuconfig

3、  编译内核

[root@localhost linux-2.6.25]# make bzImage

   或者:make zImage

区别:在X86平台,zImage只能用于小于512K的内核

如需获取详细的编译信息,可使用:

     make zImage V=1

     make bzImage V=1

编译好的内核位于arch/<cpu>/boot/ 目录下

4、编译内核模块

[root@localhost linux-2.6.25]# make modules

5、安装内核模块

[root@localhost linux-2.6.25]# make modules_install

       执行这个命令后,将编译好的内核模块从内核源代码目录copy/lib/modules

6、制作init ramdisk

       注:要进入要编译的内核文件目录下

       mkinitrd initrd-$version $version

       例:

[root@localhost linux-2.6.25]# cd /home/suruiqin/linux-2.6.25

       [root@localhost linux-2.6.25]# mkinitrd initrd-2.6.25 2.6.25

       *** $version 可以通过查询/lib/modules下的目录得到

7、内核安装(X86平台)

       1cp arch/x86/boot/bzImage /boot/vmlinuz-$version

       如:

[root@localhost linux-2.6.25]# cp arch/x86/boot/bzImage /boot/vmlinuz-2.6.25

          ***$version 为所编译的内核版本号

 

       2cp $initrd /boot/

如:

[root@localhost linux-2.6.25]# cp initrd-2.6.25 /boot

 

       3)修改 /etc/grub.conf /etc/lilo.conf

 

如:

[root@localhost ~]# gedit /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/sda2

#          initrd /initrd-version.img

#boot=/dev/sda

default=0

timeout=5

splashp_w_picpath=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

title Red Hat Enterprise Linux Server (2.6.18-53.el5)

       root (hd0,0)

       kernel /vmlinuz-2.6.18-53.el5 ro root=LABEL=/ rhgb quiet

       initrd /initrd-2.6.18-53.el5.img

 

title Red Hat Enterprise Linux Server (2.6.25)

       root (hd0,0)

       kernel /vmlinuz-2.6.25 ro root=LABEL=/ rhgb quiet

       initrd /initrd-2.6.25

注:红色部分就是为启动刚才自己做的内核而加上的

到这步时按回车,出现下面的选项:

 

 

选择第二个启动,即刚才做的内核。

 

新建一个终端:

[root@localhost ~]# uname -a

Linux localhost.localdomain 2.6.25 #1 SMP Mon Jun 4 05:26:03 PDT 2012 i686 i686 i386 GNU/Linux

 

OK