Table of Contents
Was this article helpful?

4  out of  4 found this helpful

Try Vultr Today with

$50 Free on Us!

Want to contribute?

You could earn up to $600 by adding new articles.

How to Build and Install a Custom Kernel on FreeBSD 11

Last Updated: Sun, May 21, 2017
Archived content

This article is outdated and may not work correctly for current operating systems or software.

By default, the FreeBSD operating system utilizes the GENERIC kernel; however, in this tutorial, we will recompile a FreeBSD kernel with a custom configuration known as: CUSTOM.


1) To follow this tutorial, deploy the following instance:

2) Once your instance is deployed, install sudo as the root user:

# pkg install -y sudo

3) Create a local user as a member of the wheel group and then issue a password:

# pw useradd test -g wheel

# passwd test

Changing local password for test

New Password:

Retype New Password:

4) Allow all members of the wheel group to execute any command

# visudo


# %wheel ALL=(ALL) ALL


%wheel ALL=(ALL) ALL

Save and exit by pressing the Esc key followed by typing:wq!

5) Change to the new user's shell

# su test


1. Obtaining the Source Code

In order to recompile the kernel, we must first obtain the source code from FreeBSD's version control system; in this case, subversion

$ sudo pkg install -y subversion


By default, the shell for new FreeBSD users is sh; however, we will need to change this to csh after installing subversion

1) Confirm the current user's shell:

$ echo $SHELL


2) Change the current user's shell to csh:

$ chsh -s /bin/csh


chsh: user information updated

3) Confirm the shell has changed for the current user:

$ grep test /etc/passwd

test:*:1001:0:User &:/home/test:/bin/csh


$ echo $SHELL


4) Now that the current user's shell is configured as csh, we can now rehash the directory tables:

$ rehash

5) Lastly, check out a copy of the latest stable branch to the /usr/src directory:

$ sudo svn co --trust-server-cert --non-interactive /usr/src


Checked out revision 317943.

2. Creating a CUSTOM Configuration

For our CUSTOM kernel configuration, we are going to copy the existing GENERIC configuration.

1) Copy GENERIC from the /usr/src/sys/amd64/conf/ directory as CUSTOM:

$ sudo cp /usr/src/sys/amd64/conf/GENERIC /usr/src/sys/amd64/conf/CUSTOM


Within our CUSTOM kernel configuration, we're going to make some changes.

2) Open /usr/src/sys/amd64/conf/CUSTOM:

$ sudo vi /usr/src/sys/amd64/conf/CUSTOM

On line 22, you will see an ident flag, line numbers can be seen in the vi editor by pressing the Esc key followed by typing:set nu

22 ident GENERIC

3) Change GENERIC to the name of your custom kernel; in this case CUSTOM:

22 ident CUSTOM

Moreover, at the bottom of the configuration, we're going to add the following:

options IPSEC


Once you're satisfied with your changes, save and exit again by pressing the Esc key followed by typing:wq!

Additional information for these various options can be found in the NOTES file for each type of architecture within the /usr/src/sys/ directory.

Below are a few of the common architecture NOTESlocation(s):

  • /usr/src/sys/amd64/conf/NOTES

  • /usr/src/sys/arm64/conf/NOTES

  • /usr/src/sys/i386/conf/NOTES

Architecture indepedent options can be referenced from /usr/src/sys/conf/NOTES

For further details, please see the FreeBSD Handbook.

3. Building and Installing your CUSTOM Kernel

We will now compile the CUSTOM kernel you've prepared.

1) Change to the /usr/src directory and issue a make buildkernel with the CUSTOM configuration file:

$ cd /usr/src

$ sudo make buildkernel KERNCONF=CUSTOM


Your estimated time until completion will vary depending on your instance's amount of resources.

For this tutorial, we utilized the following:

CPU:        4 vCore

RAM:        8192 MB

Storage:    100 GB SSD

With these resources, we finished compiling our CUSTOM kernel in ~ 4 hours:


>>> Kernel build for CUSTOM completed on Sat May 6 00:24:37 UTC 2017


2) Once your CUSTOM kernel has finished compiling, you can install the configuration:

$ sudo make installkernel KERNCONF=CUSTOM


Installing should complete much faster than compiling.

3) Once its finishing installing, reboot your instance:

$ sudo shutdown -r now


Your instance will now begin to shutdown and reboot into your CUSTOM kernel. You can login to your instance's console to observe the boot process.

4) Once your instance reboots, login and confirm that your CUSTOM kernel is being utilized:

$ sysctl kern.conftxt | grep ident

ident CUSTOM


$ uname -i


Want to contribute?

You could earn up to $600 by adding new articles.