Chinaunix首页 | 论坛 | 博客
  • 博客访问: 347941
  • 博文数量: 105
  • 博客积分: 2730
  • 博客等级: 少校
  • 技术积分: 1110
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-20 12:09
文章分类

全部博文(105)

文章存档

2013年(3)

2012年(2)

2011年(36)

2010年(34)

2009年(6)

2008年(20)

2007年(4)

分类: LINUX

2011-05-19 14:18:55

转载请注明:wuxb45.blog.chinaunix.net
几个要注意的地方
按照下文的过程一直到这一步:
####准备内核源码(在BUILD里放一堆源码,可打补丁的,用于build)
>>>>    cd ~/rpmbuild/SPECS
>>>>    rpmbuild -bp --target=$(uname -m) kernel.spec
如果什么都不需要修改,就直接进行配置(中间的步骤不用了):
####到要编译的内核目录下进行配置(config)
>>>>    cd ~/rpmbuild/BUILD/kernel-2.6.$ver/linux-2.6.$ver.$arch/
注意配置完不要在这里就直接编译了, 按照步骤指导来.
然后继续按指导进行.直到这个步骤:
####按指定的spec编译内核
>>>>    rpmbuild -bb --target=`uname -m` kernel.spec
这个默认编译就包含了你当前所需的东西, 包括有用的3个rpm包,其中kernel包包括了kernel镜像和ram盘.
其它几个命令可以参考, 减少不需要的debug信息等内容.
这个命令持续很长时间直到内核编译完成.至此打好的rpm包就有了,在RPMS目录下,可以按普通rpm包的方式安装了.



参考了官方资料
自己实践过后成功启动了桌面, 并且显卡驱动也不用更新(因为使用的和原来内核完全相同的版本.

----

Building a Kernel from the source RPM
Note these instructions *only* apply to Fedora 12 and later releases

This document provides instructions for advanced users who want to rebuild the kernel. Note, however, that when building or running any such kernel, one should NOT expect support from the Fedora kernel team, you're pretty much on your own here if something doesn't work as you'd hoped or expected. But hey, you're an advanced user, so you can handle it, right? Anyway, advanced users build custom kernels for a variety of reasons:

    To apply patches for testing that they either generated or obtained from another source
    To reconfigure the existing kernel
    To learn more about the kernel and kernel development

These instructions can also be used for simply preparing the kernel source tree.

Before starting, make sure the system has all the necessary packages installed, including the following:

    rpmdevtools
    yum-utils

yum-utils is a default package. To install the other package, use the following command:
####安装必要的工具包
>>>>    su -c 'yum install rpmdevtools yum-utils'

Get the Source
Do Not Build Packages as root.
Building packages as root is inherently dangerous and not required, even for the kernel. The following instructions allow any normal user to install and build kernels from the source packages.

    Prepare a RPM package building environment in your home directory. Run the following command:
####建立工作目录,默认就在home目录下建立
>>>>    rpmdev-setuptree

    This command creates different directories ${HOME}/rpmbuild/SOURCES, ${HOME}/rpmbuild/SPECS, and ${HOME}/rpmbuild/BUILD. Where ${HOME} is your home directory.
    Download the kernel-.src.rpm file. Enable the appropriate source repositories with the --enablerepo switch. (yumdownloader --enablerepo=repo_to_enable --source kernel)
####下载(与当前内核一致)内核源代码
>>>>    yumdownloader --source kernel

    Install build dependencies for the kernel source with the yum-builddep command (root is required to install these packages):
####安装内核构建依赖的包
>>>>    su -c 'yum-builddep kernel-.src.rpm'

    Install kernel-.src.rpm with the following command:
####解压内核源码(仅仅是一套源码)
>>>>    rpm -Uvh kernel-.src.rpm

    This command writes the RPM contents into ${HOME}/rpmbuild/SOURCES and ${HOME}/rpmbuild/SPECS, where ${HOME} is your home directory. It is safe to ignore any messages similar to the following:

warning: user kojibuilder does not exist - using root
warning: group kojibuilder does not exist - using root

Space Required. The full kernel building process requires several gigabytes of extra space on the file system containing your home directory.
Prepare the Kernel Source Tree

This step expands all of the source code files for the kernel. This is required to view the code, edit the code, or to generate a patch.

1. Prepare the kernel source tree using the following commands:
####准备内核源码(在BUILD里放一堆源码,可打补丁的,用于build)
>>>>    cd ~/rpmbuild/SPECS
>>>>    rpmbuild -bp --target=$(uname -m) kernel.spec

The kernel source tree is now located in the ~/rpmbuild/BUILD/kernel-/linux-. directory.
Copy the Source Tree and Generate a Patch

This step is for applying a patch to the kernel source. If a patch is not needed, proceed to "Configure Kernel Options".

Copy the source tree to preserve the original tree while making changes to the copy:
####如果要建立补丁,先搞一个备份,.
>>>>    cp -r ~/rpmbuild/BUILD/kernel-2.6.$ver$fedver/linux-2.6.$ver.$arch ~/rpmbuild/BUILD/kernel-2.6.$ver$fedver.orig
>>>>    cp -al ~/rpmbuild/BUILD/kernel-2.6.$ver$fedver.orig ~/rpmbuild/BUILD/kernel-2.6.$ver$fedver.new

The second cp command hardlinks the .orig and .new trees to make diff run faster. Most text editors know how to break the hardlink correctly to avoid problems.

Using vim on FC14, it treated the hard link as a hard link and thus the above technique failed. It was necessary to repeat the original copy used for the .orig directory for the .new directory. Note that this uses twice the space.

Make changes directly to the code in the .new source tree, or copy in a modified file. This file might come from a developer who has requested a test, from the upstream kernel sources, or from a different distribution.

After the .new source tree is modified, generate a patch. To generate the patch, run diff against the entire .new and .orig source trees with the following command:
####修改了当前的内核源码(new),和之前的(orig)进行diff得到patch
>>>>    cd ~/rpmbuild/BUILD
>>>>    diff -uNrp kernel-2.6.$ver$fedver.orig kernel-2.6.$ver$fedver.new > ../SOURCES/linux-2.6-my-new-patch.patch

Replace 'linux-2.6-my-new-patch.patch' with the desired name for the new patch. On FC14 it was necessary to copy the above patch name to my-new-patch.patch in ~/rpmbuild/SOURCES as well in order for rpmbuild to find it.
For more information on patching refer to the man pages for diff(1) and patch(1).
Configure Kernel Options

This step is for modifying the options the kernel is configured with. This step is optional. If no configuration changes are needed, proceed to "Prepare Build Files".

    Change to the kernel source tree directory:
####到要编译的内核目录下进行配置(config)
>>>>    cd ~/rpmbuild/BUILD/kernel-2.6.$ver/linux-2.6.$ver.$arch/

    If you only want to make minor changes to the default fedora kernel, skip to step 4., and use one of the two configuration tools to edit those minor changes into the default config file.
    Select the desired configuration file from ~/rpmbuild/BUILD/kernel-2.6.$ver/linux-2.6.$ver.$arch/configs. Copy the desired config file to ~/rpmbuild/BUILD/kernel-2.6.$ver/linux-2.6.$ver.$arch/.config:

>>>>    cp configs/ .config

    Run the following command:

>>>>    make oldconfig

    Then run the following command, selecting and saving the desired kernel options from the text-based UI:

>>>>    make menuconfig

        For a graphical UI, instead run:

>>>>    make xconfig

    Add a new line to the top of the config file that contains the hardware platform the kernel is built for (the output of uname -i). The line is preceded by a # sign. For example, an x86_64 machine would have the following line added to the top of the config file:
#### 在config的开头添加这个内容,注意开头有注释符号"#"
>>>>    # x86_64

    Copy the config file to ~/rpmbuild/SOURCES/:
####复制到源码包里
>>>>    cp .config ~/rpmbuild/SOURCES/config-`uname -m`

    In actual fact, a Fedora 11 x86_64 machine would use the following command, because the spec file has no config-x86_64 item, and so will not process it. The only spec entry is for generic.
####这个仅对fc11,不用了
>>>>    cp .config ~/rpmbuild/SOURCES/config-`uname -m`-generic

Prepare Build Files

This step makes the necessary changes to the kernel.spec file. This step is required for building a custom kernel.

1. Change to the ~/rpmbuild/SPECS directory:
####到SPECS目录下,编辑spec文件
>>>>    cd ~/rpmbuild/SPECS

2. Open the kernel.spec file for editing.
3. Give the kernel a unique name. This is important to ensure the custom kernel is not confused with any released kernel. Add a unique string to the kernel name by changing the 'buildid' line. Optionally, change ".local" to your initials, a bug number, the date or any other unique string.

Change this line:
####找到这行
>>>>    #% define buildid .local

To this (note the extra space is removed in addition to the pound sign):
####改成这行
>>>>    %define buildid .

4. If you generated a patch, add the patch to the kernel.spec file, preferably at the end of all the existing patches and clearly commented.
####如果有自己的patch, 加入到spec中
>>>>    # 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

The patch then needs to be applied in the patch application section of the spec file. Again, at the end of the existing patch applications and clearly commented.
####添加应用补丁的命令.
>>>>    ApplyPatch linux-2.6-cputime-fix-accounting.patch

>>>>    ApplyPatch linux-2.6-samfw-test.patch



Build the New Kernel

This step actually generates the kernel RPM files. This step is required for building a custom kernel. For Fedora 10 or 11, for most purposes, it will be simplest to build with firmware included (see the last form below).

Use the rpmbuild utility to build the new kernel:

    To build all kernel flavors:
####按指定的spec编译内核
>>>>    rpmbuild -bb --target=`uname -m` kernel.spec

    To disable specific kernel flavors from the build (for a faster build):

>>>>    rpmbuild -bb --without
阅读(2633) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~