Building an Optimized Linux Kernel on Fedora 42

fastfetch screenshot
Fastfetch shows my custom 6.15.9 Kernel

Preparation: You’ll need to install some tools and dependencies required by the build process. On Fedora you’ll want to run the following:

sudo dnf install gcc make ncurses-devel bc openssl-devel elfutils-libelf-devel rpmdevtools fedpkg rpm-build
sudo dnf builddep kernel

Getting the Kernel source tarball
Head over to https://kernel.org and download your branch of choice. I’d recommend the latest Stable tarball.

wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.15.9.tar.xz

tar -xf linux-6.15.9.tar.xz

cd linux-6.15.9

Copy your current defconfig

We’ll copy the running kernel’s configuration into our source tree…

cp /boot/config-$(uname -r) .config
make oldconfig

You should see some output, ending with “configuration written to .config”.

The easiest way to set our flags is to simply export them in our current shell before proceeding to run make. I did the following for my AMD Ryzen 5800XT:

export KCFLAGS=’-march=znver3 -O3′
export KCPPFLAGS=’-march=znver3 -O3′

You can do march=native if you’re not sure exactly what to use for your specific CPU. Only do znver3 if you’ve got a Zen 3 chip!

Then build.*

make -j$(nproc)

* If you’d like, make additional makefile edits before running make. Or, make menuconfig if you’d like to browse through available options. But, be careful… It gets pretty technical! Simply by following the instructions above you’ll end up with a Kernel which is newer than what you’ve got, better optimized, and smaller. Basically, better in all ways. All without having to make any questionable changes on your own… But of course, feel free to explore the available options! Keep in mind, always keep a known-good stable kernel in your grub configuration in case you make a mistake!

Your kernel will take some time to compile. Anywhere from several minutes to a couple of hours, depending on how powerful your processor is and how many modules must be built. Higher optimization levels typically will take more time as well; the standard level is O2, we’re doing O3. Performance is generally better but the initial build will take a bit longer.

When the compilation is finished:

sudo make modules_install
sudo make install

This will install the kernel modules to /lib/modules/6.15.9/ (in this case). These are drivers and kernel features compiled as =m; they’re loadable instead of built directly into the kernel. Make install will install the compiled image to /boot. In this case /boot/vmlinuz-6.15.9.

We can verify our new image is Grub’s default by running:

sudo grubby –default-kernel

We should see /boot/vmlinuz-6.15.9”.

Reboot into your new optimized kernel!

Leave a Reply

Your email address will not be published. Required fields are marked *

© 2025 LostGeek.NET - All Rights Reserved. Powered by ClassicPress, NGINX, Debian GNU/Linux.