Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2153380
  • 博文数量: 333
  • 博客积分: 10161
  • 博客等级: 上将
  • 技术积分: 5238
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-19 08:59
文章分类

全部博文(333)

文章存档

2017年(10)

2014年(2)

2013年(57)

2012年(64)

2011年(76)

2010年(84)

2009年(3)

2008年(37)

分类: LINUX

2010-11-29 09:55:29

Disclaimer

Building and using a custom kernel will make it very difficult to get support for your system.

While it is a learning experience to compile your own kernel, you will not be allowed to file bugs on the custom-built kernel (if you do, they will be Rejected without further explanation).

If you have a commercial support contract with Ubuntu/Canonical, this will void such support.

Also note that this page describes how to do things for the Edgy (2.6.17) kernel and newer! Until this kernel source, we did not have any mechanisms in place that would allow people to build their own kernels easily. This was intentional.

This page does NOT describe how to from kernel.org. This is how to rebuild the actual Ubuntu kernel starting from source.

Reasons for compiling a custom kernel

  • You are a kernel developer.
  • You need the kernel compiled in a special way, that the official kernel is not compiled in (for example, with some experimental feature enabled).
  • You are attempting to debug a problem in the stock Ubuntu kernel for which you have filed or will file a bug report.
  • You have hardware the stock Ubuntu kernel does not support.

Reasons for NOT compiling a custom kernel

  • You merely need to compile a special driver. For this, you only need to install the linux-headers packages.
  • You have no idea what you are doing, and if you break something, you'll need help fixing it. Depending on what you do wrong, you might end up having to reinstall your system from scratch.
  • You got to this page by mistake, and checked it out because it looked interesting, but you don't really want to learn a lot about kernels.

If you want to install a new kernel without compilation, you can use , search for linux-image and select the kernel version you want to install.

An easier way is to click on System > Administration > Update Manager, then click on the Check button, and finally click on Apply all updates including the kernel.

Tools you'll need

To start, you will need to install a few packages. The exact commands to install those packages depends on which release you are using:

  • Edgy through Gutsy:

sudo apt-get install linux-kernel-devel fakeroot kernel-wedge build-essential makedumpfile
  • Hardy:

sudo apt-get install linux-kernel-devel fakeroot kernel-wedge build-essential
  • Note: The package makedumpfile is not available in Hardy.

    Intrepid, Jaunty, and Karmic:

sudo apt-get install fakeroot kernel-wedge build-essential makedumpfile kernel-package
  • Note: The linux-kernel-devel package does not exist in Intrepid, Jaunty, or any newer release. To compile the kernel on Intrepid or newer, you'll also need to run:

sudo apt-get build-dep linux
  • This will install the compiler related packages and kernel packaging tools. It will also install the git-core package, which is the best way to interact with the Ubuntu kernel source.

    Lucid:

sudo apt-get install fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge
sudo apt-get build-dep linux
sudo apt-get install git-core libncurses5 libncurses5-dev libelf-dev asciidoc binutils-dev

Get the kernel source

There are a few ways to obtain the Ubuntu kernel source:

A) Use git

  • Use git (detailed instructions on it can be found in the ) - This is for users who always want to stay in sync with the latest Ubuntu kernel source.

    The git repository does not include necessary control files, so you must build them by:

fakeroot debian/rules clean

B) Download the source archive

  • Download the source archive - This is for users who want to rebuild the standard Ubuntu packages with additional patches. Note that this will almost always be out of date compared to the latest development source, so you should use git (option A) if you need the latest patches. To install the build dependencies and extract the source (to the current directory):

    Ubuntu Gutsy Gibbon (7.10) and previous releases

sudo apt-get build-dep linux-source
apt-get source linux-source
  • Ubuntu Hardy (8.04), Intrepid Ibex (8.10), Jaunty Jackalope (9.04)

sudo apt-get build-dep --no-install-recommends --only-source linux
apt-get source --only-source linux
  • Ubuntu modules source may also be needed if you plan to enable PAE and 64 GiB support in the kernel for 32-bit Hardy (8.04). The Ubuntu supplied modules may not be compatible with a PAE enabled kernel.

sudo apt-get build-dep --no-install-recommends linux-ubuntu-modules-$(uname -r)
apt-get source linux-ubuntu-modules-$(uname -r)
  • The source will be downloaded to a subdirectory inside the current directory.

    Ubuntu Karmic Koala (9.10) and newer releases

sudo apt-get build-dep --no-install-recommends linux-image-$(uname -r)
apt-get source linux-image-$(uname -r)
  • The source will be downloaded to the current directory (for Lucid, at least) as a trio of files (.orig.tar.gz, .diff.gz, and .dsc) and a sub-directory. For instance, if uname -r returns 2.6.32-25-generic, you'll obtain linux_2.6.32.orig.tar.gz, linux_2.6.32-25.44.diff.gz, linux_2.6.32-25.44.dsc and the sub-directory linux-2.6.32.

C) Download the source package

  • Download the source package (detailed instructions are further down this page under ) - This is for users who simply want to modify, or play around with, the Ubuntu-patched kernel source. Again, this will not be the most up-to-date (use option A/git if you need the latest source). Please be aware this is NOT the same as option B.

Modify the source for your needs

For most people, simply modifying the configs is enough. If you need to install a patch, read the instructions from the patch provider to learn how to apply it.

The stock Ubuntu configs are located in debian/config/ARCH/ where ARCH is the architecture you are building for (Starting with Jaunty this is debian.master/config/ARCH/). In this directory there are several files. The config file is the base for all targets in that architecture. Then there are several config.FLAVOUR files that contain options specific to that target. For example, here are the files for 2.6.20, i386:

ls -l debian/config/i386/
total 108
-rw-r--r-- 1 root src 73962 2007-08-13 01:29 config
-rw-r--r-- 1 root root 1369 2007-08-13 01:29 config.386
-rw-r--r-- 1 root root 1330 2007-08-13 01:29 config.generic
-rw-r--r-- 1 root root 1395 2007-08-13 01:29 config.server
-rw-r--r-- 1 root root 1756 2007-08-13 01:29 config.server-bigiron
-rw-r--r-- 1 root root 8 2007-08-13 01:25 lowlatency
-rw-r--r-- 1 root root 194 2007-08-13 01:25 vars.386
-rw-r--r-- 1 root root 218 2007-08-13 01:25 vars.server-bigiron

If you do not find the config files under debian/config, you may find them in your /boot directory (for instance, /boot/config-2.6.22-14-generic).

If you need to change a config option, simply modify the file that contains the option. If you modify just the config file, it will affect all targets for this architecture. If you modify one of the target files, it only affects that target.

After applying a patch, or adjusting the configs, it is always best to regenerate the config files to ensure they are consistent. There is a helper command for this. To regenerate all architectures run:

debian/rules updateconfigs

If you just want to update one architecture, run:

debian/scripts/misc/oldconfig ARCH

For these two commands to work, you need to give the scripts in the debian/scripts/misc and debian/scripts directories execute permission with the following command:

chmod -R u+x debian/scripts/*

Build the kernel (when source is from git repository, or from apt-get source)

To build the kernel(s) is very simple. Depending on your needs, you may want to build all the kernel targets, or just one specific to your system. However, you also want to make sure that you do not clash with the stock kernels.

Note: Though these outside instructions include making a separate and unique branch of the kernel, unlike here, they include thorough explanations of all necessary steps from start to finish.

These instructions are specific to the git-tree and for the source downloaded via apt-get source, not when downloading the linux-source package from kernel.org

Use this command to build all targets for the architecture you are building on:

fakeroot debian/rules clean
AUTOBUILD=1 fakeroot debian/rules binary-debs

debian/rules clean creates debian/control, debian/changelog, and so on from debian./* (e.g. debian.master). It is necessary in git trees following git commit 3ebd3729ce35b784056239131408b9a72b0288ef "UBUNTU: [Config] Abstract the debian directory".

The AUTOBUILD environment variable triggers special features in the kernel build. First, it skips normal ABI checks (ABI is the binary compatibility). It can do this because it also creates a unique ABI ID. If you used a git repo, this unique ID is generated from the git HEAD SHA. If not, it is generated from the uuidgen program (which means every time you execute the debian/rules build, the UUID will be different!). Your packages will be named using this ID. (Note that in Intrepid and newer, you will need skipabi=true to skip ABI checks.)

To build a specific target, use this command:

fakeroot debian/rules clean
AUTOBUILD=1 NOEXTRAS=1 fakeroot debian/rules binary-FLAVOUR

Where FLAVOUR is one of the main flavours of the kernel (e.g. generic)

To build one of the custom flavours (found in debian/binary-custom.d/), use:

fakeroot debian/rules clean
AUTOBUILD=1 NOEXTRAS=1 fakeroot debian/rules custom-binary-FLAVOUR

As of this documentation, custom flavours include xen and rt.

If you have a more than one processor or more than one core, you can speed things up by running concurrent compile commands. Prepend CONCURRENCY_LEVEL=2 for two processors or two cores; replace '2' with whatever number suits your hardware setup (for Gutsy and later, you can alternatively use DEB_BUILD_OPTIONS=parallel=2).

fakeroot debian/rules clean
DEB_BUILD_OPTIONS=parallel=2 AUTOBUILD=1 NOEXTRAS=1 fakeroot debian/rules binary-generic

If you get ABI errors, you can avoid the ABI check with skipabi=true. For example,

fakeroot debian/rules clean
DEB_BUILD_OPTIONS=parallel=2 AUTOBUILD=1 NOEXTRAS=1 skipabi=true fakeroot debian/rules binary-generic

To trigger a rebuild, remove the appropriate stamp file from debian/stamps (e.g. stamp-build-server for the server flavour, etc.).

The debs are placed in your kernel directory's parent directory.

If needed, the Ubuntu modules source for Hardy (8.04) can be built in a similar way.

cd linux-ubuntu-modules-2.6.24-2.6.24
AUTOBUILD=1 fakeroot debian/rules binary-debs

Alternatively, if you need to specify a different kernel than the running one, use

cd linux-ubuntu-modules-2.6.24-2.6.24
AUTOBUILD=1 fakeroot debian/rules binary-debs KDIR=/path/to/kerneldir
管理员在2009年8月13日编辑了该文章文章。
-->
阅读(1115) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~