Compile and Install a Custom Kernel on Fedora¶
This guide provides step-by-step instructions for manually configuring, compiling, and installing a custom or vanilla Linux kernel on Fedora systems.
Tested on: Fedora 44 KDE Plasma
Before you start¶
- Keep your Fedora kernel installed. The custom kernel is added alongside it, so if it fails to boot you can choose the Fedora kernel from the GRUB menu.
- Secure Boot: a kernel you compile yourself isn't signed, so it won't boot while Secure Boot is enabled unless you sign it with your own enrolled key.
- Space and time: a build needs roughly 20–30 GB free and can take an hour or more on a laptop.
Overview¶
This document provides instructions on how to manually compile the Linux kernel on Fedora (including Fedora 44 KDE). It begins with the simplest method (building a vanilla upstream kernel) and moves to more advanced configuration methods.
1. The Simplest Method: Building a Vanilla Upstream Kernel¶
Step 1: Install Build Dependencies¶
To compile the kernel manually, you need standard development tools and libraries. Open your terminal and run:
Step 2: Download the Kernel Source¶
Clone the mainline kernel tree directly from kernel.org. To get Linus Torvalds's tree, run:
Alternatively, if you want the stable release tree, you can add it with:
Step 3: Configure the Kernel¶
The simplest and most efficient way to configure a new kernel is to base it on your currently running Fedora system, disabling modules you do not currently have loaded. This will drastically reduce compilation time:
(Note: Press Enter to accept the default answers for any new kernel features introduced since your current kernel version).
Alternatively, if you prefer to build the kernel exactly as your current one without stripping out unused modules, you can copy the existing configuration and use oldconfig:
Step 4: Build the Kernel¶
Compile the kernel and its modules. By adding -j$(nproc), you instruct the make command to use all available CPU cores, which speeds up the compilation process significantly.
Step 5: Install the Kernel¶
Once compilation is complete, install the modules and the kernel itself. On Fedora, the make install command handles copying the kernel to /boot, creating the initial ramdisk (initramfs), and updating your GRUB bootloader menu automatically.
Step 6: Reboot¶
Upon rebooting, your newly compiled kernel will be available as the default option in your GRUB menu.
2. Advanced Method: Customizing Kernel Options¶
If your goal is to reconfigure the existing kernel, enable experimental features, or strip out features to learn about kernel development, you can manually customize the kernel.
Step 1: Open the Menu Configuration¶
After downloading the source (Step 2 above), open the terminal-based menu configuration tool:
Step 2: Customize and Save¶
- Navigate using your keyboard's arrow keys.
- Press the
Spacebarto toggle features on[*], off[ ], or as a loadable module[M]. - Once finished, navigate to
<Save>, keep the filename as.config, and exit.
Step 3: Build and Install¶
Proceed with compiling and installing exactly as you did in the simplest method:
Optional Cleanup¶
If you need to manually remove your custom kernel later, you must delete its files from /boot (e.g., config-<version>, initramfs-<version>, vmlinuz-<version>, System.map-<version>) and its module directory from /lib/modules/<version>. Finally, remove the bootloader specification entries from /boot/loader/entries/ and rebuild the GRUB config by running:
Undo: remove a custom kernel¶
Boot into your Fedora kernel first, then from the kernel source folder:
KVER=$(make -s kernelrelease) # the version you built
sudo kernel-install remove "$KVER" # removes it from /boot and the GRUB menu
sudo rm -rf "/lib/modules/$KVER"
Sources¶
- Fedora Project Wiki: Building a custom kernel - https://fedoraproject.org/wiki/Building_a_custom_kernel