分类: LINUX
2010-11-29 09:55:29
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.
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.
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
There are a few ways to obtain the Ubuntu kernel source:
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
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
sudo apt-get build-dep --no-install-recommends linux-ubuntu-modules-$(uname -r)
apt-get source linux-ubuntu-modules-$(uname -r)
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.
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.
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/*
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.
Maverick : http://blog.avirtualhome.com/2010/11/06/how-to-compile-a-ubuntu-10-10-maverick-kernel/
Maverick on Lucid : http://blog.avirtualhome.com/2010/07/14/how-to-compile-a-ubuntu-2-6-35-kernel-for-lucid/
Lucid : http://blog.avirtualhome.com/2010/05/05/how-to-compile-a-ubuntu-lucid-kernel/
Karmic : http://blog.avirtualhome.com/2009/11/03/how-to-compile-a-kernel-for-ubuntu-karmic/
Jaunty : http://blog.avirtualhome.com/2009/09/08/how-to-compile-a-kernel-for-ubuntu-jaunty-revised/
Intrepid : http://blog.avirtualhome.com/2008/10/28/how-to-compile-a-custom-kernel-for-ubuntu-intrepid-using-git/.
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.
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管理员在2009年8月13日编辑了该文章文章。
AUTOBUILD=1 fakeroot debian/rules binary-debs KDIR=/path/to/kerneldir