How to Build OpenBSD Kernels

OpenBSD UNIX desktop running the QEMU emulator.

OpenBSD desktop running the QEMU emulator, with Windows XP running inside QEMU.

This is a very simplified version of the detailed directions found at the OpenBSD site.

Install the initial kernel source

The kernel source itself is available at a URL resembling the following, although you must replace release with the output of the uname -r command:
ftp://ftp.openbsd.org/pub/OpenBSD/release/sys.tar.gz
Expect a file of 18-20 megabytes.

You do know how to use anonymous FTP, right? If not, see my guide to using anonymous FTP.

Let's say that you downloaded that archive to /tmp. You should now do this:

# cd /usr/src
# tar xvfz /tmp/sys.tar.gz

All the building and rebuilding on OpenBSD goes on under the /usr/src/ directory. It is empty when you first install the system, but the kernel and the source for userspace tools go into subdirectories.

If you're reading this page because you are responding to kernel bug reports by rebuilding your kernel, you probably have some other patching and rebuilding to do. So you might as well get both files while you're connected to the FTP server, sys.tar.gz and src.tar.gz, with that second one about five times as large. Then install both:

# cd /usr/src
# tar xvfz /tmp/sys.tar.gz
# tar xvfz /tmp/src.tar.gz

Apply All Patches

Now you need to apply all the patches. They exist for good reasons — to fix problems of stability or security. Apply those patches!

The current patch list will be found at a URL resembling http://www.openbsd.org/errata46.html, change 46 to reflect your release minus the decimal point. Download all those patch files, let's assume you also saved them in /tmp.

Now you can apply the patches. If you use csh or tcsh, do it this way:

# cd /usr/src
# foreach FILE ( /tmp/*.patch )
> patch -p0 < $FILE
> end 

Or, if you use bash or ksh:

# cd /usr/src
# for FILE in /tmp/*.patch
> do
>   patch -p0 < $FILE
> done 

Build the Kernel

Change to the appropriate directory, changing i386 in the following commands as needed to reflect your hardware. OpenBSD runs on a lot of platforms, your choices include:
alpha, amd64, arm, armish, aviion, hp300, hppa, hppa64, i386, landisk, luna88k, m68k, m88k, mac68k, macppc, mips64, mvme68k, mvme88k, mvmeppc, powerpc, sgi, sh, socppc, solbourne, sparc, sparc64, vax, zaurus,

# cd /usr/src/sys/arch/i386/conf

Configure the build:

# config GENERIC

Prepare to build, removing any leftover object files and setting up dependencies:

# cd /usr/src/sys/arch/i386/compile/GENERIC
# make clean
# make depend

Build the kernel:

# make

That will take several minutes, and should eventually result in a binary named bsd.

Install your new kernel

This just takes one command, but first let's make sure we have a backup kernel available. Just in case....

The following would let us boot the current kernel by typing b /bsd-backup at the boot prompt:

# cp /bsd /bsd-backup

OK, now it's safe to really install that kernel:

# make install

Reboot and Enjoy!

That should just work!

If it didn't, remember that you can ask for the old backup kernel at the boot prompt:

Using drive 0, partition 3.
Loading...
probing: pc0 apm mem[633K 444M a20=on
disk: hd0+
>> OpenBSD/i386 BOOT 3.02
boot> b /bsd-backup

If you have the APM issue that required a kernel configuration change to install and boot in the first place, then see my page about installing OpenBSD on a Dell laptop to refresh your memory as to how to accomplish this.

The alternative would have been to modify the kernel configuration by editing the file /usr/src/sys/arch/i386/conf/GENERIC before building a kernel that leaves out that driver.

However, if you are really qualified to modify the kernel configuration before building and installing it, I'm not sure why you're reading this page!

Rebuilding Other Binaries

The above recommendation on downloading, installing, and patching the application source code will have some of the work out of the way. At least you will have patched source code.

What remains is to build and install the binaries based on the patched code. See the patch files for the details, but this generally requires something like the following, where you would skip the patch application if you have already done it:

# cd /usr/src/path/to/patched/source/code
# make
# make install 

How to build Linux kernels

How to install and run OpenBSD on a Dell Inspiron 1000 laptop

How to compile software on OpenBSD

Various UNIX/Linux topics


Home Unix/Linux Networking Infosec Travel Technical Radio Site Map Contact
Use /bin/vi! Manipulate images with ImageMagick! Hosted on OpenBSD
Hosted on Apache Valid XHTML 1.1! Valid CSS!
© Bob Cromwell Mar 2010. Created with /bin/vi and ImageMagick, hosted on OpenBSD with Apache.    Root password available here, privacy policy here.