Kernels/Compilation/Arch Build System
The Arch Build System can be used to build a custom kernel based on the official linux package. This compilation method can automate the entire process, and is based on a very well tested package. You can edit the PKGBUILD to use a custom kernel configuration or add additional patches.
Contents
Getting the Ingredients
Since you'll be using makepkg, follow the best practices outlined there first. For example, you cannot run makepkg as root/sudo. Therefore, create a build
directory in your user home first.
$ cd ~/ $ mkdir build $ cd build/
Install the abs package and the base-devel package group from the official repositories.
You need a clean kernel to start your customization from. Fetch the kernel package files from ABS into your build directory by running:
$ ABSROOT=. abs core/linux
If you have some problem with the firewall blocking the rsync port, you can try with -t, which uses the tarball to sync.
$ ABSROOT=. abs core/linux -t
Then, get any other file you need (e.g. custom configuration files, patches, etc.) from the respective sources.
Modifying the PKGBUILD
Edit PKGBUILD
and look for the pkgbase
parameter. Change this to your custom package name, e.g.:
pkgbase=linux-custom
Changing build()
If you need to change a few config options you can use the default one and append your options to the config file:
$ echo ' CONFIG_DEBUG_INFO=y CONFIG_FOO=n ' >> config.x86_64
Or you can use GUI tool to tweak the options. Uncomment one of the possibilities shown in the prepare() function of the PKGBUILD, e.g.:
PKGBUILD
... # 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 ...
If you have already a kernel .config
file, uncommenting one of the interactive config tools, such as nconfig
, and loading your .config
from there avoids any problems with kernel naming that may otherwise occur - except in the case of at least make menuconfig. See note.
Generate new checksums
As we modified config, we need to generate new checksums by running:
$ updpkgsums
Compiling
You can now proceed to compile your kernel by the usual command
makepkg
If you have chosen an interactive program for configuring the kernel
parameters (like menuconfig), you need to be there during the
compilation.
$ makepkg -s
The -s
parameter will download any additional dependencies used by recent kernels such as xml and docs.
Installing
After the makepkg, you can have a look at the linux.install file. You will see that some variables have changed. Now, you only have to install the package as usual with pacman (or equivalent program):
# pacman -U <kernel-headers_package> # pacman -U <kernel_package>
Boot Loader
Now, the folders and files for your custom kernel have been created, e.g. /boot/vmlinuz-linux-test
. To test your kernel, update your bootloader (grub-mkconfig for GRUB) and add new entries ('default' and 'fallback') for your custom kernel. That way, you can have both the stock kernel and the custom one to choose from.