Compiling a custom Linux kernel on Manjaro

Image for post
Image for post

Compiling a custom kernel on Manjaro is very simple once you know how to do it and if you just need to change a few configurations then this quick guide is for you!

As such I researched how to do this and I quickly had to face the very unpleasant web of forum posts and passive aggressive “use the search function” dead ends that most threads on the subject end with on the Manjaro Forum. As such I will be saving you the trouble of finding the correct post buried in a thread somewhere and this will be a quick tutorial on how to recompile your kernel quickly and easily.

For the purpose of fixing slow boot times with my 3D accelerated Windows 10 libvirt Virtual machine running on a Manjaro host, it was necessary for me to compile a kernel with a few options that differ from the default kernel. We will use these changes as an example for this guide. Also if you are interested in gaming on a Windows VM on linux, then check my other guide here.

The steps are as follow:

  1. Get the kernel source from the Manjaro gitlab core repository
# Example for linux 5.6
https://gitlab.manjaro.org/packages/core/linux56

2. Clone the repository

3. Modify the configuration to suit your needs. In my case I had to remove CONFIG_PREEMPT and enable CONFIG_PREEMPT_VOLUNTARY. These configuration are located in the file starting with “config” and ending with your target architecture. In my case I run an x86_64 machine just like yours probably does, so my config file is “config.x86_64”

Note: From version 5.7 and onward there is only a single config file for all architectures and it’s named “config”.

# Locate CONFIG_PREEMPT=y and comment it out
# Add the config CONFIG_PREEMPT_VOLUNTARY=7
Before:...# CONFIG_PREEMPT_NONE is not set
# CONFIG_PREEMPT_VOLUNTARY is not set
CONFIG_PREEMPT=y
CONFIG_PREEMPT_COUNT=y CONFIG_PREEMPTION=y
...After:...# CONFIG_PREEMPT_NONE is not set
CONFIG_PREEMPT_VOLUNTARY=y
# CONFIG_PREEMPT is not set
CONFIG_PREEMPT_COUNT=y CONFIG_PREEMPTION=y
...

4. Update the configuration file checksum as the build tools will check the checksums of every file in the repository before compilation.

5. Compile your kernel. This may take from 15 to 60+ minutes depending on how powerful is your machine

# You may be prompted to confirm your configuration changes. Just follow the instructions

6. Install your newly compiled kernel

Now you may want to add a backup kernel to your grub configuration before rebooting but its up to you!

Now reboot and confirm that your kernel is correctly configured by running the following command:

# In my case I can grep the result with my changes
$ cat /lib/modules/$(uname -r)/build/.config | grep PREEMPT
# CONFIG_PREEMPT_NONE is not set
CONFIG_PREEMPT_VOLUNTARY=y
# CONFIG_PREEMPT is not set
CONFIG_PREEMPT_NOTIFIERS=y
CONFIG_DRM_I915_PREEMPT_TIMEOUT=640
# CONFIG_PREEMPTIRQ_EVENTS is not set
# CONFIG_PREEMPTIRQ_DELAY_TEST is not set
$ cat /lib/modules/$(uname -r)/build/.config | grep PREEMPT
# CONFIG_PREEMPT_NONE is not set
CONFIG_PREEMPT_VOLUNTARY=y
# CONFIG_PREEMPT is not set
CONFIG_PREEMPT_NOTIFIERS=y
CONFIG_DRM_I915_PREEMPT_TIMEOUT=640
# CONFIG_PREEMPTIRQ_EVENTS is not set
# CONFIG_PREEMPTIRQ_DELAY_TEST is not set

Voilà! You are done!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store