Linux 2.6.31 kernel Compilation Method

Source: Internet
Author: User


1. Download source code

 

$ Wget Linux-kernel/v2.6/linux-2.6.31.tar.bz2

 

2. decompress the source code

 

$ Tar-jxvf linux-2.6.31.tar.bz2-C/usr/src/

Tip: Of course, it is not necessary to decompress it to/usr/src/. You can decompress it to any location.

 

3. Check the source code (this step is not required ):

 

$ CD/usr/src/linux-2.6.31

 

$ Make mrproper

 

Tip: This step is used to check whether the source code contains. O files and dependencies. This step is not required during source code compilation. It is better to use it with make clean (mainly to clear the. o file). Make mrproper mainly clears environment variables and configuration files.

 

4. Compile the kernel

 

By default, the compiled and output files are stored in the source code directory. You can use the O = output/DIR parameter to specify the location of the output file (letter O, not number 0 ). Many people who compile the kernel for the first time will encounter a problem. The space in the partition where/usr is located is not enough. In this case, this parameter is very useful.

 

The source code provides a lot of configuration methods, it is recommended to use menuconfig: Enter/usr/src/linux-2.6.31, has been entered is skipped: $ CD/usr/src/linux-2.6.31

 

Create/build/kernel menuconfig Folder: $ sudo mkdir-P/home/your username/build/kernel menuconfig

 

Use menuconfig to configure: $ sudo make o =/home/your username/build/kernel menuconfig

 

For the first time to compile the kernel, it is not recommended to start directly from the default Kernel configuration, it is recommended to use the release version of the built-in configuration file, usually/boot there will be a config-2.6.xx file. Select load an alternate configuration file, enter the name of the config file under/boot, and load the file. For the first compilation, it is best not to modify the configuration at will. If the configuration fails, it will leave a mental shadow :-) in the configuration, you can modify the configuration according to your own needs, don't change anything you don't understand. Do not forget to save the file after it is finished. Fill in. config as the file name is saved.

 

Note: If the ncurses Development Library cannot be found, run the sudo apt-Get install ncurses-dev command and re-run the preceding command.

 

Next, we will start the official compilation. Compilation may take some time. To avoid unexpected shutdown of the terminal, you can use screen. The specific usage will not be discussed here.

 

$ Make o =/home/name/build/kernel

 

To speed up compilation, you can use the-J parameter to enable multithreading. For example, a dual-core CPU can be compiled in this way.

 

$ Make-J4 o =/home/name/build/kernel

 

Generally, the N value of-JN is twice the number of cores.

 

5. Install the kernel

 

$ Sudo make o =/home/name/build/kernel modules_install install

 

6. Generate initrd

 

$ Sudo mkinitramfs-O/boot/initrd-img.2.6.31 2.6.31 for other mkinitramfs parameters, refer to man mkinitramfs. For more information about the role of initrd, search for it by Google. I will also write an article to analyze initrd recently.

 

7. Modify Guide

 

Grub can be used directly:

 

$ Sudo Update-grub

 

You can also edit the/boot/GRUB/menu. lst or/boot/GRUB/grub. cfg file by yourself.

 

8. Restart

 

After the restart, run the following command to check whether the compiled kernel is used:

 

$ Uname-

 

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.