Making a Custom Kernel

This document has been updated 89/3/2016:

There may be two main reasons as to why you would want a custom kernel on your system:

You want to add some functionality to your system such as audio support, or
You may want to remove some unused drivers to conserve memory.

Either way, Making a Custom kernel will help your machine to be a faster box rather than using the GENERIC kernel. At the beginning of the install we updating your System to -STABLE which involved you downloading the src, or some simply put source, which we need for making the custom kernel. If you didn't do that step, here is what you need to do. For those of you who did update to -STABLE, skip to we can then start on the kernel customization:

Since sysinstall no longer works we need to use svnlite to install the sources. If you already have current sources please skip this step.

# cd /usr/src
# svnlite checkout /usr/src

This will take a few minutes to updae.

Once this is done we can then start on the kernel customization. Use one of the following commands to go to the proper folder depending if you're running i386 or amd64:

i386 users: # cd /usr/src/sys/i386/conf
amd64 users: # cd /usr/src/sys/amd64/conf

This is where FreeBSD keeps it's kernel configuration files. The generic kernel config is in the file GENERIC. All the possible kernel options can be found in the LINT file. What we will want to do first is copy GENERIC to a new Kernel name. We *NEVER* want to edit the GENERIC file.


A few notes about editing your new kernel file:

1) Here is an example line from the kernel

device ppbus # Parallel port bus (required)

any line that says (required) means exactly that. Don't comment it out or delete it. So in this example, you can delete everything below that section if you don't have a Printer, TCP/IP over parallel, or a Parallel port interface device.

2) Don't delete any lines. Comment them out with a # in the front.

3) Always change your ident line as follows

Scroll down the line that reads:

Change the line to read:

4) If you're not sure what you have or don't have for devices, you can check this in /var/log/messages (provided it hasn't been forever since your last reboot).

This is a great example. There are a ton of Network Card drivers in the kernel and you really only need one. Lets look in /var/log messages for your Ethernet Card. I'll use my NIC as an example:

fxp0: <Intel 82559 Pro/100 Ethernet> port 0xec00-0xec3f mem 0xdf100000-0xdf100fff,0xdf000000-0xdf0fffff irq 11 at device 9.0 on pci0

so if we edit MYKERNEL and scroll down to the PCI and make sure you keep the following lines in there and delete everything else in the PCI and ISA Network card sections:

device miibus # MII bus support
device fxp # Intel EtherExpress PRO/100B (82557, 82558)

So go ahead and make all the changes from there.

Now we can test your new kernel:

Change to the /usr/src directory.

# cd /usr/src

Compile the kernel.

# make buildkernel KERNCONF=MYKERNEL

If you get some errors you screwed up. Go fix it or copy GENERIC back to MYKERNEL and start over. If not, You can continue

Install the new kernel.

# make installkernel KERNCONF=MYKERNEL

You are done! You should reboot to make the changes effective!

If you do a uname -a after the reboot, you should now see

FreeBSD beast.local x.x-XXXXX FreeBSD 11.X-XXXXX #0: Day Mon XX XX:XX:56 EDT 2017 USER@beast.local:/usr/obj/usr/src/sys/MYKERNEL i386