Cainiao compiles Linux kernel-general Linux technology-Linux programming and kernel information. The following is a detailed description. Author: CVIP
Additionally, mkinitrd is a required tool. To use this tool, you must install an initrd-tools package. The installation process is as follows: apt-get install initrd-tools
Pig with double eyelid
Cainiao, I recently studied how to compile the Linux kernel. I hope to share it with you... We will not discuss the source code here, but some kernel compilation steps and related knowledge... Because I am a cainiao. So I hope to share with cainiao...
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 use RedHat9 as an example (other versions are actually the same, but they are a little different in make menuconfig ), the kernel compilation steps are described in detail:
First, 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 root; 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 make sure that the command you typed is correct, otherwise, No rule to make target *** will be returned, and a similar error message like stop will be returned. This is what cainiao should pay attention. Otherwise, it cannot start. Don't talk about it later...
1 # cd/usr/src/linux-2.4.22
2 # 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 are the source code we just downloaded, 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 # make menuconfig, make config, or make xconfig
Then we started to compile the kernel. The system could not start because of the 12-point Spirit and poor compilation. make config, make xconfig, and make config are two ways to answer questions one by one. If you have an error in the command line method, 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, make xconfig also requires some stuff, like tk. If you forget it, it is usually installed, so you won't mention it. If you don't have it, you won't be able to run it. what are ncurse and tk? 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...
This is not the topic of this post (in fact, I really want to write it, but no one is working together, I am too tired to write it, and I am also busy with exams recently, so ...) That's why we skipped it...
In make menuconfig, you can select
, Some allow you to select [M], some allow you to select [], * indicates that the selection is directly loaded into the kernel, and M indicates that it will be compiled into modules in the make modules later, allows you to call the kernel through insmod and modprobe 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 make * config is to generate. config file. want to know. what is the config file? Let's take a look... J
After this step is completed, the system will remind you that next step you should run "make dep"
4 # make dep (one to two minutes)
After determining which items to compile (make * config), determine the dependencies. This item can also be done manually, .... I am afraid that you will put everything down, spend ten days and a half months on it, and make mistakes even if you are busy, but we can use this command to complete it, so you don't have to worry about it. Well, after determining the dependency, you have to clear some stuff...
5 # make clean (less than one minute)
Clear unnecessary files. The messy stuff may cause errors during the compilation process. Do it...
6 # 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, 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...
You can't do things during this time. You will see a line of words on the screen running down. Don't worry, you can choose to redirect all the things on the standard output to/dev/null, so that you will not be able to see these things. Of course, you can also put them in the background for execution, add an & symbol to the end when the operation starts. This indicates that the operation is performed in the background... If you are afraid that this will affect your kernel compilation (in fact, it has no effect), then 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, just go and have a meeting, 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 can endure it, you will be very happy after the success...
If your kernel has already been compiled, the smaller the kernel, the better J. At this time, the system will prompt where the compiled bzImage is put, prompting the last few lines, I have already told you the core location of the new compilation, usually here (I am here 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, or the system will not be able to start...
(In fact, bzImage has been renamed as a vmlinuz-2.4.22, stay in the/boot/grub. conf to specify this new kernel)
7 # 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.
8 # 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, it is not good, and insmod and related commands are from/lib/modules/linux-2.4.22 module ah, 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...
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...
The system will prompt you:
Overwrite the 'boot/System. map'
Press Y and press Enter.
Ii. 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.
Let's talk about this process. During this period, the system will add a m to your current release version and write it to grub. conf. After restarting, you will 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 have not done anything wrong in make menuconfig. Otherwise, you will not be able to boot after the restart, for example, in fs, You must select VFS and compile EXT3 into M, because now the system generally uses the ext3 format. If you miss this stuff, you 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 check 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 can write no initrd here to replace it, so that the system will not use intird. Of course, we 'd better take it with you. We also talked about its role in the front, mainly some drivers .... And the system initialization program...
Okay, it's here... If you have any questions, I will discuss them below.
It was supposed to be long, but it was because there were too many exams... Busy graduation... So briefly complete... Sorry... If you have any questions, please MAIL it to the newjintao@yahoo.com.cn for discussion...
Ps: if anyone is interested in writing all the "make menuconfig" statements and detailed explanations, it would be better ....
This is an amazing dish .... Even further improvement .... Please correct your mistakes. Thank you...
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.