Kernel compilation steps

Source: Internet
Author: User
Tags ide hard drive
At the beginning, I downloaded the latest kernel. I used fc5 and the kernel was quite new. It was 2.6.8. I downloaded the latest kernel 2.6.20 at www.kernel.org.

Download the kernel to any place, tar: And put the compressed package under/usr/src/RedHat/sources/. In fact, this can also be done, unzip the kernel to/usr/src/, and then enter/usr/src/to find that the 2.6.20 folder already exists, compile the kernel in this file. That is to say, you can perform subsequent operations only after entering the folder.

The entire process is divided into three steps: 1. Configure the kernel (that is, determine which functions should be kept in the compiled kernel and which functions should be deleted from the kernel) and generate a compilation configuration file. config

2. Compile the kernel.

3. Install the kernel.

The subsequent steps are as follows:

Go to the current directory/usr/src/RedHat/sources/linux-2.6.20

Clear the compilation settings in the current directory:

 

Step 1:

$ Make mrproper

In fact, this step can be avoided. Generally, you should try again.

This command ensures that there are no related files and configurations in the directory. If you have compiled the Linux kernel, we recommend that you use this command.

Step 2:

You can configure the features of the kernel module in several ways:

$ Make config (Text configuration method. You need to write the configuration file yourself)

$ Make menuconfig (Text menu configuration method, which can be used on character terminals)

$ Make xconfig)

$ Make oldconfig (Text configuration method, used for basic modification of the original Kernel configuration)

The Make xconfig method is recommended. The configuration in the graphic window is more intuitive. There are three options for each configuration item:

Y -- this module is compiled into the kernel

N -- this module is not compiled into the kernel

M -- this module is compiled into a loadable kernel module.

For more information about the function Selection of each module in kernel compilation, see my article.

Here I chose: menuconfig, which is followed by a blue interface. there are more than 10 large entries in total. Press enter to enter. If there is [] in front, you can directly enter y/N in upper case, and y indicates *, the default n option is [Blank]. If you want to select N, Press Y or N, and of course [M]. in fact, there may be another thing under the entry: ---->, and press enter to enter the settings. it seems that there is another X option. When you enter, you will know how to pull it.

Pay attention to the selection of many things here. This requires you to have a certain understanding of hardware, software, and network. If you do not know it, follow the default rule. otherwise it will be useless if you cannot start it later, but I cannot start it many times, so I finally come up with a tip...

After this step is completed, the system will remind you that next step you should run "make Dep"

Then, the kernel module file connection:

Step 3:

# Make Dep (one to two minutes)
After determining which stuff to compile (make * config), you can use this command to determine the dependency, so you don't have to worry about it, after determining the dependency, we need to clear some stuff...

Step 4:

# Make clean (less than one minute)
Clear unnecessary files. The messy stuff may cause errors during the compilation process. Do it...
 

Step 5:

# Make bzimage (about 15 minutes )-
This is to generate your new core, that is, the kernel. All system hardware and software interactions depend on it ..

You can actually make zimage, but make sure that the new kernel you compile is under 640k, you can use make zimage. If it is larger than 640k, you must use make bzimage, how old do you know if it is not compiled? In my opinion, bzimage is recommended, because the compiled kernel is usually 800 ~ About K .... I am a cainiao, and this post is also written by myself as a cainiao, so... let's make bzimage by default...

If the kernel has already been compiled, the smaller the kernel, the better. At this time, the system will prompt where the compiled bzimage will be put, prompting the last few lines, I have already told you the core location of the new compilation, usually here/usr/src/linux-2.6.20/ARCH/i386/boot /, at this time, you need to put it at the bottom of the/boot directory, or the system will not be able to start...
# Cp/usr/src/linux-2.6.20/ARCH/i386/boot/bzimage/boot/vmlinuz-2.6.20 here it seems that you can not manually copy, the system will finally generate a bar under boot.
(In fact, bzimage has been renamed as a vmlinuz-2.4.22, stay in the/boot/GRUB/grub. conf to specify this new kernel)

Step 6:

# Make modules (the time required depends on the number of modules compiled by you)
Wow, another time-consuming step is coming. You can find something to do. It may take a long time. It may take about 20 minutes, this step is to make the menuconfig you selected as M stuff, all compiled into a module and put in/usr/src/linux-2.4.22... If you choose a lot of m, or... Do you have any housework? I didn't do my homework. What? However, if you prefer to compile all the things into the kernel, it will not take long, but it will take a short time to select M, which will soon be completed. It takes only one minute for me to complete the process, however, if you do not know a lot and choose the default option, it may take a long time...

Step 7:

# Make modules_install
Hoho, here is the step to install the module, the module you selected after compilation are put in/usr/src/linux-2.4.22 a subdirectory, which subdirectory you can see it, there will be a prompt after make modules .. I also forgot, huh, huh: Well, this is not good, and insmod and related commands are used to retrieve the module from/lib/modules/Linux-2.4.22, this command is to put the compiled MoD to/lib/modules, if there is no Linux-2.4.22 directory at first (that is to say, you are the first time to compile the 2.4.22 kernel ), this command will automatically create the directory if it already exists. Then the compiled kernel will be put into this directory... When you call the MOD into the kernel (insmod, modprobe), you will find the. O from here...
Note: If you are using a SCSI hard disk and the ext3 partition format, please note that you must make an initrd. IMG (because the scsicard driver is included in this). If you are using an IDE hard drive, you can skip this step. Of course, if you are patient, it's no harm to study it here.
Mkinitrd can be used to create initrd. IMG is generally used in this way. If you want to know more, you can use man mkinitrd. IMG out, then mkinitrd/boot/initrd-custom.img 2.4.22 in the/boot directory to create a initrd-custom.img file, that is, initialize the image... (Initialed ramdisk )... There are mainly some drivers in it. Because the driver is too large in the kernel, It is compiled into initrd. IMG and released at startup... This 2.4.22 indicates the 2.4.22 directory under/lib/modules...

Step 8:

# Make install
Speaking of make install, we have something to say here. Make install is equivalent to an automated process, because it will help you with other things. If you are really lazy, or you have no patience with the front-end steps. Please do this directly... Of course, you can make the new system ready soon and restart the new kernel, but you may not understand what happened in the middle, when I was in class, the teacher talked about how to grant fish instead of fish. If you are in trouble, you can save it. You still feel tired, huh, huh :)
Let's talk about this process. During this period, the system will add a custom to your current release version and write it to grub. go to Conf. After restarting, you can see the 2.4.22custom menu...
How is the file name determined? You can take a look at/usr/src/linux-2.4.22, there is a makefile inside, you have a try


Generally, we can think that the kernel compilation and installation are completed here. The final shell will tell you what is generated. config file, there is a zimage file, it seems that there is something I don't remember.

Restart, and you will see another problem. In the grub startup selection, there are three winter, one is windows, the latest version of the kernel, and the other is a previous kernel version, I tried it. The latest version can be used. The old version cannot be used. It should be the config file, and a zimage file is overwritten by the new kernel.

Then solve the startup options that are not available here. Remember to set grub, CD/etc, and then VI. /grub. conf, change the first 2 to 1, or 0, that is, starting from windows or Linux. The following three titles are available, delete all the title-related items of the old version, and restart it. haha

Now we can see that there are only two grub startup options. Do not delete the wrong title before.

I have never encountered an error in all this. I have some warnings when making. They all say that there is no initialization, or it is out of date. It doesn't matter if it is out of date. Don't miss them.

Note:

1. During configuration, in an item, "Y" means to compile a function into the core. "N" means to compile the function, and "M" means to compile the function into a module,
In addition, not all functions can be compiled into modules. Generally, some drivers can be compiled into modules.

2. During configuration, several items must be compiled into the kernel, but cannot be removed or compiled into a module. Otherwise, the compiled kernel cannot be started properly. These modules are all items under the ext3 Journalling File System Support Sub-item under the file system menu. Note that ext3 Journalling File System Support contains two sub-items: ext3 extended attributes and jbd (ext3) debugging support. All these items are selected by Y to compile them into the kernel.

3. If all of the above operations are done and the new kernel cannot be used normally at startup, enter the old kernel and set the config in/etc/SELinux
The SELinux item in can be disabled.

4. For a laptop with a DVD-optical drive, note that you must also select
Ufs switch. Otherwise, it may fail to start.

 

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.