个人工具

“UbuntuHelp:Kernel/Compile”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第3行: 第3行:
  
  
== Disclaimer ==
+
=== Disclaimer ===
  
 
'''Building and using a custom kernel will make it very difficult to get support for your system. '''
 
'''Building and using a custom kernel will make it very difficult to get support for your system. '''
第13行: 第13行:
  
 
This page does '''NOT''' describe how to build stock kernels from kernel.org. This is how to rebuild the actual Ubuntu kernel source.
 
This page does '''NOT''' describe how to build stock kernels from kernel.org. This is how to rebuild the actual Ubuntu kernel source.
 
  
 
=== Reasons for compiling a custom kernel ===
 
=== Reasons for compiling a custom kernel ===
第19行: 第18行:
 
* You are a kernel developer.
 
* 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 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 for which you have filed or will file a bug report on the stock Ubuntu kernel.
+
* 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 for which the Ubuntu kernel doesn't include support
+
* You have hardware the stock Ubuntu kernel does not support.
  
 
=== Reasons for NOT compiling a custom kernel ===
 
=== 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 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. If you hose your box, reinstall. Don't bother asking for help.
+
* 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, but checked it out because it looked interesting. Believe me, this isn't interesting at all :)
 
* You got to this page by mistake, but checked it out because it looked interesting. Believe me, this isn't interesting at all :)
  
 
+
=== Tools you'll need ===
=== What you'll need ===
+
  
 
To start, you will need to install a few packages.
 
To start, you will need to install a few packages.
  
 
<pre><nowiki>
 
<pre><nowiki>
sudo apt-get install linux-kernel-devel fakeroot
+
sudo apt-get install linux-kernel-devel fakeroot build-essential
 
</nowiki></pre>
 
</nowiki></pre>
  
 
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.
 
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.
  
samtygier: I think you also need the package m4
 
  
=== How to get the kernel source ===
+
=== Get the kernel source ===
  
There are a few ways to obtain the Ubuntu kernel source. Some prefer to use git. Detailed instructions for using git can be found in the [[UbuntuWiki:Ubuntu/KernelGitGuide|Kernel Git Guide]].
+
There are a few ways to obtain the Ubuntu kernel source. One is to use git (detailed instructions on it can be found in the [[UbuntuWiki:Ubuntu/KernelGitGuide|Kernel Git Guide]]), which allows you to always stay in sync with the latest Ubuntu kernel source.
  
The simplest was, useful to those who want to rebuild the standard Ubuntu packages with additional patches is:
+
The simplest way, useful to those who want to rebuild the standard Ubuntu packages with additional patches is:
  
 
<pre><nowiki>
 
<pre><nowiki>
apt-get source linux-image-generic
+
sudo apt-get build-dep linux-source-2.6.22
apt-get build-dep linux-image-generic
+
apt-get source linux-source-2.6.22
 
</nowiki></pre>
 
</nowiki></pre>
  
Another way is to simply:
+
Note that this will almost always be out of date compared to the latest development source, so you should use git if you need the latest patches.
  
<pre><nowiki>
 
sudo apt-get install linux-source
 
</nowiki></pre>
 
 
However, that will almost always be out of date. Using git allows you to always stay in sync with the latest Ubuntu kernel source, and using the package source allows you to keep as close as possible to an official release with any private changes.
 
 
''It seems that it is possible to use this information on 6.06 by running something similar to `apt-get source linux-image-2.6.15-26-386', which will give you kernel source along with the debian folder needed for this guide.  However, I'm just a user, proceed with caution.'' <br> -- Simon80 [[DateTime(2006-07-17T02:09:06Z)]]
 
 
''After testing it, I must warn you that this documentation doesn't work if you choose the '''sudo apt-get install linux-source-2.6.17''' way. '' <br> -- OuattaraAziz [[DateTime(2007-02-17T21:02:06Z)]]
 
  
=== Modifying the source for your needs ===
+
=== 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 for how to apply.
 
For most people, simply modifying the configs is enough. If you need to install a patch, read the instructions from the patch provider for how to apply.
  
The stock Ubuntu configs are located in ''debian/config/ARCH/'' where ARCH is the architecture you are building for. In this directory 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.17, i386:
+
The stock Ubuntu configs are located in ''debian/config/ARCH/'' where ARCH is the architecture you are building for. In this directory 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:
  
 
<pre><nowiki>
 
<pre><nowiki>
$ ls -l debian/config/i386/
+
ls -l debian/config/i386/
total 88
+
total 108
-rw-r--r-- 1 me me 62737 Jun 14 18:31 config
+
-rw-r--r-- 1 root src  73962 2007-08-13 01:29 config
-rw-r--r-- 1 me me 1859 Jun 12 14:59 config.386
+
-rw-r--r-- 1 root root 1369 2007-08-13 01:29 config.386
-rw-r--r-- 1 me me 1394 Jun 12 14:59 config.686
+
-rw-r--r-- 1 root root 1330 2007-08-13 01:29 config.generic
-rw-r--r-- 1 me me 1420 Jun 12 14:59 config.k7
+
-rw-r--r-- 1 root root 1395 2007-08-13 01:29 config.server
-rw-r--r-- 1 me me 1519 Jun 12 14:59 config.server
+
-rw-r--r-- 1 root root 1756 2007-08-13 01:29 config.server-bigiron
-rw-r--r-- 1 me me  1867 Jun 12 14:59 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
 +
 
 
</nowiki></pre>
 
</nowiki></pre>
 +
 +
'''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.
 
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.
第92行: 第85行:
  
 
<pre><nowiki>
 
<pre><nowiki>
debian/bin/oldconfig ARCH
+
debian/scripts/misc/oldconfig ARCH
 
</nowiki></pre>
 
</nowiki></pre>
  
  
=== Building the kernel ===
+
=== 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.
 
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.
  
Use this command to build all targets for the architecture you are buidling on:
+
'''These instructions are specific to the git-tree and for the source downloaded via apt-get source, ''not'' when downloading the linux-source package'''
 +
 
 +
Use this command to build all targets for the architecture you are building on:
  
 
<pre><nowiki>
 
<pre><nowiki>
第111行: 第106行:
  
 
<pre><nowiki>
 
<pre><nowiki>
AUTOBUILD=1 fakeroot debian/rules binary-debs flavours=k7
+
AUTOBUILD=1 NOEXTRAS=1 fakeroot debian/rules binary-FLAVOUR
 
</nowiki></pre>
 
</nowiki></pre>
  
This will only build the AMD k7 variant of the i386 architecture.
+
Where FLAVOUR is one of the main flavours of the kernel (e.g. generic)
  
The debs are placed in ubuntu-2.6/debian/build.
+
To build one of the custom flavours (found in debian/binary-custom.d/), use:
  
=== When it's done ===
+
<pre><nowiki>
 +
AUTOBUILD=1 NOEXTRAS=1 fakeroot debian/rules custom-binary-FLAVOUR
 +
</nowiki></pre>
  
Now that the build is complete, you can install the generated debs using dpkg:
+
As of this documentation, custom flavours include xen and rt.
  
 +
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.
 +
 +
=== Alternate Build Method: The Old-Fashioned Debian Way ===
 +
 +
The new Ubuntu build system is great for developers, for people who need the absolute latest bleeding-edge kernel, and people who need to build a diverse set of kernels (several "flavours"). However it can be a little complex for ordinary users. If you don't need the latest development sources, there is a simpler way to compile your kernel from the linux-source package. As suggested above, all you need for this is:
 
<pre><nowiki>
 
<pre><nowiki>
sudo dpkg -i linux-image-2.6.17-2-ef427c-k7_2.6.17-2.2_i386.deb
+
sudo apt-get install linux-source
sudo dpkg -i linux-headers--2.6.17-2-ef427c-k7_2.6.17-2.2_i386.deb
+
mkdir ~/src
 +
cd ~/src
 +
tar xjvf /usr/src/linux-source-<version-number-here>.tar.bz2
 +
cd linux-source-<version-number-here>
 +
</nowiki></pre>
 +
 
 +
Now you are in the top directory of a kernel source tree. Before building the kernel, you must configure it. If you wish to re-use the configuration of your currently-running kernel, start with
 +
<pre><nowiki>
 +
cp -vi /boot/config-`uname -r` .config
 +
</nowiki></pre>
 +
 
 +
Then, regardless of whether you're re-using existing configuration or starting from scratch:
 +
<pre><nowiki>
 +
make menuconfig # or "xconfig" if you prefer
 +
</nowiki></pre>
 +
 
 +
If you re-used the existing configuration, note that Ubuntu kernels build with debugging information on, which makes the resulting kernel modules (*.ko files) much larger than they would otherwise be. To turn this off, go into "Kernel hacking"; then, under "Kernel debugging", turn OFF "Compile the kernel with debug info".
 +
 
 +
Now you can compile the kernel and create the packages:
 +
<pre><nowiki>
 +
make-kpkg --rootcmd fakeroot --initrd --append-to-version=-some-string-here kernel-image kernel-headers
 +
</nowiki></pre>
 +
 
 +
The packages should be placed in ~/.
 +
 
 +
=== Build the kernel (when source is from a linux-source package) ===
 +
<pre><nowiki>
 +
make-kpkg clean
 +
fakeroot make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers
 +
</nowiki></pre>
 +
 
 +
The deb packages are in the parent directory.
 +
 
 +
=== Install the new kernel ===
 +
 
 +
If you want to see the ubuntu splash screen (or use text mode) before you get to X instead of just a black screen, you'll want to make sure the framebuffer driver loads:
 +
<pre><nowiki>
 +
echo vesafb | sudo tee -a /etc/initramfs-tools/modules
 +
echo fbcon | sudo tee -a /etc/initramfs-tools/modules
 +
</nowiki></pre>
 +
 
 +
Now that you've told initramfs-tools what modules it should include and the build is complete, you can install the generated debs using dpkg:
 +
 
 +
<pre><nowiki>
 +
sudo dpkg -i linux-image-2.6.20-16-2be-k7_2.6.20-16_i386.deb
 +
sudo dpkg -i linux-headers-2.6.20-16-2be-k7_2.6.20-16_i386.deb
 
</nowiki></pre>
 
</nowiki></pre>
  
第131行: 第180行:
 
=== Rebuilding ''linux-restricted-modules'' ===
 
=== Rebuilding ''linux-restricted-modules'' ===
  
''(These instruction are taken from an example using a different kernel to that used in the previous examples))''
+
The Linux-Restricted-Modules (l-r-m) package contains a number of non-DFSG-free drivers (as well as some firmware and the ipw3945 wireless networking daemon) which, in a perfect world, wouldn't have to be packaged separately, but which unfortunately are not available under a GPL-compatible license. If you use any of the hardware supported by the l-r-m package, you will likely find that your system does not work as well after switching to a custom kernel. In this case you should try to compile the l-r-m package.
 
+
You will need to install all the linux-headers packages that you build in the previous stage.
+
  
Then, download the source to ''linux-restricted-modules''
+
You will need to install the linux-headers packages that you built in the previous stage.
  
 
<pre><nowiki>
 
<pre><nowiki>
sudo apt-get source linux-restricted-modules-2.6.20-15-lowlatency
+
sudo dpkg -i linux-source-2.6.20-2.6.20/debian/build/linux-headers*.deb
 
</nowiki></pre>
 
</nowiki></pre>
  
and satisfy it's build dependencies
+
==== Get the source ====
  
 +
First, we make sure we have all the packages necessary to build l-r-m, and then we fetch the source:
 
<pre><nowiki>
 
<pre><nowiki>
sudo apt-get build-dep linux-restricted-modules-2.6.20-15-lowlatency
+
sudo apt-get build-dep linux-restricted-modules-common
 +
apt-get source linux-restricted-modules-common
 +
cd linux-restricted-modules-2.6.*
 
</nowiki></pre>
 
</nowiki></pre>
  
and unpack it
+
==== Adjust debian/rules ====
  
 +
Debian (and hence Ubuntu) packages are built by calling the the debian/rules script from the top source directory; this script is a specialized Makefile with 'targets' you can call as arguments when you run the script. The l-r-m debian/rules script is geared towards developers working with the official builds and makes certain assumptions about kernel version numbers and what header packages are installed; if you need to build l-r-m on your own, you will need to customize it. The full range of customizations are beyond the scope of this guide, but here are a couple examples of problems you're likely to run into and possible ways to solve them:
 +
 +
''Kernel Version Mismatch ''
 +
 +
If you built your kernel using one of the recommended methods, your kernel version is probably not precisely what debian/rules expects; for instance, my git-built kernel is called 2.6.19-7-ref-generic instead of 2.6.19-7-generic, while my make-kpkg-built kernel is called 2.6.19-7-suspend2-generic. You can solve this problem by changing this line (the actual value here will be different by the time you read this):
 
<pre><nowiki>
 
<pre><nowiki>
dpkg-source -x linux-restricted-modules-2.6.20_2.6.20.5-15.20.dsc
+
abi_version = 7
 +
</nowiki></pre>
 +
to something like this:
 +
<pre><nowiki>
 +
abi_version = 7-ref
 
</nowiki></pre>
 
</nowiki></pre>
  
Then you need to edit the debian/rules file, to add the abi-suffix generated when you built your kernel package. Look for the lines
+
After making this change, the control file will have to be rebuilt by running:
 +
<pre><nowiki>
 +
debian/rules debian/control
 +
</nowiki></pre>
  
{|border="1" cellspacing="0"
+
'' Too Many Flavours ''
| Old text || New Text
+
|-
+
| # kernel || # kernel
+
|-
+
| abi_version        == 15 || abi_version        == 15-2be
+
|}
+
  
but where 2be is the abi suffix generated for your kernel packages.
+
debian/rules expects you to have the header files for all possible kernel flavours already installed. If you only compiled one kernel flavour, this is of course impossible. So you need to look in debian/rules and change all the "flavours" lines so that only one flavour is listed -- the one you have already compiled. so for instance in my case, working on the i386 architecture:
 +
<pre><nowiki>
 +
flavours := $(addprefix $(kernel_abi_version)-,generic, server, lowlatency)
 +
</nowiki></pre>
 +
became:
 +
<pre><nowiki>
 +
flavours := $(addprefix $(kernel_abi_version)-,generic)
 +
</nowiki></pre>
 +
You may find that further modifications are necessary.
  
Finally build your packages
+
'' udebs mess you up ''
  
 +
The standard "binary" target includes building udebs, which look for flavours that you may not have installed. I did two things:
 +
* Modified debian/d-i/kernel-versions.in
 +
* deleted "build-udebs" from the binary target
 +
I'm not sure the latter was necessary, but as you are not likely to need to build any udebs it's probably pretty safe to do.
 +
 +
 +
Now cross your fingers and hope! Try to build with:
 
<pre><nowiki>
 
<pre><nowiki>
cd linux-restricted-modules-2.6.20-2.6.20.5
+
fakeroot debian/rules binary
debuild -rfakeroot
+
 
</nowiki></pre>
 
</nowiki></pre>
  
=== Other ===
+
Note: you will need around 8 hours of compilation time and around 10 Gb of hard drive space to compile all kernel flavours and a restricted modules.
[[UbuntuHelp:CompileKernelModule|How to compile a kernel module]]
+
 
 +
=== Comments ===
 +
 
 +
Please go to the community wiki page for comments, questions and discussion: https://wiki.ubuntu.com/KernelCustomBuild
 +
 
  
 
=== External information ===
 
=== External information ===

2007年11月22日 (四) 13:19的版本



Disclaimer

Building and using a custom kernel will make it very difficult to get support for your system. You will not be allowed to file bugs on the custom-built kernel (if you do, they will be Rejected without 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 build stock kernels from kernel.org. This is how to rebuild the actual Ubuntu kernel 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, but checked it out because it looked interesting. Believe me, this isn't interesting at all :)

Tools you'll need

To start, you will need to install a few packages.

sudo apt-get install linux-kernel-devel fakeroot build-essential

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.


Get the kernel source

There are a few ways to obtain the Ubuntu kernel source. One is to use git (detailed instructions on it can be found in the Kernel Git Guide), which allows you to always stay in sync with the latest Ubuntu kernel source.

The simplest way, useful to those who want to rebuild the standard Ubuntu packages with additional patches is:

sudo apt-get build-dep linux-source-2.6.22
apt-get source linux-source-2.6.22

Note that this will almost always be out of date compared to the latest development source, so you should use git if you need the latest patches.


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 for how to apply.

The stock Ubuntu configs are located in debian/config/ARCH/ where ARCH is the architecture you are building for. In this directory 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


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.

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

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

AUTOBUILD=1 fakeroot debian/rules binary-debs

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.

To build a specific target, use this command:

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:

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

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

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.

Alternate Build Method: The Old-Fashioned Debian Way

The new Ubuntu build system is great for developers, for people who need the absolute latest bleeding-edge kernel, and people who need to build a diverse set of kernels (several "flavours"). However it can be a little complex for ordinary users. If you don't need the latest development sources, there is a simpler way to compile your kernel from the linux-source package. As suggested above, all you need for this is:

sudo apt-get install linux-source
mkdir ~/src
cd ~/src
tar xjvf /usr/src/linux-source-<version-number-here>.tar.bz2
cd linux-source-<version-number-here>

Now you are in the top directory of a kernel source tree. Before building the kernel, you must configure it. If you wish to re-use the configuration of your currently-running kernel, start with

cp -vi /boot/config-`uname -r` .config

Then, regardless of whether you're re-using existing configuration or starting from scratch:

make menuconfig # or "xconfig" if you prefer

If you re-used the existing configuration, note that Ubuntu kernels build with debugging information on, which makes the resulting kernel modules (*.ko files) much larger than they would otherwise be. To turn this off, go into "Kernel hacking"; then, under "Kernel debugging", turn OFF "Compile the kernel with debug info".

Now you can compile the kernel and create the packages:

make-kpkg --rootcmd fakeroot --initrd --append-to-version=-some-string-here kernel-image kernel-headers

The packages should be placed in ~/.

Build the kernel (when source is from a linux-source package)

make-kpkg clean
fakeroot make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers

The deb packages are in the parent directory.

Install the new kernel

If you want to see the ubuntu splash screen (or use text mode) before you get to X instead of just a black screen, you'll want to make sure the framebuffer driver loads:

echo vesafb | sudo tee -a /etc/initramfs-tools/modules
echo fbcon | sudo tee -a /etc/initramfs-tools/modules

Now that you've told initramfs-tools what modules it should include and the build is complete, you can install the generated debs using dpkg:

sudo dpkg -i linux-image-2.6.20-16-2be-k7_2.6.20-16_i386.deb
sudo dpkg -i linux-headers-2.6.20-16-2be-k7_2.6.20-16_i386.deb

If you use modules from linux-restricted-modules, you will need to recompile this against your new linux-headers package.

Rebuilding linux-restricted-modules

The Linux-Restricted-Modules (l-r-m) package contains a number of non-DFSG-free drivers (as well as some firmware and the ipw3945 wireless networking daemon) which, in a perfect world, wouldn't have to be packaged separately, but which unfortunately are not available under a GPL-compatible license. If you use any of the hardware supported by the l-r-m package, you will likely find that your system does not work as well after switching to a custom kernel. In this case you should try to compile the l-r-m package.

You will need to install the linux-headers packages that you built in the previous stage.

sudo dpkg -i linux-source-2.6.20-2.6.20/debian/build/linux-headers*.deb

Get the source

First, we make sure we have all the packages necessary to build l-r-m, and then we fetch the source:

sudo apt-get build-dep linux-restricted-modules-common
apt-get source linux-restricted-modules-common
cd linux-restricted-modules-2.6.*

Adjust debian/rules

Debian (and hence Ubuntu) packages are built by calling the the debian/rules script from the top source directory; this script is a specialized Makefile with 'targets' you can call as arguments when you run the script. The l-r-m debian/rules script is geared towards developers working with the official builds and makes certain assumptions about kernel version numbers and what header packages are installed; if you need to build l-r-m on your own, you will need to customize it. The full range of customizations are beyond the scope of this guide, but here are a couple examples of problems you're likely to run into and possible ways to solve them:

Kernel Version Mismatch

If you built your kernel using one of the recommended methods, your kernel version is probably not precisely what debian/rules expects; for instance, my git-built kernel is called 2.6.19-7-ref-generic instead of 2.6.19-7-generic, while my make-kpkg-built kernel is called 2.6.19-7-suspend2-generic. You can solve this problem by changing this line (the actual value here will be different by the time you read this):

abi_version = 7

to something like this:

abi_version = 7-ref

After making this change, the control file will have to be rebuilt by running:

debian/rules debian/control

Too Many Flavours

debian/rules expects you to have the header files for all possible kernel flavours already installed. If you only compiled one kernel flavour, this is of course impossible. So you need to look in debian/rules and change all the "flavours" lines so that only one flavour is listed -- the one you have already compiled. so for instance in my case, working on the i386 architecture:

flavours := $(addprefix $(kernel_abi_version)-,generic, server, lowlatency)

became:

flavours := $(addprefix $(kernel_abi_version)-,generic)

You may find that further modifications are necessary.

udebs mess you up

The standard "binary" target includes building udebs, which look for flavours that you may not have installed. I did two things:

  • Modified debian/d-i/kernel-versions.in
  • deleted "build-udebs" from the binary target

I'm not sure the latter was necessary, but as you are not likely to need to build any udebs it's probably pretty safe to do.


Now cross your fingers and hope! Try to build with:

fakeroot debian/rules binary

Note: you will need around 8 hours of compilation time and around 10 Gb of hard drive space to compile all kernel flavours and a restricted modules.

Comments

Please go to the community wiki page for comments, questions and discussion: https://wiki.ubuntu.com/KernelCustomBuild


External information

http://www.howtoforge.com/kernel_compilation_ubuntu Compile a kernel from kernel.org source in Ubuntu