Building a Fedora Kernel (Screenplay)

This is a transcript of what I did to get to a running custom-built kernel.

Why Build the Entire Kernel When I Only Want to Build a Module

To build only kernel modules, they say, it is sufficient to install the kernel-devel package. However, that package tends to not be available in the version that you need it for (usually you build against a kernel that runs on a different system, in a different version).

Building from “Exploded Git Tree”

(Documentation on Fedora Wiki)

The “Exploded Git Tree” is Fedorish for “a kernel tree that is less integrated with the Fedora workflow, and thus more suitable for developers who refuse to integrate with any workflow”. This is me.

See below if you like workflows and RPMs.

$ uname -r
5.8.18-300.fc33.x86_64

Clone tree, and checkout the target system kernel version. Create a branch for it; read on for why changes need to be committed.

$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/jwboyer/fedora.git kernel-exploded-git-tree
$ cd kernel-exploded-git-tree
$ git checkout kernel-5.8.18-300.fc33

Edit the toplevel Makefile to fix the EXTRAVERSION. External modules built against that kernel need to have the exact same version built-in. I’d have expected the exploded tree to already contain a suitable EXTRAVERSION, but this is not the case.

Our target kernel is 5.8.18-300.fc33.x86_64, so we edit the toplevel Makefile to have

EXTRAVERSION = -300.fc33.x86_64

The kernel build system checks for version control cleanliness, and adds a “+” sign if something’s wrong, such as

  • There are uncommitted changes

  • The tree is past a tagged commit

These checks are not applied if there is no version control at all, so let’s do this simple workaround.

$ mv .git .git-hidden

Configure kernel, using the target system config.

$ scp 192.168.1.130:/boot/config-5.8.18-300.fc33.x86_64 .config
$ make oldconfig

Build kernel. If you only want to build external modules against some specific kernel version, you do have to build the entire kernel - not just modules as it used to be in old times. See here for more.

$ make -j6

Restore version control,

$ mv .git-hidden .git

Building from the RPM Source

(Documentation on Fedora Wiki)

Prerequisites
# dnf install fedpkg fedora-packager rpmdevtools ncurses-devel pesign grubby
  • Clone Fedora’s kernel RPM. (-a is anonymous, as I don’t have a developer account and don’t intent to write back into their repo.)

  • As of this writing Fedora is at its 33rd release. We intend to make modifications, so we dont just checkout that branch, but rather create a tracking branch for it.

    $ fedpkg clone -a kernel
    $ cd kernel/
    $ git checkout --track remotes/origin/f33
    
  • Modify kernel version, append .local. In kernel.spec, modify the line

    # define buildid .local
    

    to

    %define buildid .local
    
  • Pull in more packages, based upon what’s in the kernel specs.

    # dnf builddep kernel.spec
    
  • Add myself to /etc/pesign/users

    # sh -c 'echo jfasch >> /etc/pesign/users'
    # /usr/libexec/pesign/pesign-authorize
    
  • Build

$ fedpkg local