Arch Linux – Compile your own kernel
We are going to use the Arch Build System (pkgbase, PKGBUILD) to build a custom kernel based on the official linux package. The Arch Build System is a ports-like system for building and packaging software from source code.
- Create a folder in your home directory for your build system
cd ~/ mkdir build
- Install the abs package and the base-devel package group from the official repositories.
sudo pacman -S abs base-devel
- Fetch the kernel package (clean kernel) files from ABS into your build directory
cd ~/build ABSROOT=. abs core/linux
- Edit PKGBUILD and look for the pkgbase parameter. Change this to your custom package name so that you know it is your custom kernel
nano core/linux/PKGBUILD # Look for pkgbase= and change it to e.g. # pkgbase=linux-custom
- At this point you manually edit the .config file or you can of course use the menuconfig gui to edit the kernel’s configuration
and search for the following:
# load configuration # Configure the kernel. Replace the line below with one of your choice. #make menuconfig # CLI menu for configuration #make nconfig # new CLI menu for configuration #make xconfig # X-based configuration #make oldconfig # using old config from previous kernel version # ... or manually edit .config
and uncomment the make menuconfig for instance
- As we modified config, we need to generate new checksums
cd core/linux updpkgsums
- You can now proceed to compile your kernel by the usual command makepkg
The -s parameter will download any additional dependencies used by recent kernels such as xml and docs.
- If you chosen the menuconfig, it will show up, otherwise the kernel will compile with the given .config
- After the makepkg , you can install the kernel (package) as usual with pacman (or equivalent program):
pacman -U <kernel-headers_package> pacman -U <kernel_package>
- Now, the folders and files for your custom kernel have been created, e.g. /boot/vmlinuz-linux-<YOUR CUSTOM NAME> . To test your kernel, update your bootloader (grub-mkconfig for GRUB) . You can for instance change grub config:
sudo nano /boot/grub/grub.cfg
and find and change the lines
linux /boot/vmlinuz-linux [...] initrd /boot/initramfs-linux.img # change to linux /boot/vmlinuz-<YOUR CUSTOM NAME> initrd /boot/initramfs-linux-<YOUR CUSTOM NAME>.img
- Your done! Reboot and enjoy your custom kernel!