Rebuilding the OpenBSD kernel

openbsd.png

The kernel is the core of the operating system. It is the binary file that the computer loads first and stores in memory. Because it is stored in memory, the kernel needs to be as small as possible. The kernel usually lives in the root directory (‘/’) and by default is called ‘bsd’.

Users who want their OpenBSD machine to perform specific functions or need additional device drivers might want to customize their kernel. In other OS’s, like some types of Linux, it is very popular to rebuild the kernel because the default is so bloated. For most users, the default OpenBSD kernel is sufficient; however, you should still apply kernel patches, which will require rebuilding and installing a fresh kernel.

You will need the system source code and patches. I will assume both of these have been installed.

Building a new kernel

1. Using the appropriate working directory

First you’ll need to get into the appropriate working directory. This depends on the platform you are using. This example is for a macppc, but you should use your platform’s directory instead (e.g., i386, alpha, etc…).

$ cd /usr/src/sys/arch/macppc/conf

2. Configuring

Now we can configure it with the generic macppc configuration file.

$ sudo /usr/sbin/config GENERIC

3. Building

Next we will build the new kernel using make. The make program simplifies the maintenance and compiling of other programs. We will first change to the correct directory and then run the make program. The second step will take a while.

$ cd /usr/src/sys/arch/macppc/compile/GENERIC
$ sudo make clean && sudo make depend && sudo make

Installing the new kernel

We have now created a new kernel, but it is not in the right place yet. If you reboot your computer, it will launch the existing kernel in ‘/’. The one we just built is still in /usr/src/sys/arch/macppc/compile/GENERIC/. We need to move it so that it loads when we reboot.

4. Making a backup

We make a backup copy of our old kernel in case the new one won’t boot.

$ sudo cp /bsd /bsd.old

5. Putting the kernel in place

Now we can copy our new kernel to ‘/’ and try it out. It is a good idea to make sure the permissions are set correctly, too.

$ sudo cp /usr/src/sys/arch/macppc/compile/GENERIC/bsd /bsd
$ sudo chown root:wheel /bsd

All done

Now that the kernel is built and installed, you can reboot and load it!

$ sudo reboot

Related Posts

Comments are closed.