FreeBSD is a free Unix-like operating system descended from Research Unix via the Berkeley Software Distribution (BSD). Although for legal reasons FreeBSD cannot use the Unix trademark, it is a direct descendant of BSD, which was historically also called “BSD Unix” or “Berkeley Unix”. The first version of FreeBSD was released in 1993, and today FreeBSD is the most widely used open-source BSD distribution, accounting for more than three-quarters of all installed systems running open-source BSD derivatives.

FreeBSD has similarities with Linux, with two major differences in scope and licensing: FreeBSD maintains a complete operating system, i.e. the project delivers kernel, device drivers, userland utilities and documentation, as opposed to Linux delivering a kernel and drivers only and relying on third-parties for system software and FreeBSD source code is generally released under a permissive BSD license as opposed to the copyleft GPL.

It uses the GENERIC kernel by default. FreeBSD’s kernel provides support for some essential tasks such as managing processes, communication, booting and filesystems. In this article, we will show you how you can recompile a FreeBSD kernel with a custom configuration.

Some Features of FreeBSD and kernel

From the different features we can list the following ones:

FreeBSD 10.0 now supports a truly tickless kernel, enhancing battery performance on laptops and general resource effectiveness in virtual machines.

FreeBSD 10.0 brings with it support for ZFS TRIM and it also supports LZ4 compression support which compresses much better (up to 50%) than the default LZJB compression

BSD-kernel are not stand-alone kernels but are developed as being part of a whole. Of course, this is merely a philosophical point of view and not a technical one, but this give system coherence

Prerequisites

As prerequisites for this article you need to need just to have a one FreeBSD 10.1 Droplet to be able to use the following commands; we assume that you are a FreeBSD user.

Recompile A FreeBSD Kernel

We will start by getting the operating system source code. As a characteristic of FreeBSD its ability to provide the source code to its operating system to be able to modify and download the source code easily. And to be able to recompile the kernel you have to use the following command in order to pull this source code from FreeBSD’s control system:

sudo pkg install subversion

Then you have to use the following command to rearrange the directory tables since the FreeBSD’s shell utilizes an internel hash table for commands in $PATH:

rehash

Then use the following command to check out the latest stable branch to the /usr/src directory.

sudo svn co https://svn0.us-east.FreeBSD.org/base/stable/10 /usr/src

You will be asked to accept the server certificate type the “p” command to accept it. Now we will create our custom configuration for kernel. We will call our configuration CONF_anis you have the choice to choose another name of course. The kernel configuration files are in the /usr/src/sys/architecture/conf directory.

So move to the configuration directory using the following command:

cd /usr/src/sys/amd64/conf

Then use the following command to create and open the CONF_anis file in order to edit it:

Now we will start the installation of our new Kernel. So we will move to the /usr/src directory and use the following commands to use our new configuration file:

cd /usr/src
sudo make buildkernel KERNCONF=CONF_anis

It will require some time to finish that. As example of average equation for a 0.5 GB Droplet you need 45 minutes. After finishing your kernel recompilation, use the following command to start the installation:

sudo make installkernel KERNCONF=CONF_anis

After making the installation of your new system to reboot it, use the following command:

sudo shutdown -r now

And to check the functionality of your new kernel configuration use the following command:

sysctl kern.conftxt | grep ident

To be sure that everything works good you have to receive something like this:

ident CONF_anis

Conclusion

In this article we explained for you how you can get a compiled and configured kernel. Now you get it and everything works good if you received the final message while checking the functionality of your system