Opensuse kernel compilation tutorial (kernel 2.6.x)

Source: Internet
Author: User
Tags andrew morton

The http://cn.opensuse.org/OpenSUSE_%E5%86%85%E6%A0%B8%E7%BC%96%E8%AF%91%E6%95%99%E7%A8%8B_ (kernel_2.6.x)

Contents [hide]
  • 1 Statement
  • 2. Overview
  • 3 Basic Knowledge
    • 3.1 What is the kernel?
    • 3.2 What is a patch
    • 3.3 why re-compile the kernel?
    • 3.4 If the upgrade fails, how can I restore the official kernel?
  • 4. Compilation steps
    • 4.1 requirements
    • 4.2 download kernel source code and patches
      • 4.2.1 obtain the kernel source code
    • 4.3 patch the kernel source code
      • 4.3.1 select the required patch
        • 4.3.1.1 common patch Systems
        • 4.3.1.2 common SuSE Patches
      • 4.3.2 patch sequence and Method
        • 4.3.2.1 Sequence
        • 4.3.2.2 single patch file
        • 4.3.2.3 GZ/bz2 patch
    • 4.4 configure and compile the kernel
      • 4.4.1 configure the kernel
      • 4.4.2 common kernel Optimization Configuration
      • 4.4.3 compile the kernel
    • 4.5 = Update kernel-headers
  • 5. Final work
  • 6. Cleanup
    • 6.1 clear old files
    • 6.2 clear the grub startup list
Statement

1. It is not recommended that you compile the kernel on your own, especially for new users who do not compile software. All consequences and losses arising from compiling the kernel are borne by yourself. The author thruth of this document is not liable for this.

2. Focus on understanding and do not back up the operation steps.

3. Life is precious. Do not try it easily in patients with high-risk emergency such as anxiety, heart disease, coronary heart disease, cerebral thrombosis, and hypertension. If you have to compile the kernel, please first prepare the relevant ambulance measures, the whole process should be accompanied by medical staff.

4. If your mind is not mature, do not post the Linux kernel and release versions.

Note: This document does not apply to 2.4.x series kernels and only to 2.6.x series kernels.

Brief Introduction

This document briefly introduces the kernel and describes the steps and precautions for compiling the 2.6.x kernel in opensuse.

Basic knowledge what is Kernel

The kernel is the core of a Linux system. It provides underlying functions such as hardware abstraction layer, disk and file system control, and multi-task concurrency management.

What is a patch?

The Linux kernel is maintained by the kernel Team (http://www.kernel.org) who provide the latest stable version of kernel source code on the home page. This is the original pure kernel code.

As mentioned above, the original kernel is generally modified for various reasons. The source code modification is implemented by patching, and each kernel patch implements a specific function. The patch download addresses are scattered and self-search is more effective.

Compile the source code of the kernel that has been patched to obtain the binary file that can be recognized by the computer, which is the (finished) kernel we use everyday.

Why re-compile the kernel?

Opensuse has made many modifications to the kernel source code to improve the hardware compatibility and stability of the system. Conservative optimization parameters are also used during compilation. In this way, the kernel size is large and the running speed is slow, but the stability and compatibility are excellent.

There are three reasons for compiling the opensuse kernel:

1. Improve kernel compatibility or add features

Despite many official opensuse patches, they may still not meet user needs. You may need to install a specific patch or update the kernel version to support new hardware or add support for a software.

2. System Acceleration

As mentioned above, the performance of the official kernel is reserved. recompiling the kernel based on your hardware configuration and using appropriate optimization parameters is the most effective way to speed up the system.

3. Psychological Needs

People like thruth, the author of this document, always want to use the latest kernel version and recompile the kernel repeatedly.

If the upgrade fails, how can I restore the official kernel?

Start SuSE Linux on the installation CD, and enable YaST to refresh the kernel and related packages.

Compilation steps

To compile the kernel, install necessary compilation software.

Binutils GCC make module-init-tools udev ......

Download the kernel source code and patch to obtain the kernel source code

For opensuse users, there are five ways to obtain the kernel source code and patch. Please select as needed:

1. Use the official kernel-source package

Whether the kernel-source package comes with the installation disk or YaST-> Software-> the kernel-source package updated online, it is officially provided with the kernel source code that has been patched.


Note: This package is best consistent with the kernel-default package version in the system.

Advantages: it can be used directly and is secure and stable, with almost no errors

Disadvantage: The version will not be the latest and has been patched, so there is little room for performance improvement

Instructions for use: directly install and use


2. Use the SRC. RPM package of the official kernel-Source

The src directory is always available on the official image website that installs or updates the source, including various software source code. You can find SRC. RPM of kernel-source.

For example, the file http://ftp.novell.co.jp/pub/suse/suse/update/10.1/ can be found in the RPM/src directory under an image kernel-source-2.6.16.21-0.13.src.rpm Of The SuSE 10.1 official update source

Note: After extracting the package, you must manually select the patch and move the directory. If you have no requirements for the kernel version, we recommend that you use this method to obtain the kernel source code and patches.

Advantage: the kernel and patch versions are the same, so the patching operation will basically not fail. Self-patching will significantly improve the performance.

Disadvantage: the version is not the latest and needs to be decompressed multiple times. You must have a certain understanding of the entire software and hardware system.

Usage: Decompress the file-roller or rpm2cpio command of the graphics program to a directory. The files to be used and comments are as follows:

Config.tar.bz2 # according to the system architecture classification of the config Kernel configuration file linux-0000.tar.bz2?original internal kernel code novell-kmp.tar.bz2 # Novell upgrade # kernel.org official version incremental upgrade patch (with the built-in sec. rpm does not have this file: patches.suse.tar.bz2 # SuSE dedicated patch patches.uml.tar.bz2 # Patches required for the UML patch patches.xen.tar.bz2 # xen Virtual Machine

Extract the original kernel code to the/usr/src/directory. The kernel-source-2.6.16.21-0.13.src.rpm mentioned above is used as an example.

$ tar jxf linux-2.6.16.tar.bz2$ su# mv linux-2.6.16 /usr/src/


3. Use the kernel-source package of the source suser-jengelh

This installation source is in the http://ftp-1.gwdg.de/pub/linux/misc/suser-jengelh/SUSE-10.1/

Note: The version is higher than the official version. It has multiple versions and contains the unstable version of the kernel. Do not use it unless you have.

Advantage: None

Disadvantage: the system architecture is incomplete. In most cases, only the 32-bit version is supported. Some patches and configuration files cannot follow up with the new version, which is very prone to various problems.

Usage: if you are not afraid of death, install and use it directly.


4. Use the SRC. RPM package of the source suser-jengelh kernel-source to be installed unofficial

This installation source is in the http://ftp-1.gwdg.de/pub/linux/misc/suser-jengelh/SUSE-10.1/, And the src directory contains many kernel-source. version. SRC. rpm

Note: The version is higher than the official version. It has multiple versions and contains the unstable version of the kernel. Do not use it unless you have.

Advantage: None

Disadvantages: Some patches and configuration files cannot be followed up with the new version, which is very prone to various problems.

Usage: if you are not afraid of death, use the official kernelsource SRC. RPM package.


5. manually download the original kernel code and patches

The original kernel source code is downloaded in the http://www.kernel.org, and patches are searched and downloaded or decompressed using the latest official SRC. RPM patch.

Note: using this method requires you to have a good understanding of your hardware and Linux system. Be careful when tossing. Generally, it's okay.

Advantages: flexibility, new version, and obvious Performance Improvement

Disadvantage: Some patches suitable for the latest version may not be found, so you must have a good understanding of the entire software and hardware system.

Usage: Decompress the downloaded Linux source code package to the/usr/src/directory. Here, the latest official stable version of the kernel is used as an example:

$wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.18.tar.bz2$tar jxf linux-2.6.18.tar.bz2$su#mv linux-2.6.18 /usr/src/
Patch the kernel source code

The original kernel source code has been put into the directory of/usr/src/Linux-version. In the example used above, the source code using the official SRC. RPM should be in the/usr/src/linux-2.6.16 directory; instead, download the original kernel source code in the/usr/src/linux-2.6.18 directory.

The kernel source code upgrade may invalidate a patch, so it is not a patch that can "fill" all versions of the kernel. If the patch cannot be used on the new kernel, there are two situations: first, the kernel has been "supplemented" by the kernel, or the patch has expired the new kernel code. In any case, search for an error or create a new patch based on the original patch.

Select the required patch

This is a test of your understanding of the system, there are a lot of hardware and patches on the earth, the specific system and hardware selection and patches are not covered in this document. However, it is very easy to select the standard for patching. The first is hardware, the second is functional, and the last is psychological. There is no need to add all the patches. To put it simply, the more patches, the slower the system.

The hardware needs to be patched based on your hardware. A small part of the hardware uses the original kernel to cause disorder or weakness to varying degrees of functionality, and some do not affect normal use, but keep reporting errors in logs; in this case, you can use a patch to fix the problem.

A large number of Patches exist in SRC. RPM of kernel-source. decompress the bz2 files starting with patches. First, run the root permission lsmod to check which modules have been loaded, and then find out if the patch file name contains a module name. If yes, check the system architecture and other information. You don't have to take a closer look at each file name. If you are an Acer notebook, the file name containing IBM Asus has nothing to do with you. Similarly, if you are a 32-bit system, the patch with x86_64 IA64 PPC in the file name does not make sense to you. If you use amd cpu and chipset, you do not have to look at the patch with Intel name. You are not sure whether the patch is required. You can click it to view the comment at the beginning of the file.

Remember, if you only have a rough understanding of your hardware, You can first do not play or play a few hardware patches that you think are necessary. If something goes wrong, follow the log prompts, search to see if a patch is required, and then recompile it with the patch.

The feature requires that some software must be patched to implement its own functions. In order to make these software run normally, it has to be patched, such as the bootsplash patch mentioned below. If you do not know about this, you can wait for a problem and search again.

The psychological need is to have emotional dependence on some patches for various reasons. If you do not apply the patches, the users will be in bad mood. In order to avoid serious unpredictable consequences, appropriate patches should be installed to avoid such situations.

Common patch Systems

MM patch:

Http://kernel.org/patchtypes/mm.html

A series of patches compiled by Andrew Morton, the 2.6 maintainer, have many upgrades to kernel components and hardware compatibility patches. It is very important and commonly used.

AC patch:

Http://kerneltrap.org/forum/linux/kernel/2.6/ac

A set of patches maintained by Alan Cox of RedHat. It is generally used to add hardware support patches.

CK patch:

Http://members.optusnet.com.au/ckolivas/kernel/

A set of patches maintained by Con kolivas. A large number of performance optimization patches are included, which are applicable to both desktop and server. If you want to speed up the system, you can choose to use some of the patches, all of which may cause a crash.

Common SuSE Patches

Apparmor patch-works with Novell apparmor software as a unique security module for SuSE.

Bootsplash patch-animation when the system is started.

Flush-o-fat patch-add-O acceleration parameters to the hard drive written to the fat format. Without this patch, the mobile hard drive in the fat format may not be automatically mounted.

Patch Order and method order

Patch patching is performed sequentially. Generally, the incremental update patch provided by the official website is used first, followed by the patch required by the hardware, and then the patch required by the function. The priority of the psychological requirement patch is higher than that of all patches, or even higher than the kernel source code itself.

To use SRC. rpm, You need to incrementally upgrade the patch to the new version. You do not need to take this step because the source code of the original kernel is the latest.

Single patch file

A single patch file may have the following suffix. Diff. patch or no suffix. It is essentially a plain text file and can be opened and modified in a text editor. The patch method is as follows:

# Cd/usr/src/Linux-version # patch-P1-I/path/patch file name

For example, I manually download a file patch bootsplash for the pure kernel to enable the animation before the boot enters X and download the patch suitable for the latest kernel version, file is/home/truth/New/patches/bootsplash-2.6.18.diff

#cd /usr/src/linux-2.6.18#patch -p1 -i ~truth/new/patches/bootsplash-2.6.18.diff
Patch in GZ/bz2 format

Not all GZ/bz2 files can be patched using the following method. Such files must only contain more than one single file patch and should not contain other impurities. Therefore, this method should first open the GZ/bz2 compressed package to check whether the conditions are met. In essence, this patch method is to patch a single file in the ascending order of file names in the compressed package. Run the following command:

# Cd/usr/src/Linux-version GZ compressed package: # zcat path/file name .gz | patch-p1bz2 compressed package: # bzcat path/file name .bz2 | patch-p1

Here we use the official SRC. RPM source code as an example. The kernel incremental patch is the patches.kernel.org.tar.bz2 extracted from SRC. rpm in the/home/truth/New/patches/directory.

#cd /usr/src/linux-2.6.16#bzcat ~truth/new/patches/patches.kernel.org.tar.bz2 | patch -p1

Some patches in the compressed package have requirements on the path. Generally, they can be placed in the/usr/src/directory. For more information about patch commands, see info patch.

After the patch is completed, we begin to enter the Kernel configuration phase.

Configure and compile the kernel and configure the kernel

The configuration kernel is to generate a. config file in the source code Directory, which defines the parameters required for Kernel compilation. The configuration file directly determines the hardware, functions, and running speed supported by the final kernel. Configuring the kernel requires more understanding of the system and various hardware than patching.

Fortunately, after opensuse is installed, the Kernel configuration file has been stored by default in/boot/config-version-default. If your system is SuSE Linux 10.1 and an official kernel update is performed, the file is/boot/config-2.6.16.21-0.13-default. We can copy this file to the kernel source code directory, and then modify and optimize it. Of course, if you are sure you can configure the kernel on your own, you don't have to take this step. You just need to manually configure thousands of options.

If the source code fails to be compiled according to the original configuration, clear the compiled part and the original configuration file respectively in the source code directory:

#make clean#make mrproper

Copy the default configuration to the kernel source code directory:

# Cd/usr/src/Linux-version # cp/boot/config-version-default. config

Start to configure the kernel. There are multiple options to configure the kernel through graphics:

#make xconfig#make gconfig#make menuconfig

Some of them need to install the corresponding graphical interface development kit, such as xorg-x11-devel, it is recommended to use make xconfig.

All options in the. config configuration file are automatically loaded, and the graphic configuration page is displayed.

Common kernel optimization configurations

Various hardware correspond to a wide variety of kernel settings. Generally, the default SuSE configuration is correct. If you are compiling a new kernel version and adding new hardware support, manually enable the hardware support option. Here, we only provide the most common kernel optimization options. We recommend that you use these options for daily desktop applications.

Processor type and features-> processor falimy select the category of your CPU

Processor type and features-> preemption model select preemptible kernel (low-latency desktop)

Processor type and features-> machine check support removes amd hooks if it is an Intel user, and AMD users remove intel hooks.

Processor type and features-> If memory model is an Intel/via/another non-amd cpu user, remove the hook before K8 Gart iommu support.

Processor type and features-> time frequency: 1000Hz

Power Management Options-> CPU frequency scaling old CPUs that do not support CPU frequency adjustment directly remove the hook of CPU frequency scaling and skip the following two

Power Management Options-> CPU frequency scaling-> amd opteron/athlon64 powernow! Non-amd cpu users remove the previous hook

Power Management Options-> CPU frequency scaling-> intel enhanced speedstep non-Intel CPU users remove this item.

After the configuration is complete, save and close.

Compile the kernel

After completing the settings, go to the compilation stage. If the patch and configuration are correct, the following steps will not cause errors. Execute them in sequence and wait until they are completed. It generally takes the longest time to compile the module in step 3. If an error occurs during this period, go back to the above configuration kernel cleanup and reconfigure.

#make#make modules_install#make install
= Update kernel-headers

After you compile the kernel, the Linux-kernel-header cannot be automatically updated, which is controlled by the RPM software management system. Generally, this package is maintained in the official kernel version. Therefore, we need to manually update it to facilitate module compilation in the new kernel in the future.

# make headers_install
Finishing work

At this point, the kernel has been compiled and installed, and a startup item has been added at the bottom of the grub Start Menu. Restart and try to log on to the new kernel. There are also some small problems to solve. Direct/usr/src/Linux to the source code directory of the compiled kernel.

# Rm/usr/src/Linux # ln-S/usr/src/Linux-version/usr/src/Linux

Then restart and use uname-R to check the kernel version. Naturally, remember to reinstall the graphics card driver.

Cleanup

If your kernel can work stably and properly after a period of testing, you can clean up and release disk space.

Clear old files

Return to the kernel source code directory

#make clean

Delete the directory corresponding to other kernel versions under/lib/modules, that is, delete the files corresponding to other kernel versions under/boot.

Clear the grub startup list

You may not want the original kernel to remain in the boot menu, so

# Mv/boot/GRUB/menu. lst. old/boot/GRUB/menu. LST # rm/boot /*. old & RM/boot/GRUB *. old # rm/boot/vmlinuz & RM/boot/initrd # ln-s vmlinuz-new version-default vmlinuz # ln-s initrd-new version-default initrd

Opensuse kernel compilation tutorial (kernel 2.6.x)

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.