Fedora Kernel Compilation Guide

Source: Internet
Author: User
Tags config rpmbuild
Compile Fedora kernel from src RPM package for Fedora 8 and later versions

Reference Http://fedoraproject.org/wiki/Docs/CustomKernel


All of the following commands are run under a non-root user

preparatory work
Before you begin, make sure that the following necessary packages are installed on the system:
Yum-utils
Rpmdevtools
The following command can be used to install:
Su-c ' yum install yum-utils rpmdevtools '
Where Yum-utils package provides Yumdownloader and YUM-BUILDDEP these two commands, Rpmdevtools package provides rpmdev-setuptree this command

Get Source

1. First build the RPM Packaging environment directory and run the following command:
Rpmdev-setuptree
This command establishes the RPMBUILD/{SOURCES,SPECS,BUILD,RPMS,SRPMS} 5 directories in the user's HOME directory, as well as a. Rpmmacros file that defines some RPM-packed environment variables.

2. Download the kernel source src.rpm package. You can download it directly to the official Fedora source, or you can download it using the following command:
Yumdownloader--source Kernel

3. Install the package required to compile the kernel and run the following command:
Su-c ' Yum-builddep kernel-<version>.src.rpm '

4. Install the kernel source src.rpm package and run the following command:
RPM-UVH kernel-<version>.src.rpm

preparing the kernel source tree
1. Run the following command to build the kernel source tree:
CD ~/rpmbuild/specs
RPMBUILD-BP--target= ' uname-m ' Kernel.spec
The kernel source tree is now located in the ~/rpmbuild/build/kernel-<version>/linux-<version>.<arch> directory.

2. If you also need to modify the kernel source code (optional), you can follow the following steps:
Cp-a ~/rpmbuild/build/kernel-2.6. $ver/linux-2.6. $ver. $arch ~/rpmbuild/build/kernel-2.6. $ver. Orig
Cp-a ~/rpmbuild/build/kernel-2.6. $ver. Orig ~/rpmbuild/build/kernel-2.6. $ver. New
Modify the source in ~/rpmbuild/build/kernel-2.6. $ver. New and make a patch:
CD ~/rpmbuild/build
DIFF-UNRP Kernel-2.6.x.orig kernel-2.6.x.new >. /sources/linux-2.6-my-new-patch.patch

Configure kernel options (optional)
If you need to modify the kernel's compilation options, do this:
1. Enter the kernel source tree
CD ~/rpmbuild/build/kernel-<version>/linux-<version>.<arch>/

2. Select a config file based on its modification from the Configs directory to copy it into the. config file in the kernel source tree
CP configs/<desired-config-file>. config

3. Configuring kernel compilation Options
Make Oldconfig
Make Menuconfig

4. In the first line of the newly generated. config file, add a line that specifies the identity of the hardware platform (the output of uname-i), starting with the # number, for example:
# i386

5. Copy the. config file to the ~/rpmbuild/sources/directory and name it config-<arch>, for example config-i686
cp. config ~/rpmbuild/sources/config-<arch>

Prepare spec file
Enter the ~/rpmbuild/specs directory and edit the Kernel.spec file:
1. Define Buildid as a unique identifier to differentiate between different kernel RPM packages. Put
#% define Buildid. Local
Change into
%define Buildid .<custom_text>
Notice that the space between% and define is removed

2. If you have previously generated patches, add patches to the Kernel.spec file. It is generally placed at the end of all existing patches and annotated. For example:
# CPUTime accounting is broken, revert to 2.6.22 version
Patch2220:linux-2.6-cputime-fix-accounting.patch
Patch9999:linux-2.6-samfw-test.patch
In addition, in the patch of the paragraph also to fill in:
Applypatch Linux-2.6-cputime-fix-accounting.patch
Applypatch Linux-2.6-samfw-test.patch

compiling a new kernel
Using the Rpmbuild command to compile the kernel RPM package, the default command is:
RPMBUILD-BB--target= ' uname-m ' Kernel.spec
This command may be compiled several times kernel, generating different types of kernel images, such as kernel that support Xen, SMP, and so on. You can remove some by adding the--without <option> option, with options such as Xen, SMP, Up, PAE, Kdump, Debug, and Debuginfo. To indicate the compilation of a certain kernel, you can add--with <option> options, optional option baseonly, Smponly, and Xenonly. These option can be found in the spec file.
For example, to compile one of the most basic kernel, use the following command:
RPMBUILD-BB--with baseonly--without debug--without debuginfo--target= ' uname-m ' Kernel.spec
After the compilation is complete, the new RPM package is in the ~rpmbuild/rpms directory.

Install a new kernel
Install the new kernel RPM Pack RPM-IVH command, do not use the-U or--upgrade option.
RPM-IVH ~/rpmbuild/rpms/<arch>/kernel-<version>.<arch>.rpm

Shortcut
The above has done so much, in fact only to be able to generate a kernel RPM package. If you don't want to kernel into RPM package, you can save a lot of things. After running the rpmbuild-bp--target= ' uname-m ' kernel.spec command, the kernel source tree is ready and can be processed in accordance with the common compiler kernel steps.

compile kernel modules only
If you only need to compile a module for the currently running kernel, just install the Kernel-devel package.
Su-c ' yum install Kernel-devel '
For example, to compile the Foo.ko module, simply create the following Makefile file in the directory that contains the FOO.C:
Obj-m: = foo.o

Kdir: =/lib/modules/$ (Shell uname-r)/build
PWD: = $ (shell pwd)

Default
$ (make)-C $ (Kdir) m=$ (PWD) modules

Next, run the make command to compile the 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.