Difference between revisions of "Kernel Compilation"

From ArchWiki
Jump to: navigation, search
m (cleanup of old info (the page that's linked to is up to date, going to merge it in here anyway - see Requests))
m (merged in ABS kernel compilation (which is the recommended method))
Line 7: Line 7:
 
==Using the [[Arch Build System]]==
 
==Using the [[Arch Build System]]==
  
* [[Kernel Compilation with ABS]]
+
For quite some time, various methods have been proposed to easily build a custom kernel from the -ARCH one. Search the Wiki for a few examples. All these were intelligent ideas, but suffered from [[http://bugs.archlinux.org/task/12384 some drawbacks]] and were not officially supported by the devs.
 +
 
 +
On the contrary, the method described in this article should be more solid and safe, and builds on the kernel26 official package. Therefore, quick reactions are expected from forum users and the devs.
 +
 
 +
== Getting the Ingredients ==
 +
First of all, you need a clean kernel to start your customization from. In this article I will assume that you use the official kernel26 -ARCH kernel. So create a folder you want to work in and get the kernel package files from ABS (after syncing):
 +
 
 +
{{Codeline|cp /var/abs/core/kernel26/* <working_dir>/}}
 +
 
 +
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 kernel26 package.
 +
 
 +
====Changing pkgname====
 +
The first lines will look like this:
 +
{{File|name=PKGBUILD|content=
 +
# $Id: PKGBUILD 88213 2010-08-21 07:36:11Z tpowa $
 +
# Maintainer: Tobias Powalowski <tpowa@archlinux.org>
 +
# Maintainer: Thomas Baechler <thomas@archlinux.org>
 +
pkgbase="kernel26"
 +
pkgname=('kernel26' 'kernel26-headers' 'kernel26-manpages' 'kernel26-docs') # Build stock -ARCH kernel
 +
# pkgname=kernel26-custom      # Build kernel with a different name
 +
_kernelname=${pkgname#kernel26}
 +
...
 +
}}
 +
 
 +
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. For instance, your file could become:
 +
{{File|name=PKGBUILD build()|content=
 +
...
 +
# pkgname=('kernel26' 'kernel26-headers' 'kernel26-manpages' 'kernel26-docs') # Build stock -ARCH kernel
 +
pkgname=kernel26-test      # Build kernel with a different name
 +
...
 +
}}
 +
 
 +
{{Note|This assumes that you do not need to recompile kernel26-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 {{Filename|/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.:
 +
{{File|name=PKGBUILD|content=
 +
...
 +
# 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.
 +
 
 +
====Changing the package_kernel26() 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_kernel26() function to package_kernel26-test(), and adapting the instructions to your needs. If you have no particular needs, your package_kernel26-test() should look like this:
 +
{{File|name=PKGBUILD package_kernel26-test()|content=
 +
...
 +
package_kernel26-fabio() {
 +
pkgdesc="The Linux Kernel and modules"
 +
...
 +
}
 +
}}
 +
 
 +
===Compiling===
 +
Now you can proceed to compile you kernel by the usual command
 +
{{Codeline|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.}}
 +
 
 +
===Installing===
 +
After the makepkg, you can have a look at the kernel26.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):
 +
{{Codeline|#pacman -U <kernel_package>}}
 +
 
 +
===Boot Loader===
 +
Now, the folders and files for your custom kernel have been created, e.g. /boot/kernel26-test-img . 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.
 +
 
 +
===Nvidia proprietary driver===
 +
See: [[NVIDIA#Alternate_install: custom kernel]].
  
 
==Using the [[AUR]]==
 
==Using the [[AUR]]==

Revision as of 02:57, 23 November 2010

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 – فارسی

Arch Linux provides for several methods of kernel compilation.

Using the Arch Build System

For quite some time, various methods have been proposed to easily build a custom kernel from the -ARCH one. Search the Wiki for a few examples. All these were intelligent ideas, but suffered from [some drawbacks] and were not officially supported by the devs.

On the contrary, the method described in this article should be more solid and safe, and builds on the kernel26 official package. Therefore, quick reactions are expected from forum users and the devs.

Getting the Ingredients

First of all, you need a clean kernel to start your customization from. In this article I will assume that you use the official kernel26 -ARCH kernel. So create a folder you want to work in and get the kernel package files from ABS (after syncing):

Template:Codeline

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 kernel26 package.

Changing pkgname

The first lines will look like this: Template:File

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. For instance, your file could become: Template:File

Note: This assumes that you do not need to recompile kernel26-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 Template:Filename.

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.: Template:File

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.

Changing the package_kernel26() 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_kernel26() function to package_kernel26-test(), and adapting the instructions to your needs. If you have no particular needs, your package_kernel26-test() should look like this: Template:File

Compiling

Now you can proceed to compile you kernel by the usual command Template:Codeline 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.

Installing

After the makepkg, you can have a look at the kernel26.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): Template:Codeline

Boot Loader

Now, the folders and files for your custom kernel have been created, e.g. /boot/kernel26-test-img . 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.

Nvidia proprietary driver

See: NVIDIA#Alternate_install: custom kernel.

Using the AUR

There are in the AUR some packages for famous kernel flavors, like TuxOnIce, Zen, Con Kolivas patchset etc.

You can install them 'as is', or use them as a basis for your custom kernel instead of the official -ARCH one.

Traditional

The traditional way is simple and straightforward.

This method involves manually downloading a source tarball, and building in your home directory as normal user. Once configured, two compilation/installation methods are offered; the traditional manual method as well as makepkg/pacman.

If you are new to the process, the traditional way for new users may be appropriate.

Links