Custom Arch Linux Kernel Installation Guide

Author: Noah Vogt (14.04.2021)

Note: This should work on most not-crazy Arch derivatives, but this guide is specifically for a vanilla Arch install. And if you know more or less what these commands do and have a decent GNU/Linux experience, you shouldn’t actually break your system and render it unusable.

Dependencies

# pacman -S --needed base-devel xmlto kmod inetutils bc libelf git

Download Your Linux Kernel Source Code

This can be linux-libre or just the newest release from kernel.org, you have the freedom to choose whatever your heart desires. However it is recommended not to compile a version newer than the newest vanilla arch kernel. To check this, run a quick # pacman -Syu and look at the version using $ uname -r.

Before cloning a repo or downloading a tarball or similar, it is best to keep all your software source code in your $XDG_DATA_HOME/src. When you don’t have any XDG directorys set up, this would default to ~/.local/src. For further reading, please refer to the XDG Base Directory Specification.

$ cd .local/src

For this guide we will clone the git repository from kernel.org containing the stable releases.

$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
$ cd linux-stable

Now change to your wanted release using

$ git checkout VERSION

For example, the version I used when creating the guide was v5.11.13. The naimg scheme is very consistent, so this can be easely adapted to your version.

Compiling

$ make mrproper

Your kernel ‘settings’ of your running vanilla kernel are located in /proc/config.gz. You can optionally copy these over to your custom kernel source using the following steps.

$ zcat /proc/config.gz > .config

You may now change some settings in your .config file.

$ make olddefconfig

The output of this should look something like this:

HOSTCC  scripts/basic/fixdep
HOSTCC  scripts/kconfig/conf.o
HOSTCC  scripts/kconfig/confdata.o
HOSTCC  scripts/kconfig/expr.o
LEX     scripts/kconfig/lexer.lex.c
YACC    scripts/kconfig/parser.tab.[ch]
HOSTCC  scripts/kconfig/lexer.lex.o
HOSTCC  scripts/kconfig/parser.tab.o
HOSTCC  scripts/kconfig/preprocess.o
HOSTCC  scripts/kconfig/symbol.o
HOSTCC  scripts/kconfig/util.o
HOSTLD  scripts/kconfig/conf
#
# configuration written to .config
#

With the following command it tries to setup your kernel so, that it only contains support for you currently connectes I/O devices etc. As this would make your kernel a lot more minimal, I don’t recommend this. When you for example forget to connect a usb drive, your kernel won’t support that. So please use this command only when you are sure about it.

$ make localmodconfig

For customizing every kernel feature in a ncurses menue, use the following command. This is what I recommend: With this bloated default arch kernel, patch out everything you surely don’t need. This is much safer, efficient and you learn a little more about linux kernels.

$ make menuconfig

Now you can finally compile your base kernel. For this, you need to specify how much CPU threads you want to use. I recommend using all available threads. To check how many threads you CPU has, run:

$ cat /proc/cpuinfo | grep siblings

So in this example I will compile using 8 threads. (Only run the second command when you use modules)

# make -j8 && make modules_install

When everything compiled without errors, move the bzImage into your boot partition. Based on where that directory is located on your install and what architecture you are using, you may have to correct to following command accordingly.

# cp -v arch/x86_64/boot/bzImage /boot/vmlinuz-linuxVERSION

Create the INITRAMFS Image

When you compiled in INITRAMFS Support, create a initramfs image:

# mkinitcpio -k VERSION -g /boot/initramfs-linuxVERSION.img

Copy over the System.map file.

# cp System.map /boot/System.map-linuxVERSION
# cp /boot/System.map-linuxVERSION System.map

Update the Boot Loader

This is the final step. We will use grub for this guide here.

# grub-mkconfig -o /boot/grub/grub.cfg

Now your custom linux kernel should have appeared on the grub output. Now reboot and hope everything works as intended.