BSD DevCenter
oreilly.comSafari Books Online.Conferences.


OpenBSD Kernel Compilation and Optimization
Pages: 1, 2

Step 2

Once you've added/hashed out the options listed above and are satisfied with your kernel configuration, it's time to configure a build from your kernel config file and compile it into a kernel. This is done by performing the following commands:

cd /usr/src/sys/arch/$ARCH/conf ; config MYFILE

where $ARCH is your system architecture and MYFILE is the kernel config file you have written.

cd ../compile/MYFILE ; make depend && make

This will build your kernel dependencies and the kernel itself. This takes anywhere between five minutes and five hours depending on the speed and architecture of your system.

cp /bsd /bsd-original ; cp bsd /bsd

Installs your kernel and keeps the original kernel still bootable as bsd-original.

Step 3

With your new ultra-speedy kernel now in place, you're ready to reboot and make sure the kernel boots correctly and supports all the devices it's supposed to. After issuing a "halt" or otherwise resetting the system, the boot> prompt should appear. Your new kernel, if built using the exact instructions above, should boot automatically, but if not or if you wish to revert to the backed-up original kernel, you'll need to dictate the kernel to boot manually. This is in the simple format of device:/kernel-location, for example:

boot> boot wd0a:/bsd-original

boot> boot fd0a:/bsd

These commands boot the /bsd-original kernel from the first partition of the first IDE hard drive, or the /bsd kernel from the first floppy drive respectively. Should problems be encountered with the new kernel, a facility called the UKC (User Kernel Config) can perform boot-time configuration to attempt to debug it. The UKC can be invoked from the boot> prompt by using the -c flag. For example:

boot> boot wd0a:/bsd -c

Commands such as list, change, enable, disable, and of course help can be used within the UKC to configure devices and their I/O parameters and IRQ addresses. The UKC is quite complex, so I won't go into it in detail here. More information on the UKC can be found in the official kernel configuration how-to.

With the new optimized kernel working, you might be interested in benchmarking it against your previous kernel for performance. There are several benchmarking utilities available, but I find lmbench (available in the ports tree) to be a good indication of optimization. It provides scores for memory latency, CPU speed, and loopback network latency. In an age of exponential hardware growth and shortening life span of systems, it's good to see you can milk every last drop out of the hardware you have before going out and replacing it.

David Jorm has been involved with open source and security projects for several years, originally with OpenBSD and Debian GNU/Linux, now with the development team at

Read more OpenBSD Explained columns.

Discuss this article in the Operating Systems Forum.

Return to the BSD DevCenter.


Sponsored by: