Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2002
    Location
    UK
    Posts
    846

    Kernel Compilation Guide - Linux x86

    Ok, I guess i'll write a series of tutorials as i've been the one pining for this forum for a long time.

    Lets begin, basic compilation of the kernel

    Step 1 - Get your kernel
    Depending on your distribution, there are different ways to obtain your kernels:
    • Redhat/Fedora - Supplied by the manufacturer, also available via rpmfind.net
    • Debian - Provided in .deb format, either apt-cache search for it or check out the online repository
    • Gentoo - Under the sys-kernel tree of portage (/usr/portage/sys-kernel/gentoo-sources is the more common ebuild)
    • Any Linux admin can get kernel tarballs from http://www.kernel.org but they're plain vanilla, no optimisations for any distribution etc
    • FreeBSD - Will be covered in a seperate tutorial


    Step 2 - Unpack it
    Ok, a handy lesson in the tar command to go along with this, for this example our kernel is called linux-2.4.24.tar.bz2. We can see this is a bzipped image so we use the following command to untar and unzip it:
    tar xvjfp linux-2.4.24.tar.bz2
    Here is a breakdown of this command:
    • x - extract files from archive
      v - be verbose about files (list every file extracted)
      j - parse the file through the bzip2 decompressor
      f - simply means, use the file supplied on the command line
      p - preserve permissions (instead of creating files in reference to the umask.. If you are running as root this behaviour is default anyway)


    You should run this command inside /usr/src/ .. This is the most common directory for source code compilation, you may need to provide a full path if the file is not present in that directory. You should end up with a directory labelled after the kernel, for example, /usr/src/linux-2.4.24/.

    Step 3 - Symlink directory
    You will need to link your current kernel source tree (which we just extracted) to /usr/src/linux .. this is to avoid clumsy searching and pointless configuration, the appropriate command is ln -sf /usr/src/<kernel directory> /usr/src/linux .. Absolute paths can be substituted depending on your preference. The s option indicates this link is symbolic only, the f option overwrites any old existing link.

    Step 4 - Begin configuration
    Assuming you have ncurses installed (which you should have regardless, hell it's a system utility on Gentoo), we will use the menuconfig setup (X users, substitute 'xconfig' wherever 'menuconfig' is mentioned, non-ncurses users use 'config')

    First, change to the source tree's directory: cd /usr/src/linux
    Second, start the menu configuration program: make menuconfig

    Several compilations should occur then a nice menu should pop up with all your kernel options, these options will be discussed at a later date, for now we'll assume you know how to configure your kernel

    Step 5 - Compilation
    Once you have finished your configuration, exit and save your configuration file.

    You will now need to run two commands, the first is make dep - this will make all the basic dependancies needed for the kernel. Please note, this is not required for 2.6 kernels

    Once make dep has finished, you will need to build the rest of the kernel

    2.4 kernels:
    make bzImage modules modules_install - This will compile the kernel image (bzImage), the modules and also install the modules into /lib/modules/<kernel-version>/
    2.6 kernels:
    make && make modules_install - Does the same as listed before, just using the new modifications to the makefile

    Step 6 - Install your kernel
    This step is only generalised as it's impossible to predict how you want your kernel to be configured, plus how you have your bootloader setup, so here is how I do it.

    Copy the kernel image into /boot, labelled appropriately: cp arch/i386/boot/bzImage /boot/kernel-2.4.24
    Copy the System.map file into /boot, again labelled with the kernel version: cp System.map /boot/System.map-2.4.24
    Copy the config you have used to /boot: cp .config /boot/config-2.4.24

    This ensures you have enough information at any time to find the kernel version used and all configuration options, even if you have disabled /proc/config support and/or the kernel isn't running.

    You should be able to reboot your system (after reconfiguring your bootloader) and boot quite happily into your new kernel

    Not covered by this tutorial:
    • FreeBSD Kernels
    • Linux kernel configuration
    • initrd usage
    • vmlinux usage
    • bootloader configuration


    I will attempt to touch on these in the future.

  2. #2
    Join Date
    Aug 2002
    Location
    UK
    Posts
    846
    Please move this to T+SI, it was intended for there.

  3. #3
    Join Date
    Apr 2002
    Location
    Southampton, UK
    Posts
    1,023
    Several compilations should occur then a nice menu should pop up with all your kernel options, these options will be discussed at a later date, for now we'll assume you know how to configure your kernel
    Somebody who knows how to configure a kernel in the first place surely doesn't need to know how to unpack/compile it?
    Regards,
    Stephen Marsh

    UrbanServers.com - Powerful UK SSD VPS

  4. #4
    Join Date
    Aug 2002
    Location
    UK
    Posts
    846
    ^^ I never said the assumption would hold true, it's just the scope of this howto does not cover kernel configuration, you could if you wanted copy /proc/config to /usr/src/linux/.config assuming your old kernel was compiled with /proc/config support in which case you'll use the same config as your old kernel used.

  5. #5
    Join Date
    Sep 2002
    Location
    Among the corn
    Posts
    10,636
    Great newbie tutorial, only one thing that I can see missing:
    First, change to the source tree's directory: cd /usr/src/linux
    Second, start the menu configuration program: make menuconfig
    should be
    First, change to the source tree's directory: cd /usr/src/linux
    Second, configure all the old options into your new kernel configuration : make oldconfig
    Third, set the dependencies thus far: make dep
    Fourth, start the menu configuration program: make menuconfig

    Adding oldconfig will ensure that you haven't left something out that was in the previous kernel compilation, which could be anything from custom drivers to, well more custom drivers (that's where most kernels fail is at the driver level). It's rather important that you make sure to get the "oldconfig" in there so that this doesn't happen.

  6. Newsletters

    Subscribe Now & Get The WHT Quick Start Guide!

Related Posts from theWHIR.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •