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 |
| Revision | 12 | 2026-01-23T10:17:00Z |
| Revision | 13 | 2026-01-23T10:35:00Z |
| Revision | 14 | 2026-10-02T07:30:00Z |
This script is valid as of 2026-10-02T07:30:00Z - anyone reading this months or years from now - please validate - make no assumptions about the state of the Manjaro kernel buildscripts.
Huge thank you to @Yochanan for hinting how to refactor the git clone procedure.
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.
![]()
Remember
If you are using a custom kernel - be sure to mention this when/if you are having issues with your system.
Also see: [HowTo] Build your very first custom kernel
Script (to be improved if necessary)
#!/usr/bin/env bash
####---- version 14 ----####
# [date=2026-10-02 time=09:30:00 timezone="Europe/Copenhagen"]
# define manjaro kernel name to work with
if [[ -z $1 ]]; then
echo "FAILURE: Kernel must be supplied e.g. 'linux72'."
exit 1
else
if mhwd-kernel -l | awk '
# Skip header lines
/available kernels:/ { next }
# Process only lines containing the required marker pattern (*),
# which are the actual kernel listings.
/\*/ {
line = $0;
# Remove leading whitespace and bullet points (e.g., " * ")
gsub(/^[[:space:]]*\*[[:space:]]*/, "", line);
print line;
}
' | grep -q "^${1}$"; then
manjaro_kernel="$1"
else
echo "FAILURE: Kernel '$1' is not available."
exit 1
fi
fi
# define builddir - default to user's home
# if you change - remember to create the path beforehand
builddir=$HOME
# define custom kernel identifier
custom="-custom"
# define custom build host
host="$(hostnamectl hostname)"
# define custom build user
user=$USER
# define the kernel configuration path
kernel_config=${builddir}/${manjaro_kernel}/core/${manjaro_kernel}/config
# define the pkgbuild path
pkgrecipe=${builddir}/${manjaro_kernel}/core/${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 -n --depth=1 --filter=tree:0 https://code.manjaro.org/packages/PKGBUILDs.git ${builddir}/${manjaro_kernel}
cd ${builddir}/${manjaro_kernel}
git sparse-checkout set --no-cone core/${manjaro_kernel}
git checkout
# change working folder
cd ${builddir}/${manjaro_kernel}/core/${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