Alternatively, you can use ABS to build and install your kernel; see: [[Kernel Compilation]]. Using the existing {{Pkg|linux}} PKGBUILD will automate most of the process and will result in a package. However, some Arch users prefer the {{ic|traditional}} way.

Alternatively, you can use ABS to build and install your kernel; see: [[Kernel Compilation]]. Using the existing {{Pkg|linux}} PKGBUILD will automate most of the process and will result in a package. However, some Arch users prefer the {{ic|traditional}} way.

−

New users who are not fully familiar with compiling a kernel should have a look at [[Kernel Compilation without ABS for New Users]].

+

New users who are not fully familiar with compiling software should have a look at [[Kernel Compilation without ABS for New Users]].

== Fetching source ==

== Fetching source ==

Revision as of 08:20, 19 December 2011

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

The summary below is helpful for building custom kernels from kernel.org sources. This method of compiling kernels is the traditional method common to all distros; however, an excellent method of cleanly installing the custom kernel with makepkg and pacman is also included.

Alternatively, you can use ABS to build and install your kernel; see: Kernel Compilation. Using the existing linux PKGBUILD will automate most of the process and will result in a package. However, some Arch users prefer the traditional way.

Fetching source

Fetch the kernel source from ftp.xx.kernel.org/pub/linux/kernel/, where xx is your country key (f.e. 'us', 'uk', 'de', ... - Check [1] for a complete list of mirrors). If you have no ftp gui, you can use wget. For this example, we will fetch and compile 2.6.32.8; you should need to change only the version to get a different kernel.

Note: Since kernel.org security was compromised over the summer of 2011, the old public key 0x517D0F0E is considered obsolete. Newer kernel tarballs (>3.0) are currently being signed with key: 00411886.

This ensures that the kernel tree is absolutely clean. The kernel team recommends that this command be issued prior to each kernel compilation. Do not rely on the source tree being clean after un-tarring.

Build configuration

(Optional) Copy the .config file from the running kernel, if you want to modify default Arch settings.

$ zcat /proc/config.gz > .config

Configure your kernel.

The Traditional Way:

$ make menuconfig (Will start with a fresh '.config'. Option dependencies are usually automatically selected.)

Other build targets (Since kernel 2.6.32):

$ make oldconfig (Only works with the old '.config' file, copied into the build directory. Also marks previously unused options as 'NEW'.)
$ make localmodconfig (Tries to extract /proc/config.gz from running kernel. Pre-selecting options/modules in use.)
$ make localyesconfig (Same as above, except that as many modules as possible compiled into the kernel.)
$ make xconfig (Depends on Qt. A nicer interface. Dependency checking not verified.)
$ make gconfig (Depends on GTK. Otherwise same as xconfig.)
$ make help (Lists ALL targets available.)

Note: for more information about the build target "localmodconfig" refer to the 2.6.32 release notes.

Make your changes to the kernel and save your config file. It is a good idea to make a backup copy, since you will likely be doing this multiple times until you get all the options right.

If you are compiling a kernel using your current config file, do not forget to rename your kernel version, or you may replace your existing one by mistake.

$ make menuconfig
General setup --->
(-ARCH) Local version - append to kernel release '3.n.n-RCn'

What about /usr/src/ ?

Using the /usr/src/ directory for kernel compilation as root, along with the creation of the corresponding symlink, is considered poor practice by some kernel hackers. They consider the cleanest method to simply use your home directory. If you subscribe to this point of view, build and configure your kernel as normal user, and install as root, or with makepkg and pacman (covered below).

However, this concept has been the target of debate, and other very experienced hackers consider the practice of compiling as root under /usr/src/ to be completely safe, acceptable and even preferable.

Use whichever method you feel more comfortable with.

Compilation and installation

Choose one of the following:

1. Manual, Traditional method

Warning: Do not run make all if you use GRUB and still have LILO installed; it will configure LILO in the end, and you may no longer be able to boot your machine! Remove LILO (pacman -R lilo) before running make all if you use GRUB!

Compile it:

$ make

(Same as make vmlinux && make modules && make bzImage - see make help for more information on this.)

If you have a multi-core computer (i.e Dual Core, Quad Core, etc), you can compile the kernel faster by adding the -j flag. This will use all processors at 100%

$ make -j[# of processors + 1]

Note: It is recommended to put one more than how many processors you have. For example: on a dual core machine you could compile the kernel with make -j3. A Dual-core 2.8Ghz compiled in only 10-15 minutes.

Install modules: (This needs to be done as root.)

# make modules_install

This copies the compiled modules into a directory in /lib/modules named by the kernel version and appended string you set in menuconfig. This way, modules are kept separate from those used by other kernels on your machine.

Copy kernel:

# cp -v arch/x86/boot/bzImage /boot/vmlinuz-YourKernelName

If you need any modules loaded in order to mount the root filesystem, build a ramdisk (most users need this). The -k parameter accepts the kernel version and appended string you set in menuconfig and is used to locate the modules in /lib/modules:

# mkinitcpio -k FullKernelName -g /boot/initramfs-YourKernelName.img

You are free to name the /boot files anything you want. However, using the [kernel-major-minor-revision] naming scheme helps to keep order if you: Keep multiple kernels/ Use mkinitcpio often/ Build third-party modules.

If you are using LILO and it cannot communicate with the kernel device-mapper driver, you have to run modprobe dm-mod first.

2. With makepkg and pacman (Recommended)

Bootloader configuration

Add an entry for your amazing new kernel in your bootloader's configuration file - see GRUB or LILO for examples. Note that if you use LILO, the kernel sources include a script to automate the process:

$ arch/i386/boot/install.sh

If you use LILO, remember to type lilo as root at the prompt to update it.