[an error occurred while processing this directive] FreeBSD Handbook : Configuring the FreeBSD Kernel : Building and Installing a Custom Kernel
Previous: Why build a custom kernel?
Next: The Configuration File

5.2. Building and Installing a Custom Kernel

First, let us take a quick tour of the kernel build directory. All directories mentioned will be relative to the main /usr/src/sys directory, which is also accessible through /sys. There are a number of subdirectories here representing different parts of the kernel, but the most important, for our purposes, are i386/conf, where you will edit your custom kernel configuration, and compile, which is the staging area where your kernel will be built. Notice the logical organization of the directory tree, with each supported device, filesystem, and option in its own subdirectory. Also, anything inside the i386 directory deals with PC hardware only, while everything outside the i386 directory is common to all platforms which FreeBSD could potentially be ported to.

Note: If there is not a /usr/src/sys directory on your system, then the kernel source has not been been installed. Follow the instructions for installing packages to add this package to your system.

Next, move to the i386/conf directory and copy the GENERIC configuration file to the name you want to give your kernel. For example:

# cd /usr/src/sys/i386/conf
# cp GENERIC MYKERNEL
Traditionally, this name is in all capital letters and, if you are maintaining multiple FreeBSD machines with different hardware, it's a good idea to name it after your machine's hostname. We will call it MYKERNEL for the purpose of this example.

Note: You must execute these and all of the following commands under the root account or you will get ``permission denied'' errors.

Now, edit MYKERNEL with your favorite text editor. If you're just starting out, the only editor available will probably be vi, which is too complex to explain here, but is covered well in many books in the bibliography . Feel free to change the comment lines at the top to reflect your configuration or the changes you've made to differentiate it from GENERIC.

If you've build a kernel under SunOS or some other BSD operating system, much of this file will be very familiar to you. If you're coming from some other operating system such as DOS, on the other hand, the GENERIC configuration file might seem overwhelming to you, so follow the descriptions in the Configuration File section slowly and carefully.

When you're finished, type the following to compile and install your kernel:

# /usr/sbin/config MYKERNEL
# cd ../../compile/MYKERNEL
# make depend
# make
# make install
The new kernel will be copied to the root directory as /kernel and the old kernel will be moved to /kernel.old. Now, shutdown the system and reboot to use your kernel. In case something goes wrong, there are some troubleshooting instructions at the end of this document. Be sure to read the section which explains how to recover in case your new kernel does not boot .

Note: If you've added any new devices (such as sound cards) you may have to add some device nodes to your /dev directory before you can use them.


FreeBSD Handbook : Configuring the FreeBSD Kernel : Building and Installing a Custom Kernel
Previous: Why build a custom kernel?
Next: The Configuration File [an error occurred while processing this directive]