How Do I Compile a FreeBSD Kernel?

This is just an introduction into compiling your own FreeBSD kernel. For more detailed information, check out the FreeBSD Handbook.

Procedure

[my kernel dir] is some directory in your local space (such as /playpen1/clark/src/sys/). For an ALTQ kernel, replace "sys" with "sys-altq" everywhere you see it in these directions.
  1. Get a fresh kernel source
          root# mkdir [my kernel dir]
          root# cd /usr/src/sys
          root# tar cvf - . | (cd [my kernel dir]; tar xf -)
    
  2. Configure your new kernel

    Here, if you want an ALTQ kernel, replace "DIRT" with "ALTQ.1000" or "ALTQ.100" depending upon the clock speed you want.

          root# cd [my kernel dir]/i386/conf/
          root# cp DIRT [my kernel name]
          root# config [my kernel name]
    
  3. Make the new kernel
          root# cd ../../compile/[my kernel name]
          root# make depend
          root# make clean
          root# make
    
  4. Install the kernel on the appropriate machine (usually NOT on the machine where it was compiled)
          root# cp [my kernel dir]/compile/[my kernel name]/kernel /kernel.[my kernel name]
          root# chflags noschg /kernel
          root# cp /kernel /kernel.prev
          root# cp /kernel.[my kernel name] /kernel
          root# chflags schg /kernel
    
    /usr/dirt/bin/change_kernel follows these steps.

Use uname -a to check that the new kernel is running (after rebooting, obviously.)

Newer Releases

Compiling a 4.10 kernel gave me (Felix) some problems today. The procedure above failed in the make step, so I went back to the FreeBSD handbook and read about a new method (running make buildkernel KERNCONF=MYKERNEL in /usr/src). This worked like a charm (but the kernel binary ended up under /usr/obj).


Other DiRT documents
Author: Michele Clark
Modified by: Felix Hernandez