Fedora core8 kernel source code compilation Summary

Source: Internet
Author: User
Tags rpmbuild
Fedora core8 kernel source code compilation Summary


Installing the kernel source code is not required unless you want to compile the kernel or perform some special development.
Work. In some cases, we need kernelheaders.
Generally, the following four basic steps are required to install the kernel source code:
Download the required kernel source code, install srpm, and use the rpmbuild command to change the source code to available.
(Usablestate); compile and install.

1. Download the kernel source code

Can get source code from here: http://archives.fedoraproject.org/pub/archive/fedora/linux/releases/8/Fedora/source/SRPMS/

Select a kernel suitable for the current version,
Example: kernel-2.6.23.1-42.fc8.src.rpm31-Oct-200700: 0646 m

2. Install source code

That is, install the SRC. RPM obtained in the previous step:
$
Sudo rpm-IVH kernel-2.6.23.1-42.fc8.src.rpm
1: ker nel ###################################### ##### [100%]
There may be some warning prompts and so on, most of them can be ignored.

3. Conversion source code:

Before conversion, make sure that the/usr/src/directory contains the RedHat Directory (generally/usr/src/is an empty directory ).
$
Sudo rpmbuild-BP -- target = $ (uname-M)/usr/src/RedHat/specs/kernel. spec
In this way, the source code is stored in/usr/src/RedHat/build/kernel-2.6.23 /.
There are two useful folders :.
A. linux-2.6.23.ARCH -- the package provided by kernel.org was patched and upgraded by fedora.
Arch is the same as the output of uname-M, usually i686. If you want different outputs, you can use
"-- Target =" is specified.
B. Vanilla-this is a standard source code provided by kernel.org without patches or upgrades.

Paste path:
$
Ll
Total 32
Drwxr-XR-x 3 Root 4096 10-13 21:07 build
Drwxr-XR-x 2 root Root 12288 10-13 Sources
Drwxr-XR-x 2 root Root 4096 10-13 specs

4. Compile the source code:

$
CD/usr/src/RedHat/build/kernel-2.6.23/linux-2.6.23.i686
To modify the MAKEFILE file
Each kernel name contains its version number, which is also the value displayed by the uname-R command. Kernel makefile
The first four lines define the kernel name. Makefile
Modified to generate a name different from that of the running kernel. Before inserting a running kernel into a module, this module must compile the running kernel. To do this, you must edit
Makefile.
For example, if the uname-R value is 2.6.23.1-42. fc8, set extraversion =-42. fc8.
When modifying the parameters, check the values of the preceding fields and compare them with those of uname-R.
Modification of extraversion is very important. The author has encountered a modification error that causes the module to be compiled successfully but cannot be inserted.
$

Make mrproper
$
Make oldconfig
$
Make(It takes a long time to watch a movie)

$
Make modules_install
$
Make install
Since then, the kernel compilation has ended.

Debugging program:

Hello. c

Copy content to clipboard

Code:

#include <linux/module.h>

#if defined(CONFIG_SMP)
#define __SMP__
#endif

#if defined(CONFIG_MODVERSIONS)
#define MODVERSIONS
#include <linux/modversions.h>
#endif

#include <linux/kernel.h>

int init_module(void)
{
printk(KERN_DEBUG "Hello, kernel!/n");
return 0;
}

void cleanup_module(void)
{
printk(KERN_DEBUG "Good-bye, kernel!/n");
}

Makefile

Copy content to clipboard

Code:


#makefile for 2.6 linux kernel
obj-m := hello.o
KDIR :=/lib/modules/`uname -a`/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

$
Make
$
Ismod hello. Ko
$
Dmesg | tail N1

Note: 1. The makefile format of the 2.4 kernel is different from that of the 2.6 kernel.
2. makefile cannot be written as makefile and will fail to be compiled.
3. The/lib/modules/'uname-a'/build file is a link to a directory of your/usr/src/... number of kernels.

In some articles, the following tools are required:
Install kernel headers (header file)

This package provides kernel headers and makefiles to handle module compilation in the kernel package. If you need to install drivers and some third-party software, you need kernel headers. If a driver requires the kernel source code, it may be enough to install kernel headers.

Kernel headers can be obtained by installing the kernel-devel RPM package. This package may not be automatically installed by fedora. This package can be installed from your fedora DVD or online through FTP and yum.

Search online in the fedora software warehouse and update software warehouse to make sure they match your system and use the uname command. Example:
[Mirandam @ Charon ~] $ Uname-rm
2.6.23.1-42. fc8 i686

Select: kernel-devel-2.6.23.1-42.fc8.i686.rpm
Select: kernel-devel-2.6.23.1-42.fc8.i686.rpm

If you have upgraded your kernel (using YUM), we recommend that you use Yum to install this package.
[Mirandam @ Charon ~] $ Sudo Yum install kernel-devel

Article Source: http://www.diybl.com/course/6_system/linux/Linuxjs/2008628/128979_5.html

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.