Whether it’s curiosity or testing a patch, there are lots of reasons for compiling a kernel. This is a brief tutorial for compiling a kernel for Fedora.
Getting started with the kernel
The Fedora kernel is just another package in Fedora. This means that if you know how to compile other Fedora packages, you have a good start on compiling the kernel. The easiest way to compile the kernel is to use the packager tools.
$ dnf install packager-tools
This installs basic tools like
.
is used to get the kernel source code. We use
to make a clone of the Fedora kernel pkg-git in the directory called ‘kernel’. By default, the source that’s checked out will be for Rawhide. Each Fedora release has its own branch. You can use git commands to change branches. For example, to check out the source for Fedora 24, we would run the following commands.
$ fedpkg co -a kernel $ cd kernel $ git checkout -b my_kernel origin/f24
This creates a git branch named
containing the source for Fedora 24.
Building the kernel
The kernel has a number of build dependencies. These can be installed with
$ dnf builddep kernel.spec
When building a kernel for testing, it’s best to give it an identifiable name. This makes it easier to differentiate it from officially released Fedora kernels and others that have been built. There is a
in
that can be enabled for this purpose.
-# define buildid .local +%define buildid .my_kernel
This will give the kernel the name
.
As mentioned previously, the kernel is just another package. Standard
commands can be used to build.
$ fedpkg local
This will build the kernel. RPMs will be generated in the
directory under x86_64 (or the name of the architecture you are building for). This will take a long time and require up to 12GB of disk space. If you want a slightly faster build experience, you can use the
script.
$ fedpkg srpm Wrote /current/path/kernel-4.8.0-0.rc1.git1.1.my_kernel.fc26.src.rpm $ ./scripts/fast-build.sh x86_64 kernel-4.8.0-0.rc1.git1.1.my_kernel.fc26.src.rpm
This will generate only the kernel and modules.
Why rebuild the kernel?
Two common reasons to rebuild the kernel are to change configuration options and to add patches. Changes to kernel configuration options can be added to the file
. The easiest way to add patches is to use the script
.
$ ./scripts/newpatch.sh my-patch.patch
Questions about the steps for building the kernel can be sent to the Fedora kernel mailing list. The Fedora kernel wiki also has reference instructions for building a kernel.
Tarjei
$ sudo dnf install packager-tools
Last metadata expiration check: 2:15:47 ago on Tue Sep 6 08:27:22 2016.
No package packager-tools available.
Henri
dnf install fedora-packager ?
Henri
Perhaps, ‘dnf install fedora-packager ‘…
mock
more posts like this please! in fact, a series on kernel building woukd be awesome.
Victor Oliveira
I think it’s fedpkg:
dnf provides */fedpkg
Última verificação de data de vencimento de metadados: 0:00:10 atrás em Tue Sep 6 08:12:39 2016.
fedpkg-1.23-1.fc24.noarch : Fedora utility for working with dist-git
Repo : fedora
fedpkg-minimal-1.1.0-3.fc24.noarch : Script to allow fedpkg fetch to work
Repo : fedora
fedpkg-1.24-3.fc24.noarch : Fedora utility for working with dist-git
Repo : updates
Leslie Satenstein
I tried to do the dnf install with F25 alpha.
packager-tools not found
Would it be possible to indicate the Fedora release that you used for this posting?
I have tried to duplicate your results.
I did the following when packager-tools was not found
dnf install fedpkg
dnf builddep fedpkg
and proceeded from there.
I got stopped at the line with ./scripts/fastbuild
Leslie Satenstein
Hi Laura
I ran into some problems. I am using Fedora24 workstation. x86_64 and 8 gigs ram.
The first problem is that dnf did not find “packager-tools” . Is there another name in it’s place?.
I did install fedpkg and did a dnf builddep fedpkg. Is this all that is required?
The rest of the steps worked until step fedpkg local
For
-# define buildid .local
+%define buildid .my_kernel
I presume you want the first line removed, and the second line inserted. Is that a physical removal where the actual define is #define buildid .my_kernel.
fedpkg local failed
and thats where the follow on statements failed too.
In your “packager-tools” list, what is included? I would like to begin to creaate my own compiled kernel. You got me very interested, and hopefully I can follow your step by step recipe to obtain identical results.
Leslie Satenstein
is the first line
dnf install packager-tools (which is not found) or
dnf install fedora-packager ?
Gerard Braad
The package that needs to be installed in fedora-packager. not packager-tools. Also be sure to have other prerequisites installed, such as @”development-tools”
I do:
$ dnf install -y fedora-packager @”development-tools”
Gerard Braad
I setup an automated build at: https://gitlab.com/gbraad/linux-kernel-build-fedora.
The build definition is at: https://gitlab.com/gbraad/linux-kernel-build-fedora/blob/master/.gitlab-ci.yml
Leslie Satenstein
Here are my changes for successful part1 (up to step ./scripts.sh )
For the recommendation
-# define buildid .local
+%define buildid .my_kernel
Search kernel.spec for # define buildid .local and change this line to
define buildid .local
add the line
%define buildid .mykernel
NOTE
define buildid .local is a comment line
Locate the directory “kernel” within a partition where you have lots of available disk space (at lease 20gig spare)
And similarly have lots of /tmp space for the compiler and other workfiles.
The large amount of extra space will be returned when the program exits.
Tsingi
I get the same problem…
No package packager-tools available.
Leslie Satenstein
In writing my above response, the opening line % and # disappeared.
The instruction I presented should be
change # define buildid .local to ## define buildid .local
add line %define buildid .my_kernel beginning in column 1 immediately after the above line.
Wade Berrier
It looks like the scripts/newpatch.sh script is out of date:
cvs add: No CVSROOT specified! Please use the `-d' option
cvs [add aborted]: or set the CVSROOT environment variable.
Traceback (most recent call last):
File "scripts/bumpspecfile.py", line 73, in
s.getNextVR(aspec)
File "scripts/bumpspecfile.py", line 30, in getNextVR
fedora_build = rel.split('.')[pos]
IndexError: list index out of range
Try fedpkg clog or something like that
Makefile:10: recipe for target 'clog' failed
make: *** [clog] Error 1