- Ubuntu Wiki
- Prerequisites
- Kernel Build and Installation
- Using Ubuntu Kernel Configuration
- Ubuntu Wiki
- Build Environment
- Obtaining the source for an Ubuntu release
- apt-get
- git
- Modifying the configuration
- Building the kernel
- Testing the new kernel
- Debug Symbols
- See also
- Ubuntu Wiki
- Obtaining the kernel sources for an Ubuntu release using apt-get
- Obtaining the kernel sources for an Ubuntu release using git
- Obtaining a copy
- Applying Patches
- Apply patches using git cherry-pick
- Set up chroot build environment
- Get the automated chroot build scripts
- Create the chroot environment
- Packages required on a build system
- Install build system package requisites
- Building the kernel packages
- chroot into the build environment
- Setup the build tree
- Modify debian/changelog
- Build the kernel package
- Build the kernel header, source, doc packages
Ubuntu Wiki
Many times patches for bugs are committed upstream but have yet to make their way down to the Ubuntu kernel. It is often helpful if users are able to verify if the upstream patches do indeed resolve the issue they are witnessing. Likewise, in the opposite situation, it is useful to know if a bug may still exist upstream.
The following document should help users build their own kernel from the upstream mainline kernel to help verify if a bug still exists or not. If a bug is still present in the upstream kernel, it is encouraged that the bug be reported upstream following the procedure noted in this page. Please note that the following steps are targeted towards Ubuntu users and focuses on building the mainline kernel from the git repository at http://git.kernel.org.
Prerequisites
There are a few tools that are necessary in order to build your own kernel(s). The ‘git’ (or ‘git-core’ for 10.04 or before) package provides the git revision control system which will be used to clone the mainline git repository. The ‘kernel-package’ provides the make-kpkg utility which automatically build your kernel and generate the linux-image and linux-header .deb files which can be installed. You will need to install the following packages:
sudo apt-get install git build-essential kernel-package fakeroot libncurses5-dev libssl-dev ccache bison flex libelf-dev dwarves
Kernel Build and Installation
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
If you only want to test all commits up to and including a specific one, instead of every commit you just downloaded, one may execute:
cp /boot/config-$(uname -r) .config
In cases where your kernel source is significantly newer than the existing config file, you’ll be presented with all of the new config options for which there is no existing config file setting. You can either sit there and keep hitting Enter to take the default (generally safe), or you can just run:
make -j $(getconf _NPROCESSORS_ONLN) deb-pkg LOCALVERSION=-custom
sudo dpkg -i linux-image-2.6.24-rc5-custom_2.6.24-rc5-custom-10.00.Custom_i386.deb sudo dpkg -i linux-headers-2.6.24-rc5-custom_2.6.24-rc5-custom-10.00.Custom_i386.deb
Using Ubuntu Kernel Configuration
- Perform steps 1-7 above, use the Ubuntu kernel config in step 4
- Override the kernel-package default packaging scripts with the Ubuntu packaging scripts:
cd $HOME git clone git://kernel.ubuntu.com/ubuntu/ubuntu-lucid.git cp -a /usr/share/kernel-package ubuntu-package cp ubuntu-lucid/debian/control-scripts/ ubuntu-package/pkg/image/ cp ubuntu-lucid/debian/control-scripts/headers-postinst ubuntu-package/pkg/headers/
cd $HOME/linux CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --append-to-version=-custom --overlay-dir=$HOME/ubuntu-package kernel_image kernel_headers
Note: The «—overlay-dir» option is only available in Lucid or later. If you need to build a kernel on a previous distribution, either install a backport of kernel-package if available, or manually edit /usr/share/kernel-package as needed.
KernelTeam/GitKernelBuild (последним исправлял пользователь pmaydell 2021-04-10 11:22:56)
The material on this wiki is available under a free license, see Copyright / License for details.
Ubuntu Wiki
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
sudo apt-get build-dep linux linux-image-$(uname -r)
sudo apt-get install libncurses-dev gawk flex bison openssl libssl-dev dkms libelf-dev libudev-dev libpci-dev libiberty-dev autoconf llvm
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-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
apt-get source linux-image-unsigned-$(uname -r)
git
git clone git://kernel.ubuntu.com/ubuntu/ubuntu-.git
git clone git://kernel.ubuntu.com/ubuntu/ubuntu-disco.git
Modifying the configuration
chmod a+x debian/rules chmod a+x debian/scripts/* chmod a+x debian/scripts/misc/* LANG=C fakeroot debian/rules clean LANG=C 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
LANG=C fakeroot debian/rules clean # quicker build: LANG=C fakeroot debian/rules binary-headers binary-generic binary-perarch # if you need linux-tools or lowlatency kernel, run instead: LANG=C fakeroot debian/rules binary
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
sudo dpkg -i linux*4.8.0-17.19*.deb sudo reboot
Debug Symbols
sudo apt-get install pkg-config-dbgsym LANG=C fakeroot debian/rules clean LANG=C fakeroot debian/rules binary-headers binary-generic binary-perarch skipdbg=false
See also
Kernel Git Guide | More information about using git to pull down the kernel sources. |
ARM Cross Compile | For more info about ARM and cross compilation. |
Kernel/BuildYourOwnKernel (последним исправлял пользователь b-stolk 2022-09-08 00:38:14)
The material on this wiki is available under a free license, see Copyright / License for details.
Ubuntu Wiki
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.
Obtaining the kernel sources for an Ubuntu release using apt-get
apt-get source linux-image-unsigned-$(uname -r)
apt-get source linux-image-$(uname -r)
Obtaining the kernel sources for an Ubuntu release using git
The source for each release is maintained in its own git repository on Launchpad.
git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source//+git/
git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/cosmic
groovy | git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/groovy |
focal | git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/focal |
bionic | git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/bionic |
Replace your intended OS series in the above, and pull the source for the kernels you need.
The distro kernel is always on the master branch in these repositories. Each release also has a master-next branch containing the commits that will go onto the master branch and become the next release for that release.
A number of releases also have other source packages which represent other related but divergent kernels for other purposes. For example, there is a specialized AWS kernel available in the linux-aws source package. (Previously these sorts of things were done in Topic Branches and some older kernels and projects still use them.)
Obtaining a copy
To obtain a local copy you can simply git clone the repository for the release you are interested. The git command is part of the git package.
git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/bionic
git clone git://kernel.ubuntu.com/ubuntu/linux.git git clone --reference linux git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/groovy
In each case you will end up with a new directory ubuntu- containing the source and the full history which can be manipulated using the git command from within each directory.
$ git tag -l Ubuntu-* Ubuntu-5.4.0-47.51 Ubuntu-5.4.0-48.52 Ubuntu-5.4.0-49.53 Ubuntu-5.4.0-51.56 Ubuntu-5.4.0-52.57 $
git checkout -b temp Ubuntu-5.4.0-52.57
You may then manipulate the release - for example, by adding new commits.
Applying Patches
Apply patches using git cherry-pick
To apply individual patches from an upstream kernel tree to your current Ubuntu kernel tree use the following command:
Where, SHAID is the commit ID of the patch you want to apply.
Set up chroot build environment
Get the automated chroot build scripts
- buildscripts: Scripts used to farm out the kernel builds to very fast remote
- chroot-setup: Scripts to setup jailed kernel compilation enviroments.
- daily-test-isos: Scripts and support files to produce daily, custom test isos.
- git-hooks: Optional hooks to help you commit patches
- maintscripts: Scripts used for general / stable kernel maintenance
- mainline-build: Scripts to produce .debs for mainline kernels
- misc: Everything else.
Download them using the following command.
git clone git://kernel.ubuntu.com/ubuntu/kteam-tools.git kteam-tools
Create the chroot environment
To automatically create the chroot environment use:
sudo mkdir -p /usr3/chroots # prep environment sudo chroot-setup/make_chroot precise amd64 http://archive.ubuntu.com/ubuntu
- arch stands for different arch supported by the CPU, for example i386 on AMD64 or LPIA on i386 etc.
- suite stands for release name such as hardy, gutsy, intrepid etc.
- mirror stands for the http location to download environment from, http://host[:port]/dir/
Note: You don't need to specify a mirror when using the LPIA arch
Packages required on a build system
- ccache
- devscripts
- xmlto
- docbook-utils
- gs
- transfig
- sharutils
Install build system package requisites
Certain packages are required to be installed on the build system. You can install these packages using the following command:
sudo apt-get install git-core debhelper build-essential fakeroot kernel-wedge makedumpfile
Optionally you may also install the following packages that might help debuild to function flawlessly.
sudo apt-get install ccache devscripts xmlto docbook-utils gs transfig sharutils libdw-dev libdw1 libelf-dev
Building the kernel packages
chroot into the build environment
Depending on what may be installed on your system you may use "dchroot" or "schroot" to chroot into the build environment.
You should chroot into a 64bit build environment to build 64bit kernel package, 32bit build environemt to build 32bit kernel package.
Setup the build tree
This step generates the debian control files required to build the kernel. The clean target is a bit of a misnomer here since we moved the generated files (control.stub, control) out of version control. The clean target actually creates these files. It is a known drawback, and unavoidable.
fakeroot debian/rules clean
Modify debian/changelog
Modify the debian/changelog file to reflect something unique about this build, for example, you may use a launchpad bug number that you might be building this kernel for.
Modify the the first line, for example:
linux (2.6.27-12.28) UNRELEASED; urgency=low
linux (2.6.27-12.28~lpNNNNNNUSERNAME1) UNRELEASED; urgency=low
Build the kernel package
fakeroot debian/rules binary-generic
fakeroot debian/rules binary-arch
Build the kernel header, source, doc packages
The following will build the header, source, doc packages.
fakeroot debian/rules binary-indep
Kernel/Dev/QuickBuildLocal (последним исправлял пользователь 193 2010-07-20 10:29:33)
The material on this wiki is available under a free license, see Copyright / License for details.