Difference between revisions of "Kernels/Arch Build System"

From ArchWiki
Jump to: navigation, search
(useless note, already linked)
Line 10: Line 10:
{{bc|1=$ ABSROOT=. abs core/linux}}
{{bc|1=$ ABSROOT=. abs core/linux}}
{{Note|See [[Arch Build System]] for more information.}}
Then, get any other file you need (e.g. custom configuration files, patches, etc.) from the respective sources.
Then, get any other file you need (e.g. custom configuration files, patches, etc.) from the respective sources.

Revision as of 16:50, 10 January 2012

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

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.

Getting the Ingredients

# pacman -S abs base-devel

First of all, you need a clean kernel to start your customization from. Fetch the kernel package files from ABS:

$ ABSROOT=. abs core/linux

Then, get any other file you need (e.g. custom configuration files, patches, etc.) from the respective sources.

Modifying the PKGBUILD

Modify the PKGBUILD of the official linux package.

Changing pkgname

The first lines will look like this:

# $Id: PKGBUILD 130991 2011-07-09 12:23:51Z thomas $
# Maintainer: Tobias Powalowski <tpowa@archlinux.org>
# Maintainer: Thomas Baechler <thomas@archlinux.org>

pkgname=('linux' 'linux-headers' 'linux-docs') # Build stock -ARCH kernel
# pkgname=linux-custom       # Build kernel with a different name

As you see, there is a commented line for building a kernel with a different name. All you need to do here is to uncomment that line, change the suffix '-custom' to your needs, and comment the standard line. And if you want two kernels (ARCH and test) you need disable section conflicts. Files linux.install and linux.preset must be linux-custom.install and linux-custom.preset. For instance, your file could become:

#pkgname=('linux' 'linux-headers' 'linux-docs') # Build stock -ARCH kernel
pkgname=linux-test       # Build kernel with a different name
#next lines give you problems with nvidia drivers which depend on kernel
Note: This assumes that you do not need to recompile linux-headers, -manpages or -docs. If you do, change all three strings accordingly.

Now, all the variables of your package will be changed according to the new name. For instance, after installing the package the modules will be located at /lib/modules/<kernel_release>-test/.

Changing build()

You probably need a custom .config file for your kernel. You can uncomment one of the possibilities shown in the build() function of the PKGBUILD, e.g.:

  # 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, I suggest to uncomment one interactive config tool, such as nconfig, and load your config from there. This avoids problems with kernel naming I have met with other methods.

Note: If you uncomment return 1, you can change to the kernel source directory after makepkg finishes extraction and then make nconfig. This lets you configure the kernel over multiple sessions. When you're ready to compile, copy the .config file over top of either config or config.x86_64 (depending on your architecture), comment return 1 and use makepkg -i. But not use this for custom patch, put you patch commands after these lines. If you do patch manually bztar unpack and replace your patch.

Changing the package_linux() function

Now, you have to write a custom function to tell your system how to install the package. This is most easily done by changing the name of the package_linux() function to package_linux-test(), and adapting the instructions to your needs. If you have no particular needs, your package_linux-test() should look like this:

package_linux-test() {
 pkgdesc="The Linux Kernel and modules"


Tip: Running compilation jobs simultaneously can reduce compilation time significantly on multi-core systems.

You can now proceed to compile you kernel by the usual command makepkg If you have chosen an inteactive program for configuring the kernel parameters (like menuconfig), you need to be there during the compilation.

Note: A kernel needs some time to be compiled. 1h is not unusual.


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_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 (/boot/grub/menu.lst 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 in parallel.