[How To] Compile a custom Manjaro kernel

Bookmark on compiling a custom Manjaro kernel

Once upon a time a topic existed on building a custom Manjaro kernel.

Then a request was made to revive that topic.

What is this

This is the foundation for building a custom Manjaro kernel which can be installed side by side official Manjaro kernels.

You can change the kernel configuration to your liking and it should never conflict with the official kernel builds.

If you are using Nvidia - it is recommended to install Nvidia drivers by means of the official Nvidia dkms packages.

How did it come to be

So what I do is very much the trial and error approach.

I also use variables to eliminate the human error factor.

Version Timestamp
Revision 10 2026-01-23T07:40:00Z
12 2026-01-23T10:17:00Z
13 2026-01-23T10:35:00Z

This script is valid as of 2026-01-22T23:00:00Z - anyone reading this months or years from now - please validate - make no assumptions about the state of the Manjaro kernel buildscripts.

What is the usecase

Anyone who want to tweak the kernel - adding or removing patches - keeping a specific kernel release because it provides the best kernel for your specific system.

By copying /etc/makepkg.conf to ~/.makepkg.conf you can apply system specific compile options, like znver= or native which may improve kernel response times.

The script is a one-time compile script, it will clear the previous build, so if you have a specific patch set you want to apply you would probably store your tweaks separately - to avoid redoing them every time.
:slight_smile:

Script (to be improved if necessary)

#!/usr/bin/env bash

####---- version 13 ----####
# date=2026-01-23 time=11:35:00 timezone="Europe/Copenhagen"

# define custom kernel identifier
custom="custom"

# define custom build host
host="$(hostnamectl hostname)"

# define custom build user
user=$USER

# define builddir - default to user's home
# if you change - remember to create the path beforehand
builddir=$HOME

# define manjaro kernel name to work with
manjaro_kernel=linux618

# define the kernel configuration path
kernel_config=${builddir}/${manjaro_kernel}/config

# define the pkgbuild path
pkgrecipe=${builddir}/${manjaro_kernel}/PKGBUILD

# cd into builddir
cd ${builddir}

# remove ${manjaro_kernel} dir if it exist
[[ -d ${builddir}/${manjaro_kernel} ]] && rm -rf ${builddir}/${manjaro_kernel}

# clone Manjaro package build recipe
git clone https://gitlab.manjaro.org/packages/core/${manjaro_kernel}.git ${builddir}/${manjaro_kernel}

# change working folder
cd ${builddir}/${manjaro_kernel}

# --------------------------
# modify build recipe
# add '-${custom}' to kernel name
sed -i 's|^_kernelname=.*|_kernelname=\"-'${custom}'\"|g' ${pkgrecipe}

# add '-${custom}' to package base name
sed -i 's|^pkgbase=.*|pkgbase="linux\${_basever}-'${custom}'\"|g' ${pkgrecipe}

# add '-${custom}' to the base kernel name
sed -i 's|\"\${_basekernel}-\${CARCH}\"|\"\${_basekernel}-'${custom}'-\${CARCH}\"|g' ${pkgrecipe}

# --------------------------
# modify kernel config
# set KBUILD_BUILD_HOST to ${host}
sed -i 's|^export KBUILD_BUILD_HOST=.*|export KBUILD_BUILD_HOST=\"'${host}'\"|g' ${pkgrecipe}

# set KBUILD_BUILD_USER to ${user}
sed -i 's|^export KBUILD_BUILD_USER=.*|export KBUILD_BUILD_USER=\"'${user}'\"|g' ${pkgrecipe}

# set kernel config CONFIG_LOCALVERSION to '${custom}'
sed -i 's|^CONFIG_LOCALVERSION=.*|CONFIG_LOCALVERSION=\"-'${custom}'\"|g' ${kernel_config}

# set kernel config CONFIG_DEFAULT_HOSTNAME to ${host}
sed -i 's|^CONFIG_DEFAULT_HOSTNAME=.*|CONFIG_DEFAULT_HOSTNAME=\"'${host}'\"|g' ${kernel_config}

# update pkgsums
updpkgsums

# run makepkg with install and cleanup
PKGDEST=${builddir}/${manjaro_kernel} makepkg -sicC

Remember

If you are using a custom kernel - be sure to mention this when/if you are having issues with your system.

7 Likes

Thanks. I successfully ran the above script, resulting in: Finished making: linux618-custom 6.18.22-1 (za 18 apr 2026 15:22:11 CEST). But it is not visible in Manjaro Settings Manager or mhwd-kernel -l

$ mhwd-kernel -li                                                                                                                            
Currently running: 6.12.77-1-MANJARO (linux612)
The following kernels are installed in your system:
   * linux612

How can I install linux618-custom when it is not listed? What should I do next?

The tools only list kernels from the official repo - not your custom build kernels.

In the work folder - locate the package name

ls *.pkg.tar.zst

Then run

sudo pacman -U linux618-custom-6.18.22-1-x86_64.pkg.tar.zst linux618-custom-headers-6.18.22-1-x86_64.pkg.tar.zst
1 Like

Yes, thank you! After this and a reboot am now running it:

mhwd-kernel -li                                                                                                                            ✔ 
Currently running: 6.18.22-1-custom (linux618)
The following kernels are installed in your system:
   * linux612
1 Like