Web www.freebsdmadeeasy.com
Main Menu

Recompiling The Kernel In FreeBSD

Unless you have built your own custom kernel in FreeBSD, you are using the GENERIC kernel. The GENERIC kernel contains everything you need to get the machine up and running the first time and covers a wide range of hardware. Some common reasons for rebuilding the kernel are:

Creating the Kernel Config

The first step to building a new kernel is to copy the GENERIC config file to your own. This new config file is generally given the hostname of the machine.

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

Once you have does this open the new kernel config and begin hashing out modules that are not needed. For example, if you are creating this kernel for a PIII you do not need the I486_CPU or the I485_CPU in your kernel and you can take them out like this:

machine i386
#cpu I486_CPU
#cpu I586_CPU
cpu I686_CPU

You should also change the ident to the name of the file so that when booting up it will show that it is booting your kernel and not the GENERIC one.

machine i386
#cpu I486_CPU
#cpu I586_CPU
cpu I686_CPU

On machines without SCSI controllers everything in the SCSI section can be hashed out, the same is true with the RAID, USB, and Firewire sections. If something needed is removed the machine may not be able to reboot with the new kernel and the previous one will need to be loaded instead. Notes on what the different modules in the config file are responsible for can be found in /usr/src/sys/i386/conf/NOTES

Building your new kernel is traditional way

# cd /usr/sbin/config NEWKERNEL
# cd ../../compile/NEWKERNEL
# make depend
# make
# make install

To save time the last three commands can be done as

# make depend && make && make install && reboot

Building your new kernel the new way

Recently FreeBSD has a new way to build and install the new kernel and it can be done as so

# cd /usr/src
# make buildkernel KERNCONF=NEWKERNEL
# make installkernel KERNCONF=NEWKERNEL

Here KERNCONF is just a variable that refers to the name of the kernel config file you want to use. To store the name so you no longer need the last part of these commands you can put the following into you /etc/make.conf to save it.



Once you successfully built and installed the kernel you will need to reboot the machine

# reboot


If the machine reboots successfully but gives errors it may be because the kernel was compiled with source code that is newer than that of the world. To rebuild with the new source code read about performing a make world