Optimizing (slightly) the kernel

[Kernel doc]

O ne of the advantages of Ubuntu is that it turns into something quick and relatively simple to run a desktop computer with all common applications. But to get this done some "generalizations" that make the configuration adopted is not the best for our team and may improve performance by optimizing among other things, the core (kernel).

By default when you install Ubuntu, here in version 7.10-install a kernel mode called "generic." This core can run at least in theory, on any x86 compatible PC, so it might work in a 8086 Mhz 4'77 command line version, or even a very basic window manager. This starting point to say "universal compatibility" penalizes the performance of your PC, especially if you feel old. Let's see how to improve this situation.

The simplest alternative is, if we have an AMD or Intel Core 2 latter one generation, install the 64 bits. If you do not have one of these processors, or if you have installed the "normal" OS, we have a core "slightly" suffix i386 optimized, and we get by installing the meta-package linux-image-386:

sudo apt-get install linux-image-386

Restart Ubuntu and you'll notice the difference immediately.

Good. But we can go well beyond generating a core adapted to the number that corresponds to our processor. This is more complicated but not too:

Guidelines for compiling the kernel there are many, as this how-to , so I will not dwell on it, only a brief summary:

  • Install build-esential tools, libncurses5, libncurses5-dev, kernel-package
  • Install the latest kernel source current: meta-package linux-source
  • Go to the / USRC / src and untar the source linux-source-2.6.22.tar.bz2 found there.
  • Create a link to the source directory: sudo ln -s /usr/src/linux-source-2.6.22 /usr/src/linux
  • Change to / usr / src / linux
  • We launched the configuration tool with the default configuration as a starting point: sudo make oldconfig menuconfig
If the launch sudo make oldconfig menuconfig , it begins to ask, you do not have the default settings available. The copy:

/usr/src/linux$ sudo cp /boot/config-2.6.22-9-i386 .config

Here if we are to stop and identify those options that we have to turn on or off:

First we have to figure out which processor, you probably already know, but if not, in a terminal:

dmesg | grep CPU:

It will tell you you can have several lines, one of them indicates the CPU:

CPU: Intel Celeron (Coppermine) Steping 0a

[Menuconfig]

We have to enter the image menu Processor type and features

  • Selecting Processor family choose the option that corresponds to our processor, in this case Pentium-III/Celeron (Coppermine) / Pentium-III Xeon
  • In the same submenu unchecked Generic x86 support and Math Emulation. These options would only be necessary if using a 80 386 8086.80286 or equivalent, which is unlikely.
  • If we have less than 4 gigabytes of memory in our system we can put off the High Memory Support option.
  • If you have a dual core processor like the Core 2 Duo, you can enable support for use simultaneously, multi-turning symetric proccessing support (I have not tested this)
  • Timer frequency changes from 250 to 300MHZ (perhaps with a Core 2 suits, but put it to 1000)
  • If you have a Toshiba or Dell can disable Toshiba Laptop and Dell Laptop Support Support (less things to load into memory at startup and check)

We can go further by removing the device support that we needed in our particular system. Thus we get a kernel smaller and more efficient, since it does not have to check and / or upload code will never have many devices. But this is more delicate, and we run the risk that, after such a long wait, does not operate the new kernel or a device associated.

[Kernel menuconfig video]

For example, in the picture, I turned off the graphics drivers that I have, and never will because it is a laptop, and left the driver trident. It is, above all, to eliminate those components marked with an [*] that are what make "fat" to the kernel.

Well, we saved the changes, and start generating the kernel and redefined:

We pre-cleaning:

sudo make-kpkg clean , and start the compilation:

sudo make-kpkg --initrd --append-to-version=-p3 kernel_image kernel_headers

Replaces p3 (script is mandatory prior) for anything that distinguishes your new kernel existing in your computer. This process, especially if a computer is underpowered, it may take 4 to 6 hours. So when you launch the command better be before bedtime. (If you have a 3GHz Core 2 Duo will take much less of course).

And the next morning ....

You'll find two deb packages in the directory above you, / usr / src /. One corresponds to the image of the new kernel and another for the headwaters, which are necessary if you compile something about it. The install:

sudo dpkg -i linux-image-2.6.22.9-p3_2.6.22.9-p3-10.00.Custom_i386.deb

sudo dpkg -i linux-headers-2.6.22.9-p3_2.6.22.9-p3-10.00.Custom_i386.deb

It is recommended, finally, delete the symlink /usr/src/linux .

You can restart, and this newly created, will be the new default kernel.

Although I have not made any detailed benchmarking, see the difference and the laptop has gained some agility. While not expect wonders, especially with a graph and a processor so meager.

Diagnosis and Problems

The other kernels installed, the generic and if the i386, are still available. If there are problems just press Esc at the Grub countdown to display the menu and you can select some of these, starting normally and safely. This makes delicate operation does not involve virtually no risk.

Deb packages listed in Synaptic newly installed as linux-image-2.6.22.9-p3 and linux-headers-2.6.22.9-p3 and we can comfortably and uninstall from there if necessary.

If you want to leave again as alternative core simply edit /boot/grub/menu.lst and put the option default 0 to the serial number of the nucleus with which we want to start, or put the top of the list.

Driver compiled

If you have drivers compiled for you, it is recompiled to work with the new kernel.