Complete Linux kernel compilation process

Source: Internet
Author: User
I have compiled my own actual kernel through online materials. I have written the process of compiling the Linux kernel here. It may be helpful for other Linux enthusiasts to compile and learn, most of them are online materials, and some of my practical experience in the compilation process.
Kernel Introduction
Kernel is the core of an operating system. It manages system processes, memory, device drivers, files, and network systems, and determines system performance and stability.
An important feature of Linux is its open source code. All kernel source programs can be found in/usr/src/Linux. Most application software is designed to comply with GPL, you can obtain the source code. Any software engineer in the world can add code that he thinks is excellent. One obvious benefit of this is the fast fixing of Linux vulnerabilities and the use of the latest software technology. The Linux kernel is the most direct representative of these features.
Imagine what the source program with the kernel means to you? First, we can understand how the system works. By reading the source code, we can understand the operating principle of the system, which is simply a fantasy in windows. Secondly, we can tailor the system to suit our own situation, so we need to re-compile the kernel. What is the situation in windows? I believe that many people have been inexplicably confused by the increasing size of windows. Again, we can modify the kernel to meet our own needs. What does this mean? Yes, it is equivalent to developing an operating system on your own, but most of the work is done. All you have to do is add and implement the functions you need. In Windows, unless you are the core technical staff of Microsoft, you don't have to worry about it.
Kernel compilation Mode
To support a certain part of functions, such as the network, you can compile the corresponding part into the kernel (build-in) or compile the part into a module ), dynamic call. If it is compiled into the kernel, the corresponding functions can be automatically supported when the kernel is started. This advantage is convenient and fast, and the machine starts once, you can use this feature. The disadvantage is that it will make the kernel huge. Whether you need this feature or not, it will exist. This is the common practice of windows, we recommend that you compile the frequently used parts directly into the kernel, such as the NIC. If it is compiled into a module, the corresponding. o file will be generated and can be dynamically loaded during use. The advantage is that the kernel will not be too large, but you have to call these modules by yourself.
Actual kernel compilation phase:
I. Linux kernel source code package acquisition: http://www.kernel.org, compiling the kernel requires root permissions, the following operations are assumed that you are a root user. Copy the kernel you want to upgrade to/usr/src/(the following uses linux-2.4.18.tar.gz as an example). The command is
# Cp linux-2.4.18.tar.gz/usr/src
2. decompress the source code package and create a link:
In the current/usr/src content, note that there is a Linux-
The symbolic link of 2.4 points to the directory of A linux-2.4.7-10 (take redhat7.2 as an example. This is the kernel source code of the Linux installation. Delete this link.
Decompress the downloaded source code file. If the downloaded file is a .tar.gz (. tgz) file, run the following command: # tar
-Zxvf linux-2.4.18.tar.gz.tar.gz
If you download the. bz2 file, for example, linux-2.4.18.tar.bz2, use the following command
# Bzip2-D linux-2.4.18.tar.bz2
# Tar-xvf linux.2.4.18.tar
The file will be decompressed to the/usr/src/Linux directory, and we will slightly modify it:
# Mv Linux linux-2.4.18
# Ln-s linux-2.4.18 Linux (rebuild a link to the linux-2.4.18 you just extracted)
3. Check whether the. o file and file dependency are correct in the source code directory. Run the following command:
# Cd/usr/src/Linux
# Make mrproper
4. Create an ASM Linux SCSI link pointing to the compiled Kernel
To ensure that links such as ASM, Linux, and SCSI in the/usr/include/directory point to the source code of the kernel to be upgraded. They chain the real include sub-directories required by the real computer architecture (i386 for PCs) under the source code directory. For example, ASM points to/usr/src/Linux/include/asm-i386
. If you do not have these links, you must create them manually. follow these steps:
# Cd/usr/include/
# Rm-r ASM Linux SCSI
# Ln-S/usr/src/Linux/include/asm-i386 ASM
# Ln-S/usr/src/Linux/include/Linux
# Ln-S/usr/src/Linux/include/SCSI
This is an important part of configuration. Delete the ASM, Linux, and SCSI links under/usr/include, and then create a new link pointing to the directory with the same name under the new kernel source code directory. These header file directories contain the important header files required to ensure that the kernel is correctly compiled on the system.
V. Kernel configuration
The following Kernel configuration process is cumbersome, but the proper configuration is directly related to Linux running in the future. It is necessary to know some of the main and frequently used options.
You can use one of the following commands to configure the kernel based on your needs and hobbies:
# Make config (the most traditional text-based configuration interface is not recommended)
# Make menuconfig (Text menu-based configuration interface, recommended for character terminals)
# Make xconfig (the configuration interface based on the graphic window mode is recommended in XWindow)
# Make
Oldconfig (if you only want to modify some small points based on the original Kernel configuration, it will save a lot of trouble)
Make
The xconfig interface is the most user-friendly. If you can use XWindow, we recommend that you use this command. The interface is as follows:
If you cannot use XWindow, use make
Menuconfig is ready. Although the interface is worse than the above one, it is always better than make
Config is much better. For the make menuconfig interface:
When you select the corresponding configuration, there are three options, which represent the following meanings:
Y -- compile this function into the kernel
N -- do not compile this function into the kernel
M -- compile this function into a module that can be dynamically inserted into the kernel as needed
If you are using make xconfig, you can select the corresponding option with the mouse. If you are using
Make
Menuconfig, you need to use the space key for selection. You will find a bracket in front of each option,
However, there are brackets, angle brackets, and parentheses. When using the space key, you can find that the brackets are either empty or "*", while the angle brackets can be empty, "*" and "m ". This indicates that the items corresponding to the former are either not or compiled into the kernel. The latter selects the same item and can be compiled into modules. The content of the parentheses is to select one of the options provided.
The Kernel configuration options are briefly introduced in my article below:
Brief Introduction to Linux kernel compilation and configuration options (1) and
Brief Introduction to Linux kernel compilation and configuration options (2)
6. Compile and use the following command:
# Make Dep
# Make clean
# Make bzimage or make zimage
# Make modules
# Make modules_install
# Depmod-
First Command make
Dep actually reads the configuration file generated during the configuration process to create the dependency tree corresponding to the configuration, so as to determine which compilation is required and which ones are not required. The second command is "make ".
Clean: delete the files left in the previous step to avoid some errors. Make zimage and make
Bzimage fully compiles the kernel. The kernel generated by the two is compressed by G ***. Only one of them is enough. The difference between them is that make
Bzimage can generate a larger kernel. We recommend that you use the make bzimage command.
The following three commands are only used to answer the Enable loadable module
"Yes" is required for support (config_modules). Make modules and make
Modules_install generates the corresponding modules and copies the modules to the required directories.
Strictly speaking, depmod
-The a command has no relationship with the compilation process. It is used to generate the dependency between modules. After you start the new kernel, You can correctly locate the module when using the modprobe command to load the module.
VII. Update part of content
After the above steps, we finally get the new kernel version. To be able to use the new kernel version, we also need to make some changes:
# Cp/usr/src/Linux/system. MAP/boot/system. Map-2.4.18
# Cp/usr/src/Linux/ARCH/i386/bzimage/boot/vmlinuz-2.4.18
The above two files are newly generated during compilation. Next, modify the two links system. Map and vmlinuz under/boot to point them to the new kernel file:
# Cd/boot; RM-F system. Map vmlinuz
# Ln-s vmlinuz-2.4.18 vmlinuz
# Ln-S system. Map-2.4.18 system. Map
8. Modify the startup Manager
If lilo is used, modify/etc/Lilo. conf and add the following items:
Image =/boot/vmlinuz-2.4.18
Label = linux240
Read-Only
Root =/dev/hda2
The root =/dev/hda2 line must be modified as needed.
Run:
#/Sbin/lilo-V
Make sure that you have edited/etc/Lilo. conf correctly. Now restart the system:
# Shutdown-R now
If you use grub to start the manager, add the following items.
Title Red Hat Linux (2.4.18)
Root (hd0, 0)
Kernel/vmlinuz-2.4.18 Ro root =/dev/hda2
Grub automatically takes effect without calling the command again.
After the restart, you can use the new kernel.

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.