Difference between revisions of "Compiling a kernel"

From Linuxintro
imported>ThorstenStaerk
imported>ThorstenStaerk
Line 1: Line 1:
This is an example how to compile a Linux kernel. It has been tested for SUSE Linux 10.2 and kernel 2.6.21, but should work same or similar for every combination.
+
This is an example how to compile a Linux kernel. It has been tested for SUSE Linux 11.1 and kernel 2.6.27, but should work same or similar for every combination.
  
 
= Check prerequesites =
 
= Check prerequesites =
Line 7: Line 7:
 
= Get the code =
 
= Get the code =
 
* Download the kernel from ftp.kernel.org
 
* Download the kernel from ftp.kernel.org
  wget ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.21.tar.bz2
+
  wget ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.27.tar.bz2
 
* unpack the kernel
 
* unpack the kernel
  bunzip linux-2.6.21.tar.bz2
+
  bunzip linux-2.6.27.tar.bz2
 
* unpack the kernel for the second time
 
* unpack the kernel for the second time
  tar xvf linux-2.6.21.tar
+
  tar xvf linux-2.6.27.tar
  
 
= Build it =
 
= Build it =
 
* configure the kernel
 
* configure the kernel
  cd linux-2.6.21
+
  cd linux-2.6.27
 
  make oldconfig
 
  make oldconfig
 
* answer some un-understandable questions
 
* answer some un-understandable questions
 
The sense of the step ''make oldconfig'' is to tell the kernel its configuration, e.g. which parts should be built as a module, which parts should not be built at all and the name of your special build. oldconfig takes over the settings from the running kernel that you can check with <tt>zcat /proc/config.gz</tt>. The settings for the new kernel are stored in the file ''.config''. E.g. a line <tt>CONFIG_LOCALVERSION="-thorsten"</tt> in .config would tell kernel 2.6.27 to call himself 2.6.27-thorsten.
 
The sense of the step ''make oldconfig'' is to tell the kernel its configuration, e.g. which parts should be built as a module, which parts should not be built at all and the name of your special build. oldconfig takes over the settings from the running kernel that you can check with <tt>zcat /proc/config.gz</tt>. The settings for the new kernel are stored in the file ''.config''. E.g. a line <tt>CONFIG_LOCALVERSION="-thorsten"</tt> in .config would tell kernel 2.6.27 to call himself 2.6.27-thorsten.
* compile the kernel, '''note:''' on a two-CPU VMWare virtual machine with 2.4 GHz, this lasted 19m28.605s
+
* compile the kernel,
 
  make -j4
 
  make -j4
 
* compile the drivers
 
* compile the drivers
Line 28: Line 28:
 
  make modules_install
 
  make modules_install
 
* install the kernel
 
* install the kernel
  cp arch/''x86_64''/boot/bzImage /boot/vmlinuz-2.6.21
+
  cp arch/''x86''/boot/bzImage /boot/vmlinuz-2.6.27
This will install the kernel for the ''x86_64'' architecture.
+
This will install the kernel for the ''x86_32'' or ''x86_64'' architecture.
 
* prepare the initial ramdisk
 
* prepare the initial ramdisk
 
  cp System.map /boot
 
  cp System.map /boot
Line 35: Line 35:
 
This will build an initial ramdisk for all kernels contained in /boot.
 
This will build an initial ramdisk for all kernels contained in /boot.
 
* add an entry to the bootloader. Let's take grub's /boot/grub/menu.lst:
 
* add an entry to the bootloader. Let's take grub's /boot/grub/menu.lst:
  title 2.6.21-selfcompiled
+
  title 2.6.27-selfcompiled
 
     root (hd0,0)
 
     root (hd0,0)
     kernel /boot/vmlinuz-2.6.21 root=/dev/sda1
+
     kernel /boot/vmlinuz-2.6.27 root=/dev/sda1
     initrd /boot/initrd-2.6.21
+
     initrd /boot/initrd-2.6.27
  
= Newer kernels =
+
= See also =
x86_64 and x86_32 were merged into the x86 folder.
+
* [[Compiling_kernel_2.6.21]]

Revision as of 09:51, 7 February 2009

This is an example how to compile a Linux kernel. It has been tested for SUSE Linux 11.1 and kernel 2.6.27, but should work same or similar for every combination.

Check prerequesites

  • Make sure you have a compiler installed
yast -i gcc

Get the code

  • Download the kernel from ftp.kernel.org
wget ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.27.tar.bz2
  • unpack the kernel
bunzip linux-2.6.27.tar.bz2
  • unpack the kernel for the second time
tar xvf linux-2.6.27.tar

Build it

  • configure the kernel
cd linux-2.6.27
make oldconfig
  • answer some un-understandable questions

The sense of the step make oldconfig is to tell the kernel its configuration, e.g. which parts should be built as a module, which parts should not be built at all and the name of your special build. oldconfig takes over the settings from the running kernel that you can check with zcat /proc/config.gz. The settings for the new kernel are stored in the file .config. E.g. a line CONFIG_LOCALVERSION="-thorsten" in .config would tell kernel 2.6.27 to call himself 2.6.27-thorsten.

  • compile the kernel,
make -j4
  • compile the drivers
make -j4 modules

Install it

  • install the drivers
make modules_install
  • install the kernel
cp arch/x86/boot/bzImage /boot/vmlinuz-2.6.27

This will install the kernel for the x86_32 or x86_64 architecture.

  • prepare the initial ramdisk
cp System.map /boot
mkinitrd

This will build an initial ramdisk for all kernels contained in /boot.

  • add an entry to the bootloader. Let's take grub's /boot/grub/menu.lst:
title 2.6.27-selfcompiled
   root (hd0,0)
   kernel /boot/vmlinuz-2.6.27 root=/dev/sda1
   initrd /boot/initrd-2.6.27

See also