Linux.com

Feature: System Administration

Recompile your kernel for a perfect fit

By Federico Kereki on August 16, 2007 (9:00:00 AM)

Share    Print    Comments   

After I wrote an article on optimizing disk performance, some readers commented that tweaking settings was just part of the job. They pointed out that you can get more speed if you also compile your kernel, adjusting it optimally for your specific hardware and needs. Compiling the kernel isn't the challenge it used to be; nowadays the process is streamlined, and you don't have to do much but pick your choices and key in some commands.

Most distributions provide a "one-size-fits-all" kernel, compiled with the most generic options, so everybody can use it. If you have an Athlon XP CPU instead of an Intel 386 family processor, or lots of RAM, or a certain graphics card, you can tweak the kernel and compile it for optimum performance on your specific hardware. In the process, you can also probably free some memory by getting rid of unneeded options, shorten boot time, and increase responsiveness.

An almost dry run

Compiling your kernel isn't very hard, but there's a distinct chance you could hose your machine and transform it into a paperweight (ask me how I know!), so you will have to take some precautions. Have a backup kernel available; that way, should you really muck things up, you can reboot your computer and start again. I use openSUSE, on which it's easy to install two or more kernels: by using the YAST administration tool or the Smart package manager, install two different versions of your kernel. For example, I have both 2.6.18.8-0.3 and 2.6.18.8-0.5, and my boot page shows:

openSUSE 10.2 - 2.6.18.8-0.5
Failsafe -- openSUSE 10.2 - 2.6.18.8-0.5
openSUSE 10.2 - 2.6.18.8-0.3
Failsafe -- openSUSE 10.2 - 2.6.18.8-0.3

By default, my machine is set to boot with the third option; I leave that version alone (so I can fall back on it if needed) and experiment with the first one. After building and being satisfied with your new kernel, you can use the standard tools (such as YAST for openSUSE) to set it as a default; more adventurous people could resort to editing GRUB or LILO boot configuration files by hand.

You will also have to install some specific packages: kernel-source (the source code you compile), gcc (the compiler), bzip2 (needed internally), and ncurses (for the configuration menus).

If you want to optimize your kernel, you need to know about your machine's hardware. By using the commands below, you can note what kind of processor you have, the RAM in your machine, and more details. I suggest printing this information out and keeping it by your side while you work.

lspci -v
cat /proc/cpuinfo
cat /proc/meminfo

If you want to be sure you have everything that you can need, you can rebuild your kernel without touching anything. Working as root, enter the commands:

cd /usr/src/linux
make clean
make
make modules_install
make install
reboot

The make process will run for a while, and might produce some warnings, but it shouldn't show any errors. If, after you reboot, everything is still fine, you are set for your kernel rebuilding adventure; in fact, you have just done your first such build! (And if something did go seriously wrong, for example because you were missing some package, reboot with the backup kernel, fix the problem, and try a "dry run" again.)

Just say "M"!

Now, let's compile a kernel for true. Once again, su in order to work as root, and enter:

cd /usr/src/linux
make clean
make menuconfig

You will see a screen showing a menu full of hundreds of options (so many ways to mess up!) but we will change just a few. Of course, if you feel adventurous, you can change anything you desire, as long as you set up an extra kernel just in case. If you want to disable an option, unmark it and it won't get compiled. To navigate the menus and see the available options, use the cursor keys; press "H" to see help at any time.

The Linux kernel is monolithic, which loosely means that it's just one big piece of software with everything thrown in. However, you can extend it by using modules, which are loaded on demand and only if needed. Thus, if you were to compile all possible functions as modules, the kernel would be as small as possible, and you would only suffer a small performance hit the first time a module was loaded. However, you don't want to make everything a module, because some functions need be available at boot: for instance, you couldn't read the partition that holds the modules if you didn't already have the needed code in the kernel. But whenever it's reasonable, set things up to be modules.

There's another argument in favor of modules. Removing support for every seemingly unused piece of hardware can cause some strange problem: for example, I removed the option about LVM AND RAID DEVICES, and later found out this caused a needed module not to be built, which then caused lots of other problems. The safest approach is to mark undesired options with "M" (so they will be compiled as modules) and not leave out anything unless you are completely sure you won't need it; cards or disk partition types you do not have, for example, are usually safe to remove. However, there are no guarantees that removing any option won't have a secondary, hidden, undocumented effect, which might end up in some kind of problem. In that case, reboot with the backup kernel, and just mark the option in question again.

Some options you can study, in order to save some memory:

  • In Networking, uncheck Amateur Radio Support unless you connect your PC to amateur radio. The other options are usually marked as "M"; leave them that way.
  • In File Systems, verify that everything is marked "M." If you are sure you won't be needing, say, JFS, you could uncheck the corresponding option, or better yet leave it as a module.
  • Also in File Systems, see Partition Types and uncheck everything that doesn't apply to you. In my case, since I have Windows disks in my machine, I kept the Windows-related partitions.
  • In Device Drivers, examine each section, and either uncheck or mark as "M" any device you do not have. SCSI or ISDN are options you are likely to be able to drop.
  • In Bus Options, disable EISA and MCA support unless your motherboard uses these kinds of buses; check the manufacturer specs if you are not sure.

Full speed ahead!

Depending on whether you use your PC as a server or as a desktop machine, you can pick several options to enhance responsiveness. I recommend the following for a desktop machine:

  • At Code Maturity Level Options, uncheck "Prompt for development and/or incomplete code/drivers"; you need this option only if you are developing or testing something in the kernel.
  • At General Setup, uncheck "Cpuset support" unless you have more than one processor; dual and quad-core processors count as more than one.
  • At Block Layer, uncheck everything unless you have disks that are larger in size than 2TB.
  • At Processor Type and Features, uncheck "Symmetric multi-processing support" unless you have more than one processor, or a Duo or Quad one. Pick the right processor at Processor Family, and the amount of RAM you have at High Memory Support. At Preemption Model, pick the "Preemptible Kernel (Low Latency Desktop)" option. Finally, check "Preempt the Big Kernel Lock," and at "Timer Frequency" pick 1000Hz.
  • At Kernel Hacking, uncheck everything -- you won't be doing kernel development, will you?

After you have finished picking options, exit the configuration program (say "YES" when asked about saving your new kernel configuration) and then run:

make
make modules_install
make install

Pay particular attention to unexpected error messages that might show a problem with your new kernel. Be prepared to wait; on my laptop, the make process takes more than half an hour. If get an error message, you can either go back to the menu to try and fix whatever was wrong, or just reboot with your backup kernel. If you cannot figure out what happened (quite possible: it's not always easy to relate an error to your menu choices) you can always reinstall your kernel (use YAST or Smart, as above) and start again.

If there were no error messages, reboot and try your new kernel.

In my case, I shaved about 10 seconds off the boot time, and also freed a couple of megabytes of RAM. The boot speedup isn't really noticeable, but the laptop now feels a bit more agile -- though that could of course be a placebo effect. Anyway, I learned a bit more about the kernel, optimized it for my own use, and gained a new tool in my search for speed.

In conclusion

If you want the swiftest possible Linux, don't be afraid to compile the kernel. You can learn a lot, and in the end you should get better system performance.

-- Write for us -- and get paid! --

Federico Kereki is an Uruguayan systems engineer with more than 20 years' experience developing systems, doing consulting work, and teaching at universities.

Share    Print    Comments   

Comments

on Recompile your kernel for a perfect fit

Note: Comments are owned by the poster. We are not responsible for their content.

Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 195.189.216.34] on August 16, 2007 10:13 AM
Unless you want to explain how to make a new initrd for your new kernel, I'd suggest noting and stressing it might be a good idea to compile in the drivers for your boot disk as well as the fs. Given your intended audience (and the hardware they'll probably have) unchecking PCI is not a good idea. Unchecking (E)ISA on the other hand ... In networking, you can uncheck tokenring stuff, hippi, ipx etc. Ip6tables support is risky if you don't know what you're doing (it opens you up for attack thru ip6, if you don't configure ip6tables to block you), so unchecking ipv6 is a no-hassle recommendation.
finally, if you or your distro prepared things properly, you might 'make install' the kernel without having to manually edit bootmgr files ...

#

Re: Recompile your kernel for a perfect fit

Posted by: Federico Kereki on August 16, 2007 03:22 PM
Writing PCI instead of EISA was an awful lapsus -- EISA is the older bus, while PCI is in most (all?) modern machines.

As to the installation, note that OpenSUSE provides "make install" (and I used it) so you don't have to edit files and do other jobs yourself.

Thanks for the other suggestions; I'll try them out myself!

#

Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 68.126.200.152] on August 16, 2007 10:40 AM
<code>cp /usr/src/linux-old-version/.config /usr/src/linux/ && cd /usr/src/linux && make oldconfig</code>

is a neat trick

#

Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 195.11.98.194] on August 16, 2007 11:55 AM
On the whole, recompiling your kernel is fairly pointless. Most distributions will provide CPU-arch-specific kernels, and most will provide kernels which are heavily modular, meaning that the drivers you don't need are not loaded into RAM.

Unless you really know what you're doing with compiler options and kernel basics, it's very unlikely that you'll end up with a kernel that's actually faster than a distro-provided one.

Plus you're completely ignoring distro-specific compilation tools which tie in hand-rolled kernels with packaging systems and boot managers to avoid conflicts. On the whole, a pretty poor article.

#

Re: Recompile your kernel for a perfect fit

Posted by: Federico Kereki on August 16, 2007 03:26 PM
In my case, the laptop has an Athlon single processor, and the provided generic x86 kernel even included SMP features -- I *did* get a (at least, slightly) better kernel with my fiddling, and of course used the OpenSUSE tools for building. My main point is that you shouldn't be afraid of compiling the kernel, you should be willing to delve within its parameters, and you could learn a bit more in the process.

#

Re(1): Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 59.92.205.214] on August 17, 2007 08:20 PM
I agree with you 'cause more you know about the kernel, more you improve the performance. There are many patches available today with which you can certainly improve the performance based on your need.

Blueray

#

disable PCI?!?

Posted by: Anonymous [ip: 212.74.185.47] on August 16, 2007 01:08 PM
I think you mean EISA, all modern PC's use PCI...

#

Re: disable PCI?!?

Posted by: Federico Kereki on August 16, 2007 03:19 PM
Of course I meant EISA, not PCI -- what a goof to do! Sorry!

#

Re(1): disable PCI?!?

Posted by: Anonymous [ip: 207.69.174.140] on August 16, 2007 09:44 PM
So, update the article?

#

Re(2): disable PCI?!?

Posted by: Federico Kereki on August 17, 2007 02:55 PM
I already submitted the fix request; it should be up soon.

#

Modules?

Posted by: Anonymous [ip: 67.91.126.66] on August 16, 2007 01:25 PM
I build everything into the kernel when I compile it instead of loading the modules. The only module I have loaded is nvidia, since those drivers can't be distributed with the kernel. Is there an advantage to loading my non-boot required modules from outside of the kernel?

#

Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 82.227.137.141] on August 16, 2007 02:11 PM
Please stop the madness of pulling the sources and compiling your kernel in /usr/src/linux. /usr is NOT the partition where that should happen ! I compile my kernel on my /home partition, which has _plenty_ of space for that kind of things, and is user-writable. I don't know about other distros but at install-time, Debian dutifully makes a symbolic link from /usr/src/linux to where the sources really are.

#

Re: Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 190.64.55.130] on August 17, 2007 03:23 PM
What good is having /usr as a separate partition in a home system?

#

Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 65.175.201.23] on August 16, 2007 03:07 PM
Nothing wrong with wanting to delve into the land of the Linux kernel if you feel the need. It's not like it would cause great harm to try and optimize it yourself.

#

A more complete GUIDE can be found at http://linuxhelp.150m.com

Posted by: Anonymous [ip: 219.88.92.170] on August 16, 2007 04:12 PM
There is a guide to compiling your own kernel at <a href="http://linuxhelp.150m.com/" target="_blank">http://linuxhelp.150m.com/</a> (<a href="http://m.domaindlx.com/LinuxHelp/" target="_blank">mirror</a>) and NEW mirror http://linux.50webs.org/



Where there are also HOWTOs on:



1) cloning your windows XP/2000 installations using Linux (back-ups),

2) installing windows XP/2000 on a spare partition with Linux,

3) accessing and writing to Windows XP (formatted with the NTFS) from Linux,

4) a script to walk you through a Gentoo Linux installation,

5) remix those 14 Debian installation CDs as 2 DVDs,

6) the entire book "Linux Device Drivers 3" as a single web-page (ie in HTML format),

7) 3D acceleration for ATI cards (simple procedure, works for SuSE and Mandriva and Debian),

8) some discussion on the GPL and non-free third party kernel modules,

9) compiling the worlds best DVD/Movie/Video/MP3 Player and Encoder (MPlayer and MEncoder),

10) some politics, eg: Israel Fakes a Provocation for War (the "kidnapping" of Cpl Shalit),

11) articles suggesting many world leaders are Jews,

12) an AMAZING comparison of filesystems,

13) and an article on the Linux Kernel SABOTEURS.




Jade

#

Re: A more complete GUIDE can be found at http://linuxhelp.150m.com

Posted by: Anonymous [ip: 201.253.32.76] on August 18, 2007 04:40 AM
That's a fucking nazi site

#

www.linux.com = censoring assholes

Posted by: Anonymous [ip: 219.88.92.170] on August 16, 2007 04:19 PM
Yeap: DIE you bastards

#

Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 219.88.92.170] on August 16, 2007 04:20 PM
I command that you pricks die

#

Re: Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 71.202.135.220] on August 22, 2007 07:45 PM
We love you my son

#

Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 198.8.4.25] on August 16, 2007 04:47 PM
The article states "In File Systems, verify that everything is marked "M." You really should have the support for your root file system compiled in the kernel, not as a module. Otherwise, how does it load?

#

Re: Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 190.64.49.173] on August 16, 2007 06:33 PM
It should be remarked that "However, you don't want to make everything a module, because some functions need be available at boot: for instance, you couldn't read the partition that holds the modules if you didn't already have the needed code in the kernel." must have greater precedence than "In File Systems, verify that everything is marked "M." If you are sure you won't be needing, say, JFS, you could uncheck the corresponding option, or better yet leave it as a module."

#

make install doesn't work on Ubuntu

Posted by: Anonymous [ip: 216.231.44.65] on August 16, 2007 04:50 PM
Although it works fine in other distros, the "make install" for the kernel doesn't seem to work at all in Ubuntu, which is a huge percentage of the user base. There are howtos out on the internet describing the extra steps to use on Ubuntu.


Although the article recommends compiling uneeded components as modules instead of disabling them, one benefit of disabling them entirely is that the compile time is reduced greatly.

#

Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 83.23.14.237] on August 16, 2007 06:13 PM
Thanks for very interesting article Federico. Keep up the good work. Regards
<a href="http://www.profesjonalna-reklama.pl" target="_blank">Pozycjonowanie</a>

#

There are a lot of error in the article

Posted by: Anonymous [ip: 127.0.0.1] on August 16, 2007 06:46 PM
1) Linux must be compiled as user, not as root!

add a user to the src group, logut, login and you can compile in /usr/src

you need also fakeroot to compile Linux in that way


2) is not a good idea to set as M all. It is best to search what you have, search the module needed to be compiled into Linux and remove all the others ... if unsure leave the default

for do this you can read this: http://www.kroah.com/lkn


3) it is a very bad idea to remove SCSI support: SCSI is also used for USB device!


4) it is a very bad idea to uncheck "Prompt for development and/or incomplete code/drivers"

that can show you a lot of interesting module that can be needed for new hardware and also for have new module versions



Before compiling Linux it is better to:

1) install a Linux compiled for your CPU

2) copy the /boot/config-... into /usr/src/linux

3) make oldconfing




It is beast to change the Linux configuration in more step and test that all work

#

Re: There are a lot of error in the article

Posted by: Anonymous [ip: 190.64.31.221] on August 16, 2007 09:21 PM
I prefer the M option myself for that way you can waste some time compiling unneeded modules but you cannot forget to compile a module you need.

#

Re: There are a lot of error in the article

Posted by: Anonymous [ip: 208.66.144.10] on August 18, 2007 01:04 AM
re:"It is beast" - Froydian slip? lol

#

Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 80.172.133.203] on August 17, 2007 04:49 AM
" * At Kernel Hacking, uncheck everything -- you won't be doing kernel development, will you?"
At least "Magic Sys rq key" is very useful. In case your computer freezes, you may be able to sync your disks, remount them readonly, reboot among many other things. Take a look at the documentation (kernel Documentation/sysrq.txt).

Regards.

#

Poll: Do you compile your own Linux kernels?

Posted by: Anonymous [ip: 213.191.139.250] on August 17, 2007 11:01 AM
<a href="http://www.linuxinsight.com/poll-do-you-compile-your-own-linux-kernels.html">Vote here</a>

#

What bollox

Posted by: Anonymous [ip: 137.222.40.78] on August 17, 2007 11:59 AM
All you're doing is recompiling a kernel with fewer modules. Since the number of modules installed makes no difference to kernel speed, there's nothing much that you are achieving at all.

10s reduction in boot time... and how many hours recompiling your kernel ... you'll need to do a lot of rebooting before the next time you decide to upgrade your kernel to get that time back. And how often do you reboot anyway? Just suspend to disk or ram.

#

QUAKECON

Posted by: Anonymous [ip: 190.64.55.130] on August 17, 2007 03:11 PM
For ENEMY TERRITORY:QUAKE WARS it is said that 'You need a low latency kernel for good performance (this applies to both client and server installs). Mostly, make sure your kernel configuration has CONFIG_HZ_1000=y. You should also enable other low latency desktop settings, such as the various preemption capabilities.' These are the suggestions in teh 'FULL SPEED AHEAD' part, right?

#

Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 24.176.46.100] on August 23, 2007 02:34 PM
From the article: "Compiling your kernel isn't very hard, but there's a distinct chance you could hose your machine and transform it into a paperweight (ask me how I know!)"



How, pray tell, does one hose one's system with an improperly configured kernel? I'm a Gentoo user, and have spent much time in #gentoo on freenode. At worst, an improperly configured kernel won't boot. It's easily fixed by booting into a livecd and fixing the kernel config. If for whatever reason that doesn't work, you can always boot a livecd, back up your stuff, and reinstall your distro from scratch. I don't see how a bad kernel can render a machine completely useless.

#

linux property

Posted by: Anonymous [ip: 75.126.136.132] on October 07, 2007 09:29 AM
where y can fine software suse

#

Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 89.59.158.209] on October 10, 2007 11:31 AM
Thank you very much for this interesting Article, very useful information.... <a href="http://www.yellobook.eu">yellowpage</a>

#

Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 89.59.191.72] on November 05, 2007 04:16 PM
Thank you for sharing this information
<a href="http://www.yellobook.eu">yellowpages</a>

#

Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 88.244.166.77] on December 18, 2007 05:10 PM

<a href="http://www.cesurturk.org" >www.r10.net küresel ısınmaya hayır seo yarışması</a>
<a href="http://www.saboces.gen.tr" >www.r10.net küresel ısınmaya hayır seo yarışması</a>
<a href="http://www.cesurturk.org/index.php?ind=kureselisinma" >www.r10.net küresel ısınmaya hayır seo yarışması</a>
<a href="http://www.cesurturk.org/index.php?ind=kureselisinma" >r10 seo yarışması</a>
<a href="http://www.cesurturk.org/index.php?ind=reviews&op=entry_view&iden=8844" >DrCetinerDotOrg - DrCetinerDotOrg</a>
<a href="http://www.cesurturk.org/index.php?ind=reviews&op=entry_view&iden=8846" >DrCetinerDotOrg</a>
<a href="http://r10kureselisinmayahayirseo-yarismasi.blogspot.com" >www.r10.net küresel ısınmaya hayır seo yarışması</a>
<a href="http://kureselisinmaveekoloji.blogspot.com" >www.r10.net küresel ısınmaya hayır seo yarışması</a>

<a href="http://www.sagiroda-fan.com" >Sağır Oda</a>
<a href="http://izleindirfull.blogspot.com" >dizi izle</a>
<a href="http://r10kureselisinmayahayirseo-yarismasi.blogspot.com/" >www.r10.net küresel ısınmaya hayır seo yarışması</a>
<a href="http://www.cesurturk.org/index.php?ind=reviews" >dizi izle</a>
<a href="http://www.cesurturk.org/index.php?ind=gallery" >resim galerisi</a>
<a href="http://www.cesurturk.org/index.php?ind=news" >haber</a>
<a href="http://www.cesurturk.org/phpBB2/index.php" >forum</a>
<a href="http://www.cesurturk.org" >küresel ısınma</a>
<a href="http://www.saboces.gen.tr" >küresel ısınma</a>
<a href="http://www.cesurturk.org/index.php?ind=kureselisinma" >küresel ısınma</a>
<a href="http://www.cesurturk.org" >r10 seo yarışması</a>
<a href="http://www.saboces.gen.tr" >r10 seo yarışması</a>
<a href="http://www.yeseviyle.com/" >uzaktan eğitim</a>

#

Recompile your kernel for a perfect fit

Posted by: Anonymous [ip: 88.241.137.203] on January 09, 2008 09:35 AM
Best regards.

<a href="http://www.feramon.com">feromon</a> -
<a href="http://www.zets.net">Directory</a> -
<a href="http://www.by1by.com">directory</a> -
<a href="http://www.shopseks.com/feromon.html">feromon</a> -
<a href="http://www.hepzinde.com/feromon.html">feromon</a> -
<a href="http://www.koz-metik.com/toplist-a11.html">Kozmetik</a> -
<a href="http://www.shopseks.com/toplist.html">Shopseks.com</a> -
<a href="http://www.hepzinde.com/toplist.html">Hepzinde.com</a> -
<a href="http://www.hepzinde.com/penis-buyutucu.html">penis büyütücü</a> -
<a href="http://www.hepzinde.com/penis-buyutucu/penis-buyutucu-1.html">penis büyütücü</a> -
<a href="http://www.hepzinde.com/virility-pills.html">virility pills</a> -
<a href="http://www.hepzinde.com/elektronik-sigara.html">elektronik sigara</a> -
<a href="http://www.shopseks.com/virility-pills.html">virility pills</a> -
<a href="http://www.shopseks.com/penis-buyutucu.html">penis büyütücü</a> -
<a href="http://www.koz-metik.com/buyutuculer-c29.html">penis büyütücüler</a> -
<a href="http://www.koz-metik.com/bayan-fantazi-ic-giyim-c36.html">bayan iç giyim</a> -
<a href="http://www.koz-metik.com/virility-pills-p14.html">virility pills</a> -
<a href="http://www.koz-metik.com/elektronik-sigara-c46.html">elektronik sigara</a>
<a href="http://www.koz-metik.com/feromon-c47.html">feromon</a> -
<a href="http://www.shopseks.com/bayan-fantazi-ic-giyim.html">bayan iç giyim</a> -
<a href="http://www.hepzinde.com/bayan-erotik-ic-giyim-1-2-3.html">bayan iç giyim</a>

#

This story has been archived. Comments can no longer be posted.


 
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya