1.2. Compiling a Kernel

Compiling and installing a kernel can be described in three stages.

  1. Configuring the kernel

    Here we need to decide what kind of hardware and network support needs to be included in the kernel as well as which type of kernel we wish to compile (modular or monolithic). These choices will be saved in a single file: /usr/src/linux/.config

    Table 1.1. Creating the .config file

    CommandDescription
    make configEdit each line of .configone at a time
    make menuconfigEdit .config browsing through menus (uses ncurses)
    make xconfigEdit .config browsing through menus (uses GUI widgets)

    When editing the .config file using any of the above methods the choices available for most kernel components are:

    • Do not use the module (n)

    • Statically compile the module into the kernel (y)

    • Compile the module as dynamically loadable (M)

    Notice that some kernel components can only be statically compiled into the kernel. One cannot therefore have a totally modular kernel.

    When compiling a monolithic kernel none of the components should be compiled dynamically.

  2. Compiling the modules and the kernel

    The next table outlines the various 'makes' and their function during this stage. Notice that not all commands actually compile code and that the make modules_install has been included.

    Table 1.2. Compiling the kernel

    CommandDescription
    make cleanmakes sure no stale .o files have been left over from a previous build
    make depadds a .depend with headers specific to the kernel components
    makebuild the kernel
    make modulesbuild the dynamic modules
    make modules_installinstall the modules in /lib/modules/kernel-version/
  3. Installing the kernel image

    This stage has no script and involves copying the kernel image manually to the boot directory and configuring the bootloader (LILO or GRUB) to find the new kernel.