Skip to content

Compile Linux Kernel

how to create your own customized kernel

Build your kernel can have many advantages, first you will have control over what is built into your kernel, in contrast of the default kernel that comes with your distribution that contain a lot of stuff, that you actually don't need, like extra filesystems, support for hardwares you don't have ..., so if you did it correctly and build your kernel, you will have smaller, faster kernel. you can also follow if you just want to upgrade to the latest version.

Preparation

install required build tools

doas pacman -S base-devel xmlto kmod inetutils bc libelf git cpio perl tar xz

get latest kernel

wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.6.9.tar.xz

decompress it

tar -xvf linux-5.6.9.tar.xz

cd to it

cd linux-5.6.9

clean the dir

make distclean

Configuration

first you need to configure it. to use your default conf in your system:

zcat /proc/config.gz > .config

then check the conf and enable only features you will need:

make LLVM=1 menuconfig

Build

now we need to compile our kernel

make LLVM=1 -j$(nproc)

Installation

intall modules first

doas make modules_install -j$(nproc)

then the kernel itself

doas cp -v arch/x86_64/boot/bzImage /boot/vmlinuz-linux
doas cp -v System.map /boot/System-linux.map

generate initramfs

cp /etc/mkinitcpio.d/linux.preset /etc/mkinitcpio.d/linux99.preset

amend the file according to your needs. then generate the initramfs

mkinitcpio -p linux99

GRUB

finally we need to regenerates grub config

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