Compile the Linux3.0.4 kernel in Ubuntu

Source: Internet
Author: User
The Linux kernel version 3.0 has been released for some time. I don't know whether the kernel of this version is easy to use. However, at present, linux of each release version still does not use the 3.0 kernel, so you can compile the kernel yourself to feel it! This opportunity to compile the kernel allows you to familiarize yourself with the kernel compilation steps. 1. Download and decompress the kernel to any directory and download the latest kernel source code 3.0.4 from the source code official website. You can decompress the kernel to any directory and put it in the main directory :~ $ Tarxjvf & n

The Linux kernel version 3.0 has been released for some time. I don't know whether the kernel of this version is easy to use. However, at present, linux of each release version still does not use the 3.0 kernel, so you can compile the kernel yourself to feel it! This opportunity to compile the kernel allows you to familiarize yourself with the kernel compilation steps.

1. Download and decompress the kernel to any directory

Download the latest kernel source code 3.0.4 from the official website of the source code. You can decompress the package to any directory. Put it in the main directory:

  1. ~ $ Tar xjvf linux-3.0.4.tar.bz22. Configure the kernel

The kernel is configured to obtain the Kernel configuration file. config. By configuring the kernel, you can increase or decrease the support for some kernel features for the kernel that is successfully compiled in the future. There are multiple methods to configure the kernel, including text-based configuration methods and graphical user interfaces. The following uses the make menuconfig method that is widely used:

  1. ~ /Linux-3.0.4 $ sudo apt-get install libncurses5-dev ~ Linux-3.0.4 $ sudo make menuconfig

Because the configuration method is based on the ncurses library, you must install the ncurses library before starting the configuration interface. Before starting the configuration interface, you must enter the source code root directory. After the configuration interface is started successfully, see:

The kernel is compiled according to the default configuration method. Therefore, you can exit and save the configuration menu after it is started. In this case,. config is generated under the root directory of the kernel source code.

3. Compile the kernel

Now we can compile the kernel, but the entire compilation process is long. Therefore, we can add the-j parameter to make to improve the compilation efficiency. Using this option in make will allocate n concurrent tasks to the compilation process, which can shorten the Compilation Time. N is twice the number of CPUs.

  1. ~ Linux-3.0.4 $ sudo make-j4

The above process involves two parts: one is to compile the kernel, that is, the part of the kernel marked as Y in the compilation configuration option; the other is to compile the kernel module, that is, the part of the kernel marked as M in the compilation configuration option.

4. Install the kernel module and Kernel

First, install the kernel module. This process copies the kernel module generated when the kernel module is compiled to the/lib/modules/3.0.4/directory, where 3.0.4 is the corresponding kernel version. The command used is as follows:

  1. ~ Linux-3.0.4 $ sudo make modules_install

Run the following command to install the compiled kernel:

  1. ~ Linux-3.0.4 $ sudo make install

The kernel installation process mainly completes the following tasks:

1. Copy the kernel image bzImage generated during kernel compilation to the/boot directory and name it vmlinuz -. If you use an x86 cpu, the image is located in the arch/x86/boot/directory (under the kernel source code being compiled ).

2. Change ~ Copy System. map under the/linux-3.0.4/directory to the/boot/directory and rename it System. map-3.0.4. This file contains the symbol table of the kernel.

3. Change ~ The. config under the/linux-3.0.4/directory is copied to the/boot/directory and renamed as a config-3.0.4.

5. Create the initrd. imgfile

Initrd. img is the initial ramdisk file. It is an image file that packs some basic drivers and command tools into the image file. This image file is used to release the initrd file to the memory before the system has mounted the root partition, as a virtual root partition, execute related scripts and run the insmod command to load the required modules.

The specific creation method is as follows:

  1. ~ /Linux-3.0.4 $ sudo mkinitramfs 3.0.4-o/boot/initrd. img-3.0.4
6. Update grub

The last step is to update the grub Startup menu. You can use the following command to automatically update the Startup Menu:

Sudo update-grub2

In this way, the compiled kernel is placed first in the Startup menu. If you need to modify the default system startup sequence in the Startup menu, modify/boot/grub. set default = In the cfg file.

OK. The kernel has been compiled.

Related Article

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.