44.3 Rolling Your Own

Compiling your own Linux kernel may sound like a pretty scary task. Take a deep breath and ``enjoy the experience.’’ It is actually not such a big thing to compile your own kernel. And Debian makes it even more straightforward by supplying the kernel-package, kernel-package to leave you with a kernel-image package that you simply install, just as you would any kernel-image package you might get from Debian.

The advantages of compiling your own kernel include being able to tune the kernel to your specific hardware, and ending up with a smaller kernel. You may also need to compile your own kernel if the default kernel does not support some specific hardware you have. The distributed kernels though are becoming modular and it is becoming rare that you would need to compile your own kernel. If you do though, the recipe here should help and the introduction to compiling your own kernel at http://newbiedoc.sourceforge.net/tutorials/kernel-pkg/index-kernel-pkg.html should prove a useful read.

The hardware we review in this book has occasionally required kernel compiles. For example, Bartok contains over 1GB of memory but the supplied kernels limit to less than 1GB (NOHIGHMEM). Mint had a specific kernel compiled for it with sound support through ALSA, IDE SCSI emulation support for CDRW, and with PPP and IPMASQ support. Velox had a kernel compiled with sound support through ALSA, IDE SCSI emulation support for CDRW, and support for dual processors.

Some sample compiles of the kernel are included with specific installations in Chapter ??. See Section 40.44.5 for an example of compiling kernel 2.4.16 with extra memory support (HIGHMEM) and multiple CPU support (SMP). See Section @ref(sec:inst-kern-2.4.19) for an example of obtaining the linux kernel source (kernel 2.4.19) directly and compiling it the Debian way for Bach. See Section @ref(sec:inst-kern-2.4.20) for an example of obtaining the linux kernel source (kernel 2.4.19) and patching it with a pre-release (2.4.20-pre11) and compiling it the Debian way for Vivaldi.

Note that kernel version numbers interact with Debian’s package management. By calling your own compiled kernel version 2:kayon.1 it will be a more recent version number than the standard Debian kernel-image package. That is, kernel-image-2.2.14_2:kayon.1_i386 is regarded as being more recent than kernel-image-2.2.14_2.2.14-1_i386. Thus, the packaging system will not try to install a more recent 2.2.14 over your own kernel image. Debian kernel packages always have the version number the same as the kernel version number.

44.3.1 Getting Started

The first step is to install the appropriate packages:

  bin86
  kernel-package
  kernel-source-2.4.16
  debconf-utils
  alsa-source-0.5       (if you need ALSA's extra sound support)
  pcmcia-source

For the particular release of Debian being used the version numbers will be different. The kernel-package, kernel-package provides tools to generate, from the compiled kernel image, a genuine Debian package that you simply install as a standard type package. The resulting package can be installed (and uninstalled) cleanly and correctly with dpkg and wajig.

Note that you do not need the kernel-headers package as all the headers required are in the kernel-source, kernel-source package. The headers were split out for other reasons (compiling other packages without installing all of the kernel sources).

Installing the kernel-source, kernel-source package simply places the archived kernel source file (kernel-source-2.4.16.tar.bz2) into /usr/src. Similarly for any kernel modules you wish to also install (like alsa). Extract the actual source code into /usr/src/kernel-source-2.4.16:

  # cd /usr/src
  # tar jxvf kernel-source-2.4.16.tar.bz2
  # tar zxvf alsa-driver-0.5.tar.gz 
  # tar zxvf pcmcia-cs.tar.gz 

You can also obtain a more recent (or even just any different) version of the kernel from the net yourself and still use the Debian kernel-package utilities.

44.3.2 Kernel Configuration

{#sed:kernel.config}

The next task is to configure the kernel to suit your setup. There are very many configuration options and most can be ignored. Each also has a brief but helpful piece of documentation in /usr/src/linux/Documentation/Configure.help.

There are three methods available for selecting the configuration. The first and most basic is config which presents each option, sequentially, for you to decide what to do. This is a long process. The menu-based menuconfig presents a menu in a terminal. Options are grouped hierarchically and you can navigate to the specific options you wish to modify. The X Window System configurator is xconfig. We might suggest xconfig as the more convenient of the methods, but menuconfig is a good alternative if there is no X Window System running.

A good starting point for configuration is the basic configuration that is the default provided by Debian. You then refine the configuration. For an installed kernel-image you can find its configuration in /boot/config-2.4.16, for example. A simple approach to configuration is to copy the installed kernel’s configuration as the starting point and simply enable the options missing from that configuration (e.g., SMP):

  # cp /boot/config-2.4.16-686 kernel-source-2.4.16/.config

However, you may be better off starting with no .config. A default configuration will be installed and you can then add to this support for your specific hardware.

Below is a record of my configurations for Mint and Velox where configuration started with no /usr/src/kernel-source-2.4.16/.config:

  # cd kernel-source-2.4.16
  # make xconfig (or menuconfig or config)
        -> CONFIG_M686=y
      Plug and Play support
        -> CONFIG_PNP=y
      Block devices
        -> CONFIG_BLK_DEV_IDECD=m (previously y)        
        -> CONFIG_BLK_DEV_IDESCSI=m     
        -> CONFIG_BLK_DEV_LOOP=m
      Networking options
        -> CONFIG_FIREWALL=y                            Mint
        -> CONFIG_IP_FIREWALL=y                         Mint
        -> CONFIG_IP_MASQUERADE=y                       Mint
        -> CONFIG_IP_MASQUERADE_ICMP=y                  Mint
      SCSI support
        -> CONFIG_BLK_DEV_SR=m (previously y)
        -> CONFIG_BLK_DEV_SR_VENDOR=y
        -> CONFIG_CHR_DEV_SG=m
      SCSI support -> SCSI low-level drivers
        -> CONFIG_SCSI_AIC7XXX=y                        Velox
      Network device support -> Ethernet (10 or 100Mbit) 
        -> CONFIG_NET_VENDOR_3COM=y
        -> CONFIG_VORTEX=m
      Network device support
        -> CONFIG_PPP=y                                 Mint
      Filesystems
        -> CONFIG_ISO9660_FS=y
        -> CONFIG_JOLIET=y
        -> CONFIG_NTFS_FS=m
        -> CONFIG_FAT_FS=m
        -> CONFIG_MSDOS_FS=m
        -> CONFIG_VFAT_FS=m
      Sound
        -> CONFIG_SOUND=m               (Will use ALSA modules)

For Alpine and Bartok the configuration began with a copy of config-2.4.16-686-smp and /boot/config-2.4.16 respectively and the following were modified for the extra memory and SMP.

    Processor Type and Features
      CONFIG_MPENTIUMIII=y
      CONFIG_HIGHMEM4G=y (originally off)
      CONFIG_HIGHMEM=y (set automatically)
      CONFIG_SMP=y (already set)

For the laptop Inco the initial configuration was that of /boot/config-2.4.16-686 then modified as:

    Processor Type and Features
      CONFIG_MPENTIUMIII=y

This is not really needed though as I believe this simply adds some minor tunings to the kernel.

44.3.3 Kernel Modules

{#sec:modules}

The primary advantage of modules is that you compile to a smaller kernel for multiple machines with different hardware and have the hardware drivers loaded as needed. If you are compiling for a specific machine with specific hardware then you might as well compile the various drivers into the kernel rather than as modules.

44.3.4 Compiling the Kernel

{#sec:kernel.compile}

  # make-kpkg clean
  # make-kpkg --append-to-version -p3 --revision kayon01 --initrd kernel_image
  # make-kpkg --append-to-version -p3 --revision kayon01 --initrd modules_image

The use of --append-to-version will cause a new package to be created called kernel-image-2.4.16-p3 with revision 1.0. This package can then be installed without overwriting kernel-image-2.4.16 which may have been separately downloaded and installed.

You will be left with /usr/src/kernel-image-2.4.16-p3_kayon01_i386.deb and /usr/src/alsa-modules-2.4.16-p3_0.5.10b-6+p0+kayon01_i386.deb and /usr/src/pcmcia-modules-2.4.16-p3_3.1.8-10+2:kayon01_i386.deb, depending on what you have. These are ready to install.

44.3.5 Installing the Kernel

{#sec:kernel.install}

Installing thee new kernel and module packages is no different to installing similar packages you would obtain from the Debian archives.

If you are installing a new version of a kernel that is already installed you should move the corresponding modules aside, or else you will be asked to do so during the install:

  # cd /lib/modules
  # mv 2.4.16-p3 2.4.16-p3.prev

Now we are ready to install the kernel:

  # cd /usr/src
  # wajig install kernel-image-2.4.16-p3_kayon01_i386.deb

You will be asked whether you wish to run lilo. Usually you would. If this wipes out a precious master boot record (MBR) you can recover it with lilo -u.

Now install the modules (if any):

  # wajig install alsa-modules-2.4.16-p3_0.5.10b-9+p0+kayon01_i386.deb
  # wajig install pcmcia-modules-2.4.16-p3_3.1.8-10+2:kayon01_i386.deb

For Mint with support for CD-RW you now need to modify /etc/modutils/cdrw (as suggested in CD Writing HOWTO):

  options ide-cd ignore=hdd
  alias scd0 sr_mode
  pre-install sg          modprobe ide-scsi
  pre-install sr_mod      modprobe ide-scsi
  pre-install ide-scsi    modprobe ide-cd

To get this information into the right place the following should be done:

  # update-modules

Again for Mint the following were added to /etc/modules (otherwise the modules must be loaded manually for some reason which can be avoid using char-major stuff but don’t understand this yet):

  sr_mod
  sg
  ide-cd

For alsa edit /etc/alsa/alsa-base.conf to set startosslayer=true to be sure snd-pcm-oss is loaded at boot, otherwise it needs to be added to /etc/modules also.

  # reboot

44.3.6 Lilo Configuration

  image=/boot/vmlinuz-2.4.16-p3
       label=2.4.16-p3
       read-only
       initrd=/boot/initrd.img-2.4.16-p3


Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0