BuildYourOwnKernel

Differences between revisions 31 and 39 (spanning 8 versions)
Revision 31 as of 2014-12-17 01:50:26
Size: 5005
Editor: adsl-75-10-157-132
Comment: Told the people who are building custom kernels what to do to prevent "apt-get upgrade" from listing the Ubuntu kernel as upgradeable.
Revision 39 as of 2018-08-30 04:39:47
Size: 6142
Editor: anthonywong
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
##(see the SpecSpec for an explanation)
||<tablestyle="float:right; font-size: 0.9em; width:40%; background:#F1F1ED; margin: 0 0 1em 1em;" style="padding:0.5em;"><<TableOfContents()>>||
Line 55: Line 58:
If you've not built a kernel on your system before, there are some packages needed before you can successfully build. You can get these installed with: If you have not built a kernel on your system before, there are some packages needed before you can successfully build. You can get these installed with:
Line 59: Line 62:
}}}

The above command requires your system to have the correct {{{deb-src}}} lines in {{{/etc/apt/sources.list}}}. For example, on Xenial you should have:
    {{{
deb-src http://archive.ubuntu.com/ubuntu xenial main
deb-src http://archive.ubuntu.com/ubuntu xenial-updates main
Line 66: Line 75:
chmod a+x debian/rules
Line 69: Line 79:
fakeroot debian/rules editconfigs fakeroot debian/rules editconfigs # you need to go through each (Y, Exit, Y, Exit..) or get a complaint about config later
Line 74: Line 84:
apt-get will try to "upgrade" the kernel to the stock build/version of the Ubuntu kernel if you build a custom kernel without appending an extra string to the end of your kernel version. To prevent apt-get from listing the Ubuntu kernel as upgradeable when you type `apt-get upgrade`, you must (from the kernel documentation) append an extra string to the end of your kernel version. This will show up when you type uname, for example.

Kernel Configuration Menu Navigating Directions
 1. General setup --->
 2. () Local version - append to kernel release
In order to make your kernel "newer" than the stock Ubuntu kernel from which you are based you should add a local version modifier. Add something like "+test1" to the end of the first version number in the {{{debian.master/changelog}}} file, before building. This will help identify your kernel when running as it also appears in {{{uname -a}}}. Note that when a new Ubuntu kernel is released that will be newer than your kernel (which needs regenerating), so care is needed when upgrading. NOTE: do not attempt to use CONFIG_LOCALVERSION as this _will_ break the build.
Line 87: Line 93:
fakeroot debian/rules binary-headers binary-generic # quicker build:
fakeroot debian/rules binary-headers binary-generic binary-perarch
# if you need linux-tools or lowlatency kernel, run instead:
fakeroot debian/rules binary
Line 90: Line 99:
If the build is successful, a set of three .deb binary package files will be produced in the directory above the build root directory. For example after building a kernel with version "2.6.38-7.37" on an amd64 system, these three (or four) .deb packages would be produced: If the build is successful, a set of three .deb binary package files will be produced in the directory above the build root directory. For example after building a kernel with version "4.8.0-17.19" on an amd64 system, these three (or four) .deb packages would be produced:
Line 95: Line 104:
    linux-headers-2.6.38-7_2.6.38-7.37_all.deb
    linux-headers-2.6.38-7-generic_2.6.38-7.37_amd64.deb
    linux-image-2.6.38-7-generic_2.6.38-7.37_amd64.deb
    linux-headers-4.8.0-17_4.8.0-17.19_all.deb
    linux-headers-4.8.0-17-generic_4.8.0-17.19_amd64.deb
    linux-image-4.8.0-17-generic_4.8.0-17.19_amd64.deb
Line 107: Line 116:
sudo dpkg -i linux*2.6.38-7.37*.deb sudo dpkg -i linux*4.8.0-17.19*.deb
Line 109: Line 118:
}}}


== Debug Symbols ==

Sometimes it is useful to have debug symbols built as well. Two additional steps are needed. First pkg-config-dbgsym needs to be installed. Second when executing the binary-* targets you need to add 'skipdbg=false'.

    {{{
sudo apt-get install pkg-config-dbgsym
fakeroot debian/rules clean
fakeroot debian/rules binary-headers binary-generic binary-perarch skipdbg=false

This page will describe how to easily build the kernel.

The majority of users that are interested in building their own kernel are doing so because they have installed Ubuntu on their system and they wish to make a small change to the kernel for that system. In many cases the user just wants to make a kernel configuration change.

The purpose of this page is to give that user a minimum amount of information for them to meet the goal of making a simple change to the kernel, building it and installing their kernel. It is not intended to be the definitive guide to doing Ubuntu kernel development.

Obtaining the source for an Ubuntu release

There are a number of different ways of getting the kernel sources. The two main ways will be documented here.

If you have installed a version of Ubuntu and you want to make changes to the kernel that is installed on your system, use the apt-get method (described below) to obtain the sources.

However, if you wish to get the most up to date sources for the Ubuntu release you are running and make changes to that, use the git method (described below) to obtain the sources.

apt-get

The source code which generated a specific binary package may be obtained using the apt-get source <package> command. For example to obtain the source for the currently running kernel you can use the command:

  • apt-get source linux-image-$(uname -r)

git

All of the Ubuntu Kernel source is maintained under git. The source for each release is maintained in its own git repository on kernel.ubuntu.com. To obtain a local copy you can simply git clone the repository for the release you are interested in as shown below.

  • git clone git://kernel.ubuntu.com/ubuntu/ubuntu-<release codename>.git

For example to obtain the precise tree:

  • git clone git://kernel.ubuntu.com/ubuntu/ubuntu-precise.git

Build Environment

If you have not built a kernel on your system before, there are some packages needed before you can successfully build. You can get these installed with:

  • sudo apt-get build-dep linux-image-$(uname -r)

The above command requires your system to have the correct deb-src lines in /etc/apt/sources.list. For example, on Xenial you should have:

  • deb-src http://archive.ubuntu.com/ubuntu xenial main
    deb-src http://archive.ubuntu.com/ubuntu xenial-updates main

Modifying the configuration

This step can be skipped if no configuration changes are wanted. The build process will use a configuration that is put together from various sub-config files. The simplest way to modify anything here is to run:

  • chmod a+x debian/rules
    chmod a+x debian/scripts/*
    chmod a+x debian/scripts/misc/*
    fakeroot debian/rules clean
    fakeroot debian/rules editconfigs # you need to go through each (Y, Exit, Y, Exit..) or get a complaint about config later

This takes the current configuration for each architecture/flavour supported and calls menuconfig to edit its config file. The chmod is needed because the way the source package is created, it loses the executable bits on the scripts.

In order to make your kernel "newer" than the stock Ubuntu kernel from which you are based you should add a local version modifier. Add something like "+test1" to the end of the first version number in the debian.master/changelog file, before building. This will help identify your kernel when running as it also appears in uname -a. Note that when a new Ubuntu kernel is released that will be newer than your kernel (which needs regenerating), so care is needed when upgrading. NOTE: do not attempt to use CONFIG_LOCALVERSION as this _will_ break the build.

Building the kernel

Building the kernel is quite easy. Change your working directory to the root of the kernel source tree and then type the following commands:

  • fakeroot debian/rules clean
    # quicker build:
    fakeroot debian/rules binary-headers binary-generic binary-perarch
    # if you need linux-tools or lowlatency kernel, run instead:
    fakeroot debian/rules binary

If the build is successful, a set of three .deb binary package files will be produced in the directory above the build root directory. For example after building a kernel with version "4.8.0-17.19" on an amd64 system, these three (or four) .deb packages would be produced:

  • cd ..
    ls *.deb
        linux-headers-4.8.0-17_4.8.0-17.19_all.deb
        linux-headers-4.8.0-17-generic_4.8.0-17.19_amd64.deb
        linux-image-4.8.0-17-generic_4.8.0-17.19_amd64.deb

on later releases you will also find a linux-extra- package which you should also install if present.

Testing the new kernel

Install the three-package set (on your build system, or on a different target system) with dpkg -i and then reboot:

  • sudo dpkg -i linux*4.8.0-17.19*.deb
    sudo reboot

Debug Symbols

Sometimes it is useful to have debug symbols built as well. Two additional steps are needed. First pkg-config-dbgsym needs to be installed. Second when executing the binary-* targets you need to add 'skipdbg=false'.

  • sudo apt-get install pkg-config-dbgsym
    fakeroot debian/rules clean
    fakeroot debian/rules binary-headers binary-generic binary-perarch skipdbg=false

See also

The above instructions provide a very simple recipe for obtaining the sources and then building them. If you are going to be doing more kernel development than simple configuration changes you may want to look at:

Kernel/BuildYourOwnKernel (last edited 2024-01-25 18:52:39 by mhcerri)