Building the Fedora Kernel

Building the Fedora Kernel

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

fedpkg

.

fedpkg

is used to get the kernel source code. We use

fedpkg

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

my_kernel

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

%define

in

kernel.spec

that can be enabled for this purpose.

-# define buildid .local
+%define buildid .my_kernel

This will give the kernel the name

my_kernel

.

As mentioned previously, the kernel is just another package. Standard

fedpkg

commands can be used to build.

$ fedpkg local

This will build the kernel. RPMs will be generated in the

pkg-git

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

fast-build.sh

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

config-local

. The easiest way to add patches is to use the script

newpatch.sh

.

$ ./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.

For Developers Using Software

14 Comments

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

  2. more posts like this please! in fact, a series on kernel building woukd be awesome.

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

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

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

  6. Leslie Satenstein

    is the first line

    dnf install packager-tools (which is not found) or
    dnf install fedora-packager ?

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

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

  9. Tsingi

    I get the same problem…

    No package packager-tools available.

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

  11. Wade Berrier

    It looks like the scripts/newpatch.sh script is out of date:

    ./scripts/newpatch.sh test.patch
    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

Comments are Closed

The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat. Fedora Magazine aspires to publish all content under a Creative Commons license but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site. The Fedora logo is a trademark of Red Hat, Inc. Terms and Conditions