Build a fedora kernel: Updated

The primary source of information on building a custom kernel in fedora is here. This post will step you through that with an additional step to add the patches you may need.

🔗 Get the source

First, where-ever you feel like, clone the kernel packaging source, for example:

cd ~ && mkdir projects && cd ~/projects
fedpkg clone -a kernel

Then cd in to the new directory and checkout the required branch matching the fedora release number you need:

cd ~/projects/kernel
git checkout origin/f33

you can also checkout f34 which will be the 5.11 kernel, and what the more recent patches will apply to.

To save work with git (not a compulsory step, but will help with updating), do:

git checkout -b patch-f33
git branch -u origin/f33

🔗 Prepare for build

🔗 Install deps


sudo dnf install fedpkg fedora-packager rpmdevtools ncurses-devel pesign grubby
sudo dnf builddep kernel.spec

🔗 Edit kernel.spec

In kernel.spec is where you will do most of the work, so open up that file in your favourite text editor which is vim and search for this line:

# define buildid .local

and replace it with:

%define buildid .local

then a few hundred or so lines further down the file you will find lines like this one:


don't worry if that particular line doesn't exist, look for Patch1 or Patch, case-sensitive. This is where you will need to add patches, an example is adding the asus-hid driver patch required for ASUS laptops with the 0x1866 device (N-Key Keyboard). So below the line above add:

# ROG Laptops
Patch500: 0001-WMI-asus-Reduce-G14-and-G15-match-to-min-product-nam.patch
Patch501: 0001-HID-asus-Filter-keyboard-EC-for-old-ROG-keyboard.patch
Patch502: 0001-HID-asus-Add-support-for-2021-ASUS-N-Key-keyboard.patch

and lastly, grab the patches - they must be in the same directory as kernel.spec:

  1. 0001-WMI-asus-Reduce-G14-and-G15-match-to-min-product-nam.patch
  2. 0001-HID-asus-Filter-keyboard-EC-for-old-ROG-keyboard.patch
  3. 0001-HID-asus-Add-support-for-2021-ASUS-N-Key-keyboard.patch

and then build using fedpkg --release f33 local (remember to replace f33 with the branch you checked out).

Update1: for whatever reason, the patches haven't been applying in the recent builds so you may need to manaully add them before the # END OF PATCH APPLICATIONS line like-so:

ApplyOptionalPatch 0001-WMI-asus-Reduce-G14-and-G15-match-to-min-product-nam.patch
ApplyOptionalPatch 0001-HID-asus-Filter-keyboard-EC-for-old-ROG-keyboard.patch
ApplyOptionalPatch 0001-HID-asus-Add-support-for-2021-ASUS-N-Key-keyboard.patch

You can also build non-debug with:

make release
fedpkg --release f33 local

Update2: make release is borked for the kernel builds for whatever reason. I'm looking in to it and will update instructions.

Update3: some laptops have touchpad issues, particularly Ryzen models. For these machines you need to edit kernel-local so it contains amd_pinctrl:

# This file is intentionally left empty in the stock kernel. Its a nicety
# added for those wanting to do custom rebuilds with altered config opts.

🔗 Install

All the rpm packages will be located in ~/projects/kernel/x86_64/, it's likely that you will need to install all except the debug packages.

🔗 Updating

If you have any work to save, git commit it, or git stash.

git pull

then git stash pop if you stashed work.