Procedure for compiling the kernel-a beginner's Guide

Source: Internet
Author: User
1. Why should we compile the kernel;

Sometimes we need Kernel support for some features, such as iptables firewalls, and hardware support. At this time, we need to re-compile the kernel;


2. Selection of the kernel source code version;

If the release version provides the kernel source code, it is best to use the release version. For example, fedora 4.0 provides many versions of the kernel source code. After installation, the built-in configuration file can meet our needs. For Beginners, the configuration file is based on the built-in kernel. config, we can also learn how to configure the kernel. There is no difficulty, and practice makes perfect;

You can also download the latest stable kernel version from kernel.org;


3. install or decompress the kernel source code;

For Fedora Core 4.0, the kernel source code is stored in the/usr/src/kernels directory. If the kernel is upgraded online, it is also stored in this directory; if no content exists in/usr/src/kernels/in your system, the kernel source code package kernel-devel is not installed;

You can use the Package Manager to complete the installation. See fedora/RedHat package management guide.

If you use Fedora Core 4.0, we recommend that you download the latest kernel kerenl-devel and the corresponding kernel version online or from kernel.org on the basis of keeping the old kernel, sometimes the new kerenl may have solved your problems, so there is no need to compile the kernel;

If you install the kernel source code package online, such as through apt + synaptic or yum, the kernel source code will be placed in the directory under/usr/src/kernel, you need to enter the corresponding directory for compilation;

For online update software packages, see fedora/RedHat software package management guide. apt + synaptic tools are recommended;

If you are downloading the RPM package of kernel and kernel-devel, you can install it through;

[root@localhost beinan]# rpm -ivh kernel*.rpm

 

If you are downloading a linux-2.6.13.tar.bz2 or linux-2.6.13.tar.gz similar to kernel.org, move the downloaded file to the/usr/src directory to decompress it; then go to the decompressed directory for configuration and compilation;

[root@localhost beinan]# mv linux-2.6.13.tar.bz2
[root@localhost beinan]# cd /usr/src/
[root@localhost src]# tar jxvf linux-2.6.12.3.tar.bz2

 

Tip:This article takes the linux-2.6.12.3 as an example, in fact, the upgraded version of the kernel-devel and download from kernel.org is similar, the same; the difference is through the online upgrade of the RPM format of the kernel source package, there is a configuration file. config can be referenced. The installation destination is/usr/src/kernel for FC 4.0. If you want to compile and configure the kernel,


4. Kernel configuration;


1. Run make mrproper in the directory. For the source code package in tar. BZ format downloaded from kernel.org;

[root@localhost src]# cd linux-2.6.12.3/
[root@localhost linux-2.6.12.3]#
[root@localhost src]# cd linux-2.6.12.3/
[root@localhost linux-2.6.12.3]# make mrproper
[root@localhost linux-2.6.12.3]# make menuconfig

 

For Fedora Core 4.0, if you are using a new version of the kernel and kernel-devel installed online, such as 2.6.12-1.1398 _ FC4-i686, you can directly execute make menuconfig in the/usr/src/kernel/directory. config. Do not make mrproper; otherwise,. config will no longer exist. This is why the kernel source code upgrade package provided by the release version is used;

Other configurations are similar to those for installation. You can imitate them;


2. Briefly configure the kernel;

After entering the Kernel configuration mode, we may not know anything about it. See the following;

There are two Kernel configuration methods: one is to directly put the kernel *; the other is to compile the module m; the two methods have their own advantages; directly compiled into the kernel, such as the startup of the device, the process of Loading modules is no longer required. Compiling modules requires Loading modules supported by the kernel of the device. However, it is not feasible to directly compile everything into the kernel, the kernel size will increase, and the system load will also be too heavy. When compiling the kernel, it is best to include the most important data into the kernel. If you do not understand anything else, you 'd better use the default value.


1) Move the left and right keys on the keyboard and press enter to enter a directory. Move the pointer to exit and exit the current directory to the parent directory;

Select the CPU of your machine;

2) Modify existing problems on your machine, such as support for large memory;

Move the keyboard to processor type and features ---> and press Enter;
Find Processor family (Pentium-Pro) ---> press enter to enter;

After entering, we found that there are a lot of CPU models available; in general, according
Bash-3.00 # select the output information of CAT/proc/cpuinfo. For example, if we are from the celon (P4) generation, we should select the following, of course, the default 486 version can also run normally. Since we re-compile the kernel, We have to select the corresponding model, which may improve the performance;

Processor family (Pentium-4/Celeron(P4-based)/Pentium-4 M/Xeon)

Supports large memory. If the memory is 1 GB or above, but less than 4 GB, 4 GB is required. If the memory exceeds 4 GB, 64 GB is required;

 

 

High Memory Support (4GB) --->
(X) 4GB
( ) 64GB

 

There are also hardware such as sound cards that need to be viewed step by step. If there is something unknown, we need to press [shift] +? To view the description. In general, the 2.6.x kernel will automatically generate a file based on the machine's situation. You just need to check the file and change the important part;

Another example: for example, if I use intel ac97 sound card, how should I configure it?

First, you need to know the chipset of your sound card. We need to check it through lspci-V;

[root@localhost beinan]#lspci -v

To view only the sound card, use the following method:[root@localhost beinan]# lspci -v |grep audio
00:1f.5 Multimedia audio controller: Intel Corp. 82801DB (ICH4) AC'97 Audio Controller (rev 03)

 

Through the above output, we know that this machine uses the Intel ac97 sound card, so we should pay special attention to the ac97 configuration;

 

Find device drivers ---> sound --->
<M> sound card support: This must be selected;
<M> advanced Linux sound architecture supports sound card-supported ALSA drivers;
The following is an OSS driver. If you want to use a more comprehensive OSS driver, you can buy it. For other options, see the following;
<M> sequencer support
<M> sequencer dummy Client
<M> OSS mixer API
<M> oss pcm (digital audio) API [*] OSS sequencer API
<M> RTC timer support [*] verbose printk
[] Debug

 

Most of them are default values. If you do not know what to use or how to use them;

Then let's look down at

Generic devices ---> enter
<M> dummy (/dev/null) Soundcard
<M> virtual MIDI Soundcard
<M> motu miditimepiece AV multiport MIDI
<M> uart16550 serial MIDI driver
<M> generic MPU-401 UART driver
ISA devices ---> select this option if you use the ISA sound card;
PCI devices ---> if you use the PCI sound card, select it here, and the integrated sound card is also here;
USB devices ---> This is an option supported by the USB sound card kernel. I have such a sound card, but I have not tried it;
PCMCIA devices ---> This is the option of PCMCIA sound card. I have not seen such a sound card yet. If you have one, click here.

Because I use an Intel integrated sound card, we can see two Intel-related sound cards in PCI;<M> Intel/SIS/NVIDIA/AMD/Ali ac97 controller is the sound card of Intel ac97;
<> Intel/SIS/NVIDIA/AMD mc97 modem (experimental) is an Intel cat buzzer integrated with machines;

I found that two conflicts may occur if the driver of the buzzer of the cat is selected. So you can only select the one above;

 

Let's go back to open sound system ---> and see if it is related to my sound card?

<M> Open Sound System (DEPRECATED)
<M> Intel ICH (i8xx) audio support
<M> OSS sound modules
<M> Loopback MIDI device support
<M> Microsoft Sound System support

We can also see that there are also a lot of sound card drivers in the open sound system. Let's choose based on the previous lspci-v.

 


3) support for the file system used by the operating system should be compiled into the kernel. It is best not to compile the file system into modules. (important)

For example, my Fedora Core 4.0 file system uses ext3, so I want to compile it directly into the kernel. The advantage is that the system cannot be started without the loss or damage of modules; sometimes, when you compile the file system used by the system into a module, a VFS error occurs, it may be because you have not added ext3 to the configuration file of the corresponding loading module. Therefore, to reduce the trouble and minimize the risk, you must directly place it in the internal model;

File systems --->
<*> Ext3 journalling file system support
[*] Ext3 extended attributes
[*] Ext3 POSIX Access Control Lists
[*] Ext3 Security Labels

If you have other hard disk partitions to read, such as reiserfs, ext2, fat, FAT32, and NTFS, such partitions can be compiled into modules;

 

Another example: If your operating system uses the reiserfs file system, of course, you must directly compile the reiserfs file system into the kernel. Other files can be compiled into modules for support;


4) hard disk and raid support should be directly compiled into the kernel;

For example, ATA, SATA, SCSI, and raid support are directly supported by the kernel. Sometimes, after the kernel is compiled, the hard disk and raid cannot be identified during startup. Most of the work is here; slackware has module support in this aspect. We can change it from module M to kernel * for support. If you do not understand it, use the default mode; apart from selecting SATA support and IDE support, you must also select SCSI support;

5) for devices we don't have, we can leave them out of the kernel, which makes perfect;

For example, if I do not have an ISDN device, I will remove the ISDN device;

ISDN subsystem --->
< > Linux telephony support

 

If you do not have a 1394 device, you can also remove the 1394 support and so on .......

If you have a USB device, take a good look at the USB, such as mobile hard disks, USB cats, and scanners;

There are so many kernel configurations, too many. I cannot tell them clearly, and the level is limited;

Save the Configuration

Save configuration to an alternate File

One

Enter a filename to which this configuration, shocould be saved as an alternate. Leave blank to abort.
. Config

Press enter to save it;

Then exit, and save will also appear;

If you want to save. config, you can copy it to a safe directory for later use;

5. Compile the kernel;

 

[root@localhost linux-2.6.12.3]# make
[root@localhost linux-2.6.12.3]# make modules_install

 

In this way, the compilation is completed, and the module is also installed in the/lib/modules directory. Please refer:

[root@localhost linux-2.6.12.3]# ls /lib/modules/
2.6.11-1.1369_FC4 2.6.12.3

 


6. Install the kernel and configure grub or Lilo;


1. Copy bzimage and Other Related Files and create the initrd file;

[root@localhost linux-2.6.12.3]# cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.12.3
[root@localhost linux-2.6.12.3]# cp System.map /boot/System.map-2.6.12.3
[root@localhost linux-2.6.12.3]# cd /boot
[root@localhost linux-2.6.12.3]# /sbin/mkinitrd initrd-2.6.12.3.img 2.6.12.3

 

We copy the compiled bzimage into the/boot directory to the vmlinuz-2.6.12.3;
And use mkinitrd to create a imitrd-xxx.img file, where XXX is the kernel version number, is to view the/lib/modules to the corresponding version, we compile is 2.6.12.3, so run the above command to create, create a initrd-2.6.12.3.img; do not create this file, sometimes cannot start up, such as the prompt VFS error;


2. view the configuration file of grub or lilo in the System Boot manager.

If you want the new inner nuclear energy to be visible on the grub and Lilo menus of the System Boot manager, you must change grub. conf or Lilo. conf, but we must keep the boot menu of the old kernel in grub and Lilo. After all, we cannot make the kernel a hundred percent success, right ?? Security first;

I only talk about grub. I don't have Lilo, and I won't use it. So let's continue with grub. The FC 4 System Boot manager is grub, so let's talk about grub settings;

View/etc/grub. conf;

For example, the content of my grub. conf is like this;

 

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,7)
# kernel /boot/vmlinuz-version ro root=/dev/hda8
# initrd /boot/initrd-version.img
#boot=/dev/hda
default=0
timeout=5
#splashimage=(hd0,7)/boot/grub/splash.xpm.gz
#hiddenmenu
title Fedora Core (2.6.11-1.1369_FC4)
        root (hd0,7)
        kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/ rhgb quiet
        initrd /boot/initrd-2.6.11-1.1369_FC4.img
title WinXP
        rootnoverify (hd0,0)
        chainloader +1

 

We need to keep the startup of the old kernel to prevent unexpected events. We only need to add the startup of the new kernel, so I will add such a paragraph;

 

title Fedora Core (2.6.12.3)
root (hd0,7)
kernel /boot/vmlinuz-2.6.12.3 ro root=LABEL=/ rhgb quiet
initrd /boot/initrd-2.6.12.3.img

 

Let's take a look at the modified configuration file;

 

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,7)
# kernel /boot/vmlinuz-version ro root=/dev/hda8
# initrd /boot/initrd-version.img
#boot=/dev/hda
default=0
timeout=5
#splashimage=(hd0,7)/boot/grub/splash.xpm.gz
#hiddenmenu
title Fedora Core (2.6.12.3)
        root (hd0,7)
        kernel /boot/vmlinuz-2.6.12.3 ro root=LABEL=/ rhgb quiet
        initrd /boot/initrd-2.6.12.3.img
title Fedora Core (2.6.11-1.1369_FC4)
        root (hd0,7)
        kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/ rhgb quiet
        initrd /boot/initrd-2.6.11-1.1369_FC4.img
title WinXP
        rootnoverify (hd0,0)
        chainloader +1

 

Then restart the machine. If a VFS error occurs, it may be that an error occurs in the important part of my writing;

Note:If the kernel is re-enabled, the previously installed display card drivers, such as nvidia and ATI drivers, need to be re-installed;

Postscript:

To prepare for installation of sound cards and other hardware devices, rewrite this document and correct some errors;

Appendix:

1. kernel management overview
2. Fedora/RedHat software package management guide
3. kernel main site: http://kernel.org

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.