Stripping Down the Kernel


Every device driver and option in the kernel uses memory. One reason for rebuilding a kernel is to reduce its memory footprint, leaving more memory for other applications. In most cases, purchasing more memory is a better move than recompiling the kernel, but this may not be an option. This will have the added side effect of decreasing the amount of time your system takes to boot by a few seconds. To do this, simply find every line in the kernel configuration that doesn't have matching hardware in your system and comment it out with a pound sign (#).

For example, we saw in "Connection Configuration" that the kernel can recognize two sorts of ISA bus connections: one to the main bus and one to the PCI-ISA bridge.

 isa0    at mainbus0 isa0    at pcib? 

Your computer will only have one ISA bus in it, however! One of these configuration entries is useless. You can find out which is correct by looking at your computer's boot-time messages, in /var/run/dmesg.boot. My test system has the following entry for its ISA bus.

 isa0 at pcib0 

The ISA bus in this system is attached to the PCI-ISA bridge. I could remove the entry for the ISA bus attached to the main bus.

Each line in /var/run/dmesg.boot matches a line in the kernel configuration. The simplest way to trim out unnecessary device drivers is to remove device driver entries that don't match anything in your system. For example, I see 37 SCSI card drivers in the 3.1 GENERIC kernel. Even if I have a SCSI card, chances are that 36 of those drivers are completely useless. I can comment them out, along with the SCSI bus drivers that depend upon them.

Dmassage and Kernel Configuration

Matching lines in /var/run/dmesg.boot to kernel configuration statements is a very tedious task and a perfect candidate for automation. The dmassage program we looked at in Chapter 11 can do this for us. Dmassage's "-s" flag will compare an existing kernel configuration and /var/run/dmesg.boot and comment out any entries in the kernel configuration that do not appear in the dmesg.boot. Dmassage will dump the output to standard out, so be sure to redirect to a file. Here we'll use dmassage to strip down a GENERIC kernel and create a new minimalist version of the kernel configuration.

 # dmassage -s GENERIC > OPENBSDTEST 

One problem with using dmassage in this manner is that dmassage doesn't consider removable devices. If you are using USB hardware, for example, you'll want to go through your stripped kernel configuration and put the appropriate device drivers back in. Laptop PCMCIA cards have similar problems. To add these devices back to your kernel configuration, just remove the leading pound signs.

Alternately, you could boot with every device you own plugged in. This would make them show up in /var/run/dmesg.boot, and hence dmassage would keep them in the kernel configuration.

Enhancing the Kernel

So, you know how to remove options from the kernel. But how do you add them? And, more importantly, how do you know what to add? You have two major sources of information on what to add: options(4) and the GENERIC kernel configuration itself.

The options(4) man page lists every kernel option available for general use. Many of these options are already included in the GENERIC kernel, but some are not. You might want to add some of them, depending on your needs. In most cases, though, additional options aren't necessary.

The GENERIC kernel configuration includes quite a few commented-out device drivers. Some of these are commented out because they conflict with other device drivers, and some of these conflicts are quite annoying to work around otherwise. For example, the Mitsumi CD-ROM drive (quite famously) conflicts with other hardware and consequently prevents a successful installation. The driver for non-Plug-and-Play joysticks can cause problems during the boottime hardware probe. Most of this hardware is not only rare, but also obscure. It's commented out in GENERIC because supporting it by default causes more trouble than it's worth. You might want to uncomment one of these, if you have the appropriate hardware to use them. Just remove the comment, and it's ready to go.

Changing the Kernel

You might find that you need to change the options on a device driver, much as you can do with config(8) (see Chapter 11). Device drivers that have IRQs, port addresses, and driver flags hard-coded all have that specified in the kernel's device entry. To change any of these settings, simply edit the configuration file. For example, the default configuration for our ISA NE2000 card looks like this:

 ne0     at isa? port 0x240 irq 9              # NE[12]000 ethernet 

The IRQ and memory port number are specified right on the line. Change them to any sensible values to accommodate your hardware. Changing hardware information isn't enough reason in and of itself to recompile your kernel, but if you're recompiling anyway you might as well correct them.




Absolute Openbsd(c) Unix for the Practical Paranoid
Absolute OpenBSD: Unix for the Practical Paranoid
ISBN: 1886411999
EAN: 2147483647
Year: 2005
Pages: 298

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net