Frequently Asked Questions for FreeBSD 2.X : Kernel Configuration : Ok, so how DO I compile my own kernel, anyway?
Previous: Kernel Configuration
Next: When I compile a kernel with multi-port serial code, it tells me that only the first port is probed and the rest skipped due to interrupt conflicts. How do I fix this?

8.1. Ok, so how DO I compile my own kernel, anyway?

Before you can compile a kernel, you need either the complete srcdist or, at the minimum, the kerndist loaded on your system. This provides the necessary sources for building the kernel, as we have a policy of NOT shipping our kernels in linkable object form as most commercial UNIX vendors do. Shipping the source takes a bit more space, but it also means that you can refer to the actual kernel sources in case of difficulty or to further your understanding of what's actually happening.

Anyway, to answer the question, once you have the kerndist or srcdist loaded, do this:

  1. cd /usr/src/sys/i386/conf

  2. cp GENERIC MYKERNEL

  3. vi MYKERNEL

  4. config MYKERNEL

  5. cd ../../compile/MYKERNEL

  6. make depend

  7. make all

  8. make install

  9. reboot

Step 2 may not be necessary if you already have a kernel configuration file from a previous release of FreeBSD 2.X. - simply bring your old one over and check it carefully for any drivers that may have changed boot syntax or been rendered obsolete.

A good kernel config file to look into is LINT, which contains entries for all possible kernel options and documents them fairly well. The GENERIC kernel config file is used to build the initial release you probably loaded (unless you upgraded in-place) and contains entries for the most common configurations. It's a pretty good place to start from.

If you don't need to make any changes to GENERIC, you can also skip step 3, where you customize the kernel for your configuration. Step 7 should only be undertaken if step 6 succeeds. This will copy the new kernel image to /kernel and BACK UP YOUR OLD ONE IN /kernel.old! It's very important to remember this in case the new kernel fails to work for some reason - you can still select /kernel.old at the boot prompt to boot the old one. When you reboot, the new kernel will boot by default.

If the compile in 6 falls over for some reason, then it's recommended that you start from step 4 but substitute GENERIC for MYKERNEL. If you can generate a GENERIC kernel, then it's likely something in your special configuration file that's bad (or you've uncovered a bug!). If the build of the GENERIC kernel does NOT succeed, then it's very likely that your sources are somehow corrupted.

Finally, if you need to see your original boot messages again to compile a new kernel that's better tailored to your hardware, try the dmesg(8) command. It should print out all the boot-time messages printed by your old kernel, some of which may be quite helpful in configuring the new one.


Frequently Asked Questions for FreeBSD 2.X : Kernel Configuration : Ok, so how DO I compile my own kernel, anyway?
Previous: Kernel Configuration
Next: When I compile a kernel with multi-port serial code, it tells me that only the first port is probed and the rest skipped due to interrupt conflicts. How do I fix this?