Rebuilding the OpenBSD Kernel
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'.
Some users want their OpenBSD machine to perform specific functions or support additional device drivers and may 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, but you should still apply the patches, which will require you to rebuild and install a fresh kernel.
You will need the system source code and patches. I will assume both of these have been installed, if not check out my Patching OpenBSD instructions. You can apply all the patches that require a kernel rebuild before rebuilding the kernel. This way you only rebuild once. Just make sure to apply them in order!
Building a new kernel
1) First you'll need to get into the appropriate working directory. This depends on the platform you are using. I'm working on a macppc but you can just substitute your platform where applicable. (i386, alpha, etc)
$ cd /usr/src/sys/arch/macppc/conf
2) Now we can configure it with the generic macppc configuration file.
$ sudo /usr/sbin/config GENERIC
3) Next we will make the new kernel. The make(1) program simplifies the maintenance and in this case, the compiling of other programs. We will first change to the correct directory and then run the make program. This 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’s not in the right place. If you reboot your computer, it will launch the kernel that is in '/' and the one we just built is still in /usr/src/sys/arch/macppc/compile/GENERIC. Lets move it so we can reboot and take advantage of the security patches we installed.
4) First lets make a backup copy of our old kernel in case the new one is broken.
$ sudo cp /bsd /bsd.old
5) Now we can copy our new kernel to '/' and try it out. It’s 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
6) Finally you can reboot and load the new kernel!
$ sudo reboot