Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4008578
  • 博文数量: 536
  • 博客积分: 10470
  • 博客等级: 上将
  • 技术积分: 4825
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-26 14:08
文章分类

全部博文(536)

文章存档

2024年(3)

2021年(1)

2019年(1)

2017年(1)

2016年(2)

2013年(2)

2012年(10)

2011年(43)

2010年(10)

2009年(17)

2008年(121)

2007年(252)

2006年(73)

分类: LINUX

2007-08-01 23:05:27

This guide describes the procedure I used to compile the Linux kernel on my workstation, which runs Redhat Linux 7.2.
 1. Download kernel sources
You can download the latest Linux kernel sources at . Do not discard the old kernel sources, but change the directory name to another one.

Now put your kernel sources at /usr/src/. As root, unpack the tarball, and then make (or change) the symbolic link to it as

ln -s linux-2.4.xx linux
 2. Preparation
Before compiling the kernel, you need to gether some information about your system. You need to know what file systems are used, what hardware devices are on your system, etc. Most of the device drivers are compiled as modules. You can find what device drivers are currently up and running on your system by using command lsmod . When you configure the kernel, you can safely select these drivers to be compiled as modules. Following is an example of the lsmod result on my computer.

$ lsmod
Module                  Size  Used by
sr_mod                 15360   0 (autoclean)
es1370                 25440   0 (autoclean)
gameport                1936   0 (autoclean) [es1370]
soundcore               4464   4 (autoclean) [es1370]
r128                   87264   1
agpgart                27584   3
binfmt_misc             6416   1
autofs                 11520   0 (autoclean) (unused)
tulip                  39232   1
ipchains               39200   0
ide-scsi                8224   0
scsi_mod               95696   2 [sr_mod ide-scsi]
ide-cd                 27072   0
cdrom                  28512   0 [sr_mod ide-cd]
nls_iso8859-1           2832   1 (autoclean)
nls_cp437               4352   1 (autoclean)
vfat                    9584   1 (autoclean)
fat                    32384   0 (autoclean) [vfat]
usb-uhci               21536   0 (unused)
usbcore                51712   1 [usb-uhci]
ext3                   64624   2
jbd                    40992   2 [ext3]

Note: Tulip is the chipset of my network card. It's important for me to know it. When you configure the kernel, you will select the same device driver.
 3. Configuration
This is the most difficult part for kernel compilation. To start configuration, change to /usr/src/linux and type make menuconfig or make xconfig . If you have previously configured the kernel, the configuration is saved in a file .config . You can load in this file to start your configuration based on what you have done last time.

For each item, there is a help that you should look at. There some thing that you need to notice when select each item.

    * Compile the support for your harddisk controller and your native file system (ext2) into kernel. Don't compile them as modules.
    * You can select EXT3 Journalling file system support as a module. See the result of lsmod.
    * You should select MS dos fat fs support and vfat (windows) fs support as modules if you mount a windows partition.
    * Be sure to compile sound card support as a module. If not, you can't use sndconfig to configure your sound card later.
    * You can select support for USB as a module. And you should select 'y' to enable preliminary USB device file system.

4. Compile kernel and modules
After you are done with kernel configuration, use the following command to compile the kernel.

make dep
make clean
make bzImage

The new kernel is named bzImage, and it is stored at /usr/src/linux/arch/i386/boot/bzImage. The current kernel is normally  /boot/vmlinuz.
you should copy the new kernel to the /boot directory and give a new name. For example

cp /usr/src/linux/arch/i386/boot/bzImage /boot/vmlinuz-2.4.xx

Don't forget to compile and install the modules. You can do it by

make modules
make modules_install
5. Configure grub or lilo, the boot loader
To boot the new kernel you should add a new entry to grub or lilo, depending on which you are using. To do it, edit the file /etc/grub.conf or /etc/lilo.conf.

For example, in /etc/grub, you can add the following entry. (suppose you just compiled the kernel version 2.4.17)

title Red Hat Linux (2.4.17)
        root (hd0,1)
        kernel /boot/vmlinuz-2.4.17 ro root=/dev/hda2

Now you can reboot your machine and select to boot the new kernel at the menu of grub or lilo. If new kernel cannot boot correctly, you can press ctrl+alt+del to reboot and select the old kernel for troubleshooting.

Good luck!
6. Documentation
Kernel-Howto
man lsmod

from:

=================================
QA: error message::
Kernel panic: VFS: Unable to mount root fs on  unknown-block(0,0)"

A::
I was seeing the same kernel panic and I wasn't sure how to use mkinitrd to fix this problem. I'm installing a new 2.6.12.3 kernel on ubuntu so I used

mkinitrd -o /boot/initrd.img.2.6.12.3 2.6.12.3

It's important to put the 2.6.12.3 at the end of the line, or the image created is just for the currently running kernel.

Then I changed the initrd line in my menu.lst to point to the new initrd.img and my system booted ok.

阅读(2666) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~