How to compile the Linux Kernel

Source: Internet
Author: User
How to compile the Linux operating system kernel-general Linux technology-Linux programming and kernel information. For more information, see the following. I. Configuration

1. configuration tools
Before configuring the kernel, run the command "make clean | make mrproper" to clear the compiled executable file and check the integrity of the source code tree.

Linux provides the following four Kernel configuration tools. You need to run one of the following commands on the top layer of the source code directory.
(1) make config: Query all configuration options in sequence.
(2) make oldconfig: Use the. config file as the configuration file, and only ask about the options in which it is not configured. It is generally used to upgrade the kernel to the latest version.
(3) make menuconfig: Use a text-based menu to provide configuration help. This is the most widely used method, but it requires the support of the ncurses library.
(4) make xconfig/gconfig: Use the X-Windows interface menu to provide configuration help. The former requires the support of the qt Library and the latter requires the support of the gtk library.
After the configuration is complete, A. config file is generated at the top level of the source code Directory, which contains all the configuration options. In addition, an autoconf. h file will be generated under the include/linux directory of the source code. The "CONFIG _ *" is used to define the options to be included by the C Preprocessor.

2. Prompt
(1) always enable the "Prompt for development... drivers." option.
(2) starting from version 2.6.8? Append to kernel release adds the identifier used to personalize the kernel. For the old version of the kernel, You need to modify the EXTRAVERSION item in the Makefile file.
(3) Disable module versioning and enable the module loader, kernel module, and module uninstaller.
(4) disable unnecessary options and only enable those necessary items.
(5) ensure that the correct CPU type (/proc/cpuinfo) is selected ).
(6) Find the installed PCI device (lspci-v ).
(7) Check the options compiled by the current kernel (dmesg ).
(8) for the Kernel Hacking item, all options except "Use 4Kb for kernel stacks instead of 8Kb" are enabled. If the machine performance is insufficient, disable the Debug memory allocations option.

Ii. Compilation

After the kernel is configured, compile the kernel as follows:
(1) make-j [jobs] bzImage
Here, the "-j" option indicates the number of commands defined in Makefile that are executed at the same time. Since the source code needs to be read from the disk first, it is best to execute two commands simultaneously on one processor. If an error occurs during compilation, it is best to use a single thread to re-compile, in order to better locate the error. The compiled kernel module is placed in the arch/i386/boot directory of the source code, named bzImage.
(2) make modules --> make modules_install
If the module is enabled, use these two commands to compile and install the module. Before installing a new module, You 'd better back up the current module (command: mv/lib/modules/'uname-R'. bak ). The compiled modules are installed in the/lib/modules/[version] Directory ([version] can be found in the include/linux/version. h file ).
If only the source code of a module is modified, you do not need to use the above two commands to compile and install all the modules. For example, if only the drivers/char/foo file is changed. c, you can use the command "make-C [source code top-level Directory] SUBDIRS = $ PWD modules" under the drivers/char directory to compile the files under this directory, and automatically re-compile all required files, and then use the command "insmod foo. ko to install the module. (before compiling and installing the module, run the "rmmod foo. ko command to remove the installed modules ).

3. Use new kernel boot

Note: retain at least one Boot Loader and kernel that can use and start the system for recovery if necessary.
(1) run the "make install" command to install the kernel to the/boot directory.
(2) modify the/etc/grub. conf file (use GRUB for Guidance ). In this file, partial formats of the boot options are described as follows:
Title Linux
Root (hd0, 0)
Kernel/vmlinuz ro root =/dev/hda3
Initrd/initrd. img
The title item specifies the menu item displayed when the system is selected; the root item specifies the hard disk number and Partition Number of the/boot directory; the kernel item specifies the location of the kernel and provides corresponding options, note that the path is relative to the root directory path specified by the root user. The initrd item is optional and is used to load some files before the root file system is mounted (usually only recognized by a specific release) kernel module.

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.