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

Script (to be improved if necessary)

The script is only needed for first time setup

#!/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 kernel name
sed -i 's|\"\${_basekernel}-\${CARCH}\"|\"\${_basekernel}-'${custom}'-\${CARCH}\"|g' ${pkgrecipe}

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

# set KBUILD_BUILD_USER to current 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 current hostname
sed -i 's|^CONFIG_DEFAULT_HOSTNAME=.*|CONFIG_DEFAULT_HOSTNAME=\"'${host}'\"|g' ${kernel_config}

# update pkgsums
updpkgsums

# run makepkg
PKGDEST=${builddir}/${manjaro_kernel} makepkg -s

Remember

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

6 Likes