Linux Kernel Compilation

Source: Internet
Author: User

 

How to compile the Linux kernel? I believe you will get many different answers, and I always get some compilation errors before writing this article.

How do you always encounter compilation errors or failures? In many cases, the problem is that you download the kernel version, that is, compiling the kernel of the lower version in the GCC version causes compilation failure. If you are familiar with compiling the kernel, You can Google many compilation methods on the Internet, but they all fail. Let's take a look at the kernel readme document or run make help in the kernel directory. It will tell you many secrets you don't know.

1. General methods for compiling the kernel in Linux

The readme file in the kernel code has a very detailed introduction to the compilation process. The method described below is the General Compilation Method of the Linux kernel, which is the compilation process defined by the MAKEFILE file.

1) download the source code (taking 2.6.28 as an example)

Wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.28.1.tar.gz

2) decompress the package and put it in the/usr/src/directory.

Gzip-D linux-2.6.28.1.tar.gz

Tar-xvf linux-2.6.28.1.tar

MV-RF linux-2.6.28.1/usr/src

3) create a soft link to the linux-2.6.28.1 directory in/usr/src/

CD/usr/src

Ln-s linux-2.6.28.1 Linux

CD Linux

4) Clear the source code (if some intermediate files have been generated before, you can run this command, otherwise it will not be necessary)

Make mrproper

5) generate the config file

CP/boot/config-'uname-R'./. config

Make menuconfig

On the make menuconfig configuration page, select load config file, load the file to be copied before modification. After modification, select exit directly, then, in the prompt, choose to save the current configuration file.

6) Compile

Make

7) Installation Module

Make modules_install

This command will put the module and related files under the/lib/modules/2.6.18.1/directory and will not conflict with the current kernel unless the kernel version is the same.

8) install the kernel

Make install

This command will put the kernel-related files (bzimage, initrd. IMG, system. Map. config) under the/boot/directory. The file names all contain the kernel version names, which are different from other versions.

If lilo is installed on the system, it will add the startup of the kernel. If it is a grub program, it depends on the situation. In the fodera system, it automatically adds the boot item to the/boot/grup/menu. LST file, but not in Ubuntu. You need to manually add it. After adding the kernel, restart the new kernel.

2. Ubuntu kernel compilation method.

The general method described above is suitable for all Linux systems, and Ubuntu is no exception. Ubuntu also provides kernel compilation methods. The method is very simple. Replace steps 6th and 7 with the following command.

Make-kpkg -- initrd -- append-to-version <your_tag> kernel_image kernel_headers

<Your_tag> adds the specified string to the kernel name based on the version number. If you want to directly use the kernel version number as the kernel name, remove -- append-to-version and its parameters from the command line. I personally recommend that you do not use this option, because the kernel name is the running result of uname-R, so that sometimes the uname-R and make kernelrelease results are inconsistent when new module programs are compiled.

After this fate line is complete, two Deb packages are generated. The other is the kernel and module package, and the other is the Deb package of the header file. If not, remove kernel_header from the command line.

It is easy to install the kernel. You only need to install the Deb package of the generated kernel image. Run the following command:

Dpkg-I linux-image-2.6.28.1_2.6.28.1-10.00.Custom_i386.deb

After the installation is complete, all the operations are completed, and the Startup menu items of/boot/GRUB/menu. lst are modified. All you have to do is restart the system.

The advantage of using this method is self-evident: you only need to compile a newer Kernel on a Ubuntu server to upgrade it throughout the lab. Why not?

3. fodera kernel Compilation Method

Sorry, we have not found a very accurate fodera kernel compilation method, which will be completed later. However, the method described here is still applicable to the fodera system, that is, compiling the kernel into an RPM package like ubuntu. It is also very simple. You only need to replace step 6th and Step 7 with the following command:

Make rpm-PKG

After running, the kernel RPM package is located under the/usr/src/RPM/RPMS/i386/kernel-2.6.28.1.i386.rpm using rpm-I
Kernel-2.6.28.1.i386.rpm
Command to install.

After the RPM installation is complete, check whether the/boot/grup/menu. LST file has started the new kernel. If not, manually add it.

 

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.