Linux Kernel compilation steps

Source: Internet
Author: User

Linux Kernel compilation steps
For new Linux users, it is relatively difficult to compile the kernel, and I don't even know how to start with it. By collecting this information on the Internet, I finally compiled it successfully.
I have summarized this article, and it is still a relatively detailed step. I hope you will have some suggestions for new users.
Help.
1. Preparations
(1) sort out the hardware, file system types, and network protocols to be supported by the system.
(2) run the uname-R command to check the system version. If your system version is the same as the kernel version to be compiled, back up the content under/lib/modules, otherwise, the file generated by the make modules_install step will overwrite the content in this path.
(3) A: Download and decompress the Linux kernel, it is recommended to download the kernel from the http://www.kernel.org/pub/linux/kernel/, because the source code installed during the installation of the system supports many devices by default, this increases the difficulty of Kernel Cutting. Assume that you have downloaded the linux-y-z.tar.gz file. Generally, the Linux kernel source code is put under/usr/src. We still follow this habit. If the kernel version already exists under your path, we recommend that you change the name of the existing kernel.

B: If the kernel has been installed (/usr/src/directory has a Linux subdirectory), skip if not installed, put the Linux installation CD in the optical drive, find the kernel-source-2.xx.xx.rpm file (XX represents a number, (For example, the RPMs directory of RedHat Linux is the/RedHat/RPMS/directory, and then install the kernel using the command rpm-IVH kernel-source-2.xx.xx.rpm)

2. Clear the residual. O files and unnecessary associations during previous kernel compilation.
CD/usr/src/Linux
Make mrproper
Make sure that there is no correct. o file and file dependency in the source code directory. After executing this command, the kernel option will return to the default state. If you download the kernel source code and it is the first compilation, you do not need to perform this step.

3. Configure the kernel and modify relevant parameters. For more information, see.
In the graphic interface, make xconfig; In the character interface, make menuconfig
Set a kernel option correctly in the Kernel configuration menu, save and exit

4. correctly set the associated file
Make Dep
Create the file dependency based on the options selected in the previous step.
5. Make clean
Clear unnecessary files. If you delete some options based on the previous compilation, we recommend that you perform this step. Otherwise, it is unnecessary.

6. Compile the kernel
For large kernels (such as SCSI support), make bzimage
For small kernels, make zimage

7. Compilation Module
Make modules
Compile and load the module (that is, select m as the kernel option). The compilation time is related to the number of M options.

8. Installation Module
Make modules_install
Copy compiled modules to/lib/modules, which is why you are reminded of the backup in step 3 of "Preparation.

9. Use the new kernel
Method 1:
(1) kernel replacement: A, MV/usr/src/linuxx. x. x/system. MAP/boot/system. Map
B. mV/usr/src/linuxx. x. x/ARCH/i386/boot/bzimage/boot/vmlinuz
(2) modify the/etc/Lilo. conf file, add a startup option, and start it with the new kernel bzimage/zimage. The format is as follows:
Boot =/dev/hda
Map =/boot/Map
Install =/boot. B
Prompt
Timeout = 50
Linear
Default = Linux-New ### tell lilo to start Linux using the new kernel by default ###
Append = "mem = 256 m"

Image =/boot/vmlinuz-2.2.14-5.0
Label = Linux
Read-Only
Root =/dev/hda5

Image =/boot/bzimage (zimage)
Label = Linux-New
Read-Only
Root =/dev/hda5

Retain the old boot options to ensure that the new kernel cannot be booted. You can also perform other operations in Linux.

After saving and exiting, do not forget the most important step. Run/sbin/lilo to make the modification take effect.
Method 2: Use grub (modify the grub. conf file)
(1) kernel replacement: A, MV/usr/src/linuxx. x. x/system. MAP/boot/system. Map
B. mV/usr/src/linuxx. x. x/ARCH/i386/boot/bzimage/boot/vmlinuz
(2) modify the Boot manager grub,/etc/grub. conf
The content is as follows:
# Boot =/dev/had
Default = 0
Timeout = 10
Splashimage = (hd0, 0)/GRUB/splash.xpm.gz
Title Red Hat Linux (2.4.20-8)
Root (hd0, 0)
Kernel/vmlinuz-2.4.20-8 Ro root = label =/
Initrd/initrd-2.4.20-8.img
Method 3: Modify the startup configuration file
Currently, grub is used to start. You need to modify/boot/GRUB/grub. conf and add the corresponding startup information. The simplest format of the content to be added is as follows:
Title name displayed on the Startup Menu
Root file system mount Partition
Kernel File Name compressed by Kernel
Initrd root file system file name
For example:
Title my new kernel
Root (hd0, 2)
Kernel/boot/vmlinuz-x.y.z
Initrd/boot/initrd-x.y.z.img
10. regenerate the RAM disk
If/etc/Lilo. conf in your system does not use the RAM disk option initrd, skip
If/etc/Lilo. conf in your system uses the RAM disk option initrd,
Run the mkinitrd initrd-kernel version number command to regenerate the RAM disk file, for example, my RedHat 6.2:
Mkinitrd initrd-2.2.14-5.0 2.2.14-5.0
Then point initrd in/etc/Lilo. conf to the new initrd-2.2.14-5.0 file:
Initrd =/boot/initrd-2.2.14-5.0

The RAM disk can optimize the system performance as much as possible. For details, see the/usr/src/Linux/documents/initrd.txt file.

11. Restart. OK!

========================================================== ========================================================

Http://www.51cto.com/art/200707/52008.htm

This article is based on the 2.6 kernel. We also recommend that you take a look at "Linux kernel design and implementation (version 2)" as a basic knowledge. Of course, from a practical point of view, as long as you follow the steps below, you should be able to successfully compile the kernel and load the module.

For Linux: Debian GNU/Linux and 2.6.20-1-686.

◆ Step 1: Download the source code of the Linux kernel, that is, build the kernel tree mentioned above in ldd3 (Linux Device Drivers 3rd.

If the source code is already included in the installed Linux system, it should be in the/usr/src directory. If the directory is empty, you need to manually download the source code. There are a lot of methods and links for downloading code, or can it be done on the Cu via http://download.chinaunix.net/search? Key = & Q = Kernel & frmid = 53. However, the downloaded kernel version should be the same as the kernel version of the running Linux system. Of course, it can also be lower than the Linux kernel version, but it should not work if it is higher (I have not practiced it ).

Debian can be easily downloaded from the Debian Source:

First, find the downloadable kernel source code:

# Apt-cache search Linux-Source

The display is: linux-source-2.6.20, not exactly match with my kernel version, but it does not matter, direct download can be:

# Apt-Get install linux-source-2.6.20

After the download is complete, install in/usr/src, the file name is: linux-source-2.6.20.tar.bz2, is a compressed package, extract can get the source code of the entire kernel:

# Tar jxvf linux-source-2.6.20.tar.bz2

Decompress the package and generate a new directory/usr/src/Linux -- source-2.6.20. All source code is in this directory.

Note: This directory varies with the kernel version. You only need to know the specific location of your source code.

◆ Step 2: Configure and compile the kernel.

Go to the/usr/src/Linux -- source-2.6.20 directory, and you can see the MAKEFILE file, which contains the entire kernel tree compilation information. The top four lines of this file are about the kernel version. You do not need to modify the entire makefile. You can use the default value.

Generally, you need to configure the kernel by using commands such as "make menuconfig", "Make xconfig", or "make oldcofig". These commands are used to configure the kernel, but they run in different environments. execute any of these commands to configure the kernel:

Make menuconfig is an interface-Based Kernel configuration method. Make xconfig should be based on the qt library, and make gcofig is also a graphical configuration method. It should be a GTK environment, make oldcofig is the original kernel tree. configure the config file.

In fact, the Kernel configuration is mainly to ensure that the kernel startup module can dynamically load the configuration. The default configuration should already contain such content. Therefore, I use make oldconfig.

Run the following command in the kernel source code directory:

# Make

# Make bzimage

The first make statement can also be executed without making bzimage. This process may take about an hour, so it is re-compiled for the entire kernel. After the execution is complete, a new file named vmlinux is generated in the current directory. Its attribute is-rwxr-XR-X.

Then execute:

# Make modules

# Make modules_install

Compile and install all kernel modules.

After the execution, a new directory/lib/modules/2.6.20/is generated under/lib/modules /. The build directory under this path will be used for subsequent compilation of module files. So far, the kernel compilation is complete. You can restart the system.

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.