How to build and install a custom kernel on FreeBSD?

Lets get started. The main reason I am writing this when so many articles on this already exist is because many articles do not have all the steps in one place. For example, the article in the FreeBSD Handbook doesn’t have steps for downloading the source using subversion or for making sure you have enough space on the root partition. See this article here: Building and Installing a Custom Kernell

Step 1 – Install FreeBSD as VMWare Guest.

Instructions for installing FreeBSD 9 are found here:

How do I install FreeBSD 9?

You may also want to install FreeBSD ports:

How to install FreeBSD ports

Step 2 – Download FreeBSD Source

Instructions for downloading FreeBSD Source can be found here:

How to download FreeBSD source using svn?

Step 3 – Build the GENERIC Kernel

Before you create a custom kernel it is always good to know that the default GENERIC kernel is compiling and working. Also, if you are practiced at this and are certain this will work, feel free to skip this step.

Note: I call it the GENERIC kernel because the GENERIC is the file name of the default kernel configuration.

  1. Go to the /usr/src directory:
    # cd /usr/src
    
  2. As root, run this command:
    # make buildkernel
    
  3.  Wait for the compile to complete

Step 4 – Create a new kernel config

  1. Determine your architecture by running this command:
    # uname -a
    FreeBSD 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan 3 07:46:30 UTC 2012 root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64
    
  2. Look at the last text item in the output string. I have amd64 so that is my architecture: amd64
  3. Change to the directory of the kernel configuration files for your architecture. Remember if you are on a different architecture to replace amd64 in the following command lien with your architecture.
    # cd /usr/src/sys/amd64/conf
    
  4. Copy GENERIC to a new file.
    # cp GENERIC KRNL1
    
  5. Edit KRNL1 with your favorite text editor.
  6. First, change the ident value near the top from GENERIC to KRNL1.
    ident           KRNL1
    
  7. Make any other changes you would like to make.It is hard to know why you are building a custom kernel and hopefully you know what you need in your custom kernel. This is where you modify the kernel to provide what you need.
  8. Save and close your new KRNL1 configuration file.

Step 5 – Build the custom kernel

Now that you have a new configuration file, build a kernel using that configuration file.

  1. Compile the kernel.
    # cd /usr/src
    # make buildkernel KERNCONF=KRNL1
    
  2. Wait for you kernel to build.

Step 6 – Verify you have enough space for the new kernel

  1. Make sure you have enough free space to install your kernel.Note: Your output may be quite different than mine.
    # df -ah
    Filesystem    Size    Used   Avail Capacity  Mounted on
    /dev/da0p2     74G    4.3G     64G     6%    /
    devfs         1.0k    1.0k      0B   100%    /dev
    
  2. If your root partion, /, has a capacity greater than 55%, you probably OK. Otherwise, your backup or kernel installation may fail.

Step 7 – Install the custom kernel

  1. Install the Kernel.
    # make installkernel KERNCONF=KRNL1
    
  2. Reboot the system.
    # reboot
    

You now have a custom kernel installed.

3 Comments

  1. FreeBSD: Build and Install a Custom Kernel...

        FreeBSD is a very powerful OS and you can even achieve higher performance by modifying the Kernel and only using the modules that you need. Before playing with the kernel you need to have the full FreeBSD source tree installed. The source...

  2. [...] steps are identical to the steps contained in the How to build and install a custom kernel on FreeBSD? article, with the exception of the kernel configuration [...]

  3. [...] and install a custom kernel on FreeBSD? Filed under: FreeBSD — rhyous @ 1:09 pm Read more Share this:DiggRedditLike this:LikeBe the first to like this post. Leave a [...]

Leave a Reply

Powered by sweetCaptcha