November 22

conf./comp./inst. linux kernel..

     Different methods of obtaining the Linux kernel can be found here. In this entry we’ll be configuring, compiling, and installing a Linux kernel. The kernel used for this example is v3.17.1.

     We’ll start by entering the directory with the kernel source code:

cd /usr/src/linux-3.17.1/

     Now, there are different methods to configure the kernel source before compilation. For the purpose of this example, we will simply copy our current kernel’s configuration options into the source directory. To do so, we issue the command:

sudo cp /boot/config-`uname -r` .config

from within the kernel source directory.

     Alternatively, we may opt to simply invoke a menu which will allow us to create a configuration file. During this process, if a .config file was previously copied into the directory, a new version will replace it and the old version is kept and renamed as .config.old. The newer version would consequently be used during kernel compilation. To use the menu configuration option, I issue the command:

sudo make menuconfig

     This brings up a menu interface within the terminal where we can select different options to be configured. Once the appropriate options/modules have been selected, we can save the configuration menu leaving the name unchanged as .config, and exit.

     There are plenty of different methods to configure a kernel which can be found here under configuration targets. Do note that some of these options require additional packages to be installed. For instance, xconfig and gconfig require extra packages for the graphical frontends they provide, such as QT and GTK respectively. QUick searches Online can mention exctly what packages are need, or sometimes clues in error messages may also hint on what dependencies are missing.

     Because the Linux kernel is a relatively large “program”, the vast number of pieces to compile may take some time to complete. There are, however, some tricks to reduce compilation time, such as using simultaneous jobs based on the processors available on a given machine. One way to find out how many processors are available is by issuing the following command:

grep -c "processor" /proc/cpuinfo

     The above command will count the number of occurences of “processor“, a pattern usually associated with the line containg the processor number as output of the /proc/cpuinfo module. the -c parameter of grep is used to count the occurences.

     If the output were 4 for example, this would mean that we could run 4 instances of the GNU C Compiler simultaneously, effectively reducing compilation time. Our command would look something like:

sudo make -j 4 deb-pkg LOCALVERSION=-custom

where:

  • -j 4: this tells make to run 4 simutaneous instances of gcc
  • deb-pkg: this says we would like to create *.deb packages out of the source
  • LOCALVERSION=-custom: we would like to append a differentiating name to the resulting files

     The result of the above command is 5 *.deb located one hierarchy above the source directory, and may look something like:

linux-firmware-image-3.17.1-custom_3.17.1-custom-1_amd64.deb
linux-headers-3.17.1-custom_3.17.1-custom-1_amd64.deb
linux-image-3.17.1-custom_3.17.1-custom-1_amd64.deb
linux-image-3.17.1-custom-dbg_3.17.1-custom-1_amd64.deb
linux-libc-dev_3.17.1-custom-1_amd64.deb

     We can avoid building some of these, which can save us some more time. For instance, to avoid building the kernel image with debuggin g symbols, or:

linux-image-3.17.1-custom-dbg_3.17.1-custom-1_amd64.deb

     We could add another parameter to the make command, such as INSTALL_MOD_STRIP=1. This will not only avoid the incluson of debugging symbols, but will also drastically reduce the size of the resulting files.

     Of the different *.deb pacages produced, the two main files we are mainly interested in are:

linux-image-3.17.1-custom_3.17.1-custom-1_amd64.deb
linux-headers-3.17.1-custom_3.17.1-custom-1_amd64.deb

where the first is the actual kernel image we need to instal tomake use the new kernel, and the second comprises several headers files pertaining to that specific kernel, whcih will help us build kernel modules in another entry of this blog.

     Now that we know which files we need to install, we can do so by issuing the following commands:

sudo dpkg -i ../linux-image-3.17.1-custom_3.17.1-custom-1_amd64.deb
sudo dpkg -i ../linux-headers-3.17.1-custom_3.17.1-custom-1_amd64.deb

     Installing the linux-image file will automatically update the GRUB configuration file on Ubuntu machines and variants and make the more recent version the defaut boot option. Access to the boot menu options in case we would like to boot another kernel image can be configured by following the steps found here. Once that is set, we’re done! All that is left is to reboot the machine:

sudo reboot