Skip to main content
  1. Notes/
  2. Linux Kernel/

Getting Started with Kernel Development

Linux Kernel Versions
#

  • Linux kernel comes in two flavors: stable and development.
  • New stable kernel versions are released only to fix bugs and security issues. Development versions undergo rapid changes and include new features.

Kernel Versioning Scheme
#

Historically,

  • Linux kernel versions are numbered in the form X.Y.Z, where:
    • X is the major release number.
    • Y is the minor release number.
    • Z is the revision number.
  • Sometimes, an additional fourth number W is added, which is the stable version number.
  • Minor releases also determine whether the kernel is a stable or development version:
    • If Y is even, it is a stable release.
    • If Y is odd, it is a development release. Example: 2.6.30.1 is a stable release, while 2.5.45 is a development release.
  • Development kernels stablize over time, for example, series 1.3 stablized into 2.0, and 2.5 stablized into 2.6.

After 2.6 series,

  • After an invite-only Kernel Development Summit in 2004, the versioning scheme was changed, and the kernel developers decided to prolong the 2.6 series and postpone the introduction of 2.7 development series.
  • Instead, the development cycle of each 2.6 revision grew longer, each release incorporating a mini-development series.
  • To compensate for the reduced frequency of releases, the kernel developers introduced the stable version number W as the fourth number in the versioning scheme, which contain only bug fixes and security patches. And these are often backported from the under-development kernel. Example: Release 2.6.32.8 is the eighth stable release based on the development kernel 2.6.33.
  • This allows the previous releases to receive attention focused on stabilization.
Linux Mailing List(lkml)
#
  • This is the mail forum where kernel development is discussed.
  • It is a high-traffic list with thousands of messages per day.
  • Subscriptions are free and open to anyone: https://vger.kernel.org.
  • Here is an archive of the mailing list: https://lkml.org.
  • Since, its a high-traffic list, Linus and other kernel maintainers often get thousands of emails per day. So, they are not open to dealing with nonsense.
  • This is where you will find testers, developers, peer reviewers while developing new features or fixing bugs.

Kernel Setup and Configuration
#

  • Get the latest code from Linus’s tree:

    git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
    

    or get the tarball from the website and uncompress it:

    • bzip2 format:
      tar xvjf linux-x.y.z.tar.bz2
      
    • GNU zip(modern):
    tar xvzf linux-x.y.z.tar.gz
    

NOTE: The kernel source lives in /usr/src/linux in your system. Avoid directly making any changes to it, even when installing new kernel.

  • Configure the kernel:

    • Configure kernel before building it. The configuration lives in the .config file, in the root of the kernel source.

    • Configure options are either booleans(yes or no) or tristates(yes, no, or module).

    • A module setting in tristate represents a config option that is set but is to be compiled as a module(separate dynamically loadable object).

    • Drivers are usually represented by tristates.

    • These options do not control the build process, they just specify values that kernel source can access as a preprocessor macro.

    • Kernels such as those provided by Canonical for Ubuntu or Red Hat for Fedora, are precompiled as part of the distribution. Mostly these enable a good cross section of the needed kernel features and compile nearly all drivers as modules.

    • To configure the kernel one option at a time run:

      make config
      

      NOTE: This can get very tedious.

    • Better ways to config:

      • Use a TUI menu
      make menuconfig
      

      NOTE: This is what I use.

      • Or a gtk+ based graphical utility:
      make gconfig
      
    • Sometimes, you just want things to be up and running with a default config file:

      make defconfig
      
    • Validate config before proceeding:

      make oldconfig
      
  • Build the Kernel

    • Simple
    make
    
    • Using multiple jobs to speed up compilation:
    make -jN
    

    where N is the number of threads to use.

    NOTE: Using make -j$(nproc) uses all available cores.

  • Install the Kernel: Depends on architecture and bootloader. Here I will cover installation for x86 systems using GRUB bootloader.

    • Install modules first: Installs modules to /lib/modules
    sudo make modules_install
    
    • Install the kernel:
    sudo make install
    
    • This will copy the kernel image to /boot and update the GRUB config file located at /boot/grub/grub.cfg or /boot/grub2/grub.cfg depending on your distribution.
    • Reboot the system to use the new kernel.

References
#