Linux Kernel compilation process

Source: Internet
Author: User
First, make sure that you have a system with Linux installed. You can compile the kernel on the local computer, or download the kernel from the Internet to compile it. here we will detail how to upgrade the kernel. You can download the latest kernel version from www.kernel.org. Here we take redhat9 as an example (the same is true for other versions, but it is a little different in make menuconfig). Let's take a closer look at the kernel compilation steps:
 
Make sure that you log on as a root user. Run the kernel source code CP under the/usr/src directory (Make sure that you are operating as a root user; otherwise, the permission denied prompt will be returned ):
Mkdir/ usr/src/linux-2.4.22
CP 2.4.22.tar.bz2/usr/src/linux-2.4.22 (I used the 2.4.22 kernel)

Decompress the package. If you are familiar with Linux, you should know:
Bunzip2 *** .tar.bz2 | tar xvf
Go to the/usr/src/linux-2.4.22 directory, make sure that you are operating under this directory, and ensure that the command you typed is correct, otherwise no rule to will be returned
Make target *** and stop are similar error messages. This is what cainiao should pay attention. Otherwise, it cannot start. Don't talk about it later...

1 [color = Red] # cd/usr/src/linux-2.4.22.

2 [color = Red] # Make mrproper
In fact, this step does not need to be used. The purpose is to clear the original directory. config and. O (object file), if we just downloaded the source code, you can save this step), but if you have compiled the kernel multiple times, this step is required. Otherwise, there will be many minor problems in the future. Don't blame me for not telling you .... The config file will be mentioned later...

3 [color = Red] # Make menuconfig or make config or make xconfig

Then we started to compile the kernel. We had a 12-point spirit, and the compilation was not good. The system could not be started. Please be careful. In fact, there are two other methods for this step: Make config and make.
Xconfig, make
Config is a command line method for answering questions one by one. If the answer is incorrect, you cannot correct it (so this compilation method is not recommended). Make
Menuconfig and make xconfig provide more friendly operations, but make menuconfig requires the ncurse package, while make
Xconfig also needs something like TK. If you forget it, it is usually installed and you won't mention it. If you don't have it, you won't be able to run it. you don't know what ncurse and TK are.
? So I won't talk about it. Go to www.google.com to search for 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...

In make
In menuconfig, you can select [*], [m], or [].
* Indicates that the selected file is directly loaded into the kernel, while M indicates that
Les is compiled into modules, so that you can call insmod and modprobe to the kernel at any time... I personally think that this feature of Linux is really great... But this is not what other operating systems do.
* The purpose of config is to generate the. config file. If you want to know what the. config file is, you can see it at a glance... J
After this step is completed, the system will remind you that next step you should run "make Dep"

4 [color = Red] # Make Dep (one to two minutes)
Make
* Config). Determine the dependency. This stuff can also be done manually, .... I am afraid that you will put everything down, and spend ten days and a half months on it.
There will be errors, but we can use this command to complete it, so you don't have to be so busy with it. Haha, after determining the dependency, we will clear some stuff...
 
5 [color = Red] # Make clean (less than one minute)
Clear unnecessary files. The messy stuff may cause errors during the compilation process. Do it...

6 [color = Red] # Make bzimage (about 15 minutes )-
Oh, this is the most important thing. this is to generate your new core. Don't tell me you don't know what the core is, that is, kernel. All the system hardware and software interaction depends 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, 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...


You can't do things during this time.
You don't have to worry about running a line of words on the screen. You can choose to redirect all the items on the standard output to/dev/null, in this way, you will not be able to see these things. Of course, you can also
In order to put it in the background for execution, add an & symbol at the end of the operation to start, which indicates that it is running in the background... If you are afraid that this will affect your kernel compilation (but it does not affect your system), simply press Alt + F2 to directly open another virtual terminal, work while there, and wait until the compilation is complete. The machine will give you a sound notification. If you really don't want to wait, you can play it.
Yes, listen to songs or something, and come back later. This is a time to test your patience. If you have no patience, there will be a time-consuming step in the future. Let's endure it, to prevent the system from wasting resources, you still
Sorry, you will be very happy after the success...
If your kernel has been compiled, the smaller the kernel, the better J. At this time, the system will prompt where the compiled bzimage will be stored.
The last few lines of the prompt, have told you the core location of the new version of AH, generally here Oh (I here is redhat9),/usr/src/linux-2.4.22
/ARCH/i386/boot/. At this time, you need to put it at the bottom of the/boot directory. Otherwise, the system will not be able to start it...


# Cp/usr/src/linux-2.4.22/ARCH/i386/boot/bzimage/boot/vmlinuz-2.4.22


(In fact, bzimage has been renamed as a vmlinuz-2.4.22, stay in the/boot/GRUB/grub. conf to specify this new kernel)


7 [color = Red] # Make modules (the time required depends on the number of modules you have compiled)
Wow, another
A time-consuming step is coming. You can find something to do. It may take a long time. It may take about 20 minutes.
Choose m in menuconfig, all compiled into a module and put it under/usr/src/linux-2.4.22... If you choose a lot of m, or... Go
Have you done 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 one minute to complete. However, if you choose the default option if you do not know a lot about it, it may take a long time...


8 [color = Red] # Make modules_install
Hoho,
Here, but the steps to install the module, the module you selected after compilation are put in a/usr/src/linux-2.4.22 subdirectory, which subdirectory you will know
Now, make
After modules, there will be a prompt... I also forgot, haha :), this is not good, and insmod and related commands are from/lib/modules/Linux-
2.4.22 to take the module ah, this command is to put the compiled MOD/lib/modules down Oh, if the beginning does not have the Linux-2.4.22 directory,
(That is to say, it is the first time you compile the 2.4.22 kernel), then this command will automatically create this 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 initrd. IMG (because the scsicard driver includes
If you are using an IDE hard disk, you can skip this step. Of course, if you are patient, it is no harm to study here.
Mkinitrd can be created
Initrd. IMG is generally used in this way. If you want to know more, you can use man
Mkinitrd, if you just want to get an initrd. IMG out, then mkinitrd/boot/initrd-custom.img
2.4.22 create a initrd-custom.img file under the/boot directory, 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... And 2.4.22 indicates/lib.
/The 2.4.22 directory under modules...


Here, there are two ways to do this:
1. manually update the system. Map File
It is the description of the fuctions of the currently running kernel. If you do not update the system after compiling the kernel. map. If problems occur ., trouble Shooting is very difficult. You may encounter a lot of annoying information, so we need to update it manually. It's quite simple...
# Cp/usr/src/linux-2.4.22/system. MAP/boot/system. Map
The system will prompt you:
Overwrite the 'boot/system. map'
Press Y and press Enter.
Ii. make install
Speaking of make install, let's talk about it again. Make
Install is equivalent to an automated process, because it will help you with other tasks. If you are really lazy or have no patience with the previous steps, you can perform this step 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 teach it to fish instead
There is no way. 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
# Head-N 5 makefile
I believe you have seen it... This is the reason for naming, so you can also modify your Linux... Do you feel uncomfortable about the name of your own m release...


From the above steps, there is basically no problem. Of course, please make sure that you
Menuconfig has not done anything wrong. Otherwise, it will still fail to be guided after the restart. For example, VFS must be selected in FS, and ext3 must be compiled into M, because system 1
In general, the ext3 format is used. If you miss this stuff and cannot load partitions, don't blame me for not telling you. Of course, second extended FS must be selected :)


In the history of compilation, I used to experience VFS: Unable to mount root FS on. It has been stuck there for a long time and has not been solved. However, I finally found that it should be a FS problem, or your root partition is not specified ..


Read so much. I believe you are also very tired, and the Post is coming soon, because it will soon be over... (If you select make
Install, you don't need to read it here.) The last point is to modify grub. conf (if you are using grub for guidance, sorry I don't understand Lilo, because I am also a cainiao ...), Enable the system to start from the new kernel after restarting...
# Vi/boot/menu. lst
The content of menu. lst is the same as that of grub. conf. It is a link, but it is a colorful text here. I like it very much and I will edit it ..
Add a row based on the original one:
Title new Linux (2.4.22) // you can name it yourself, that is, the stuff that appears in the grub Startup menu.
Kernel/vmlinuz-2.4.22 Ro root = label =/
The above line specifies the path of the kernel. Do you remember to generate a new kernel for the vmlinuz-2.4.22 on the front? Oh, that's it... After it is specified here, the new kernel will be used after you select this option to start.
The RO that follows indicates readonly, which means read-only. Root = label =/indicates the specified path.
Initrd/initrd. img
Here you need to specify the initrd. IMG you have created. If this is incorrect, it cannot be started... Of course, this means that you are using a SCSI hard disk, if it is an IDE hard disk. You
You can write "no" here.
Replace initrd so that the system will not use intird. Of course, we 'd better take it with you. We also talked about the role of intird in the front, mainly some drivers .... And the system initialization program...


Address: http://www.cnxhacker.com/Article/ OS /Unix/200610/6030.html

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.