Compiling a custom Linux kernel on Manjaro

Leduccc
3 min readJul 9, 2020

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
https://gitlab.manjaro.org/packages/core# Example for linux 5.10
https://gitlab.manjaro.org/packages/core/linux510

2. Clone the repository

$ git clone https://gitlab.manjaro.org/packages/core/linux510
$ cd linux510

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”.

# Linux >= 5.7
$ nano config
# Linux <= 5.6
$ nano config.x86_64
# 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.

$ updpkgsums
==> Retrieving sources...
-> Found linux-5.6.tar.xz
-> Found patch-5.6.19.xz
-> Found config.x86_64
-> Found config
[...]
==> Generating checksums for source files...

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

$ makepkg -s# You may be prompted to confirm your configuration changes. Just follow the instructions

6. Install your newly compiled kernel

$ makepkg -i

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:

$ cat /lib/modules/$(uname -r)/build/.config# 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!

Update: 29/10/2021

--

--

Leduccc

I'm writing simple and accessible tutorials for all the aspiring computer scientists out there!