There are four categories of trouble that can occur when building a custom kernel. They are:
If config(8) fails, it is probably a simple error. Fortunately, config(8) will print the line number that it had trouble with. For example, for this message:
config: line 17: syntax error
Make sure the keyword on line 17 is typed correctly by comparing it to the GENERIC kernel or another reference.
If make fails, it usually signals an error in the kernel description which is not severe enough for config(8) to catch. Review the configuration, and if you still cannot resolve the problem, send an email to the FreeBSD general questions mailing list with the kernel configuration.
If the new kernel does not boot, or fails to recognize devices, do not panic! Fortunately, FreeBSD has an excellent mechanism for recovering from incompatible kernels. Simply choose the kernel to boot from at the FreeBSD boot loader. This can be accessed when the system boot menu appears by selecting the “Escape to a loader prompt” option. At the prompt, type boot kernel.old, or the name of any other kernel that will boot properly. When reconfiguring a kernel, it is always a good idea to keep a kernel that is known to work on hand.
After booting with a good kernel, check over the configuration file and try to build it again. One helpful resource is /var/log/messages which records the kernel messages from every successful boot. Also, dmesg(8) will print the kernel messages from the current boot.
Note: When troubleshooting a kernel, make sure to keep GENERIC, or some other kernel that is known to work, on hand as a different name that will not get erased on the next build. Do not rely on kernel.old because when installing a new kernel, kernel.old is overwritten with the last installed kernel which may be non-functional. As soon as possible, move the working kernel to the proper /boot/kernel location or commands such as ps(1) may not work properly. To do this, simply rename the directory containing the good kernel:
# mv /boot/kernel /boot/kernel.bad # mv /boot/kernel.good /boot/kernel
If the kernel version differs from the one that the system utilities have been built with, for example, a -CURRENT kernel on a -RELEASE, many system status commands like ps(1) and vmstat(8) will not work. To fix this, recompile and install a world built with the same version of the source tree as the kernel. This is one reason why it is not a good idea to use a different version of the kernel than the rest of the operating system.