0% found this document useful (0 votes)
28 views4 pages

Build Your Own Kernel

How to build your own kernel in Ubuntu

Uploaded by

Rabo Karabekian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views4 pages

Build Your Own Kernel

How to build your own kernel in Ubuntu

Uploaded by

Rabo Karabekian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

BuildYourOwnKernel

Contents

1. Build Environment
2. Obtaining the source for an
Ubuntu release
1. apt
2. git
3. Modifying the configuration
4. Building the kernel
5. Testing the new kernel
6. Debug Symbols
7. See also

This page describes how to 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.

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 build-dep linux linux-image-unsigned-$(uname -r)

Unfortunately, the above does not install all of the necessary dependencies. The current Disco
Dingo release requires the following additional packages.

 sudo apt install libncurses-dev gawk flex bison openssl libssl-dev


dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf llvm

If you are going to be using git, install it via:

 sudo apt install git

The above command requires your system to have the correct deb-src lines in
/etc/apt/sources.list. For example, on Disco Dingo you should have:
 deb-src http://archive.ubuntu.com/ubuntu disco main
 deb-src http://archive.ubuntu.com/ubuntu disco-updates main

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 method 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.

apt

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

 apt source linux-image-unsigned-$(uname -r)

git

Follow the instructions in the Git guide.

Modifying the configuration


This step can be skipped if no configuration changes are wanted.

The build process uses a configuration that is put together from various sub-config files. The
simplest way to modify anything here is to run the commands below. This takes the current
configuration for each architecture/flavour supported and calls menuconfig to edit its config
file. The chmod is needed only if you obtain the source by apt rather than git, because the
way the source package is created, it loses the executable bits on the scripts.:

 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

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, several .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 more) .deb packages will 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 debian packages (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 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:

More information about using git to pull down the kernel


Kernel Git Guide
sources.
ARM Cross
For more info about ARM and cross compilation.
Compile

You might also like