A Guide To Customizing Your FreeBSD Kernel

Posted on

Hey there world! Archie here. I decided to start my blog from scratch, so this would be my first blog post. In this guide, I'll show y'all how to easily customize your kernel on the FreeBSD operating system.

Earlier On...

So, I recently upgraded my Wi-Fi card to the Intel AX210, thus ensuring great support, and I decided to try out FreeBSD on my laptop.

I had tinkered with the FreeBSD kernel in the past, but now that i have proper compatibility, I decided to customize my kernel, because, why not?

As you may know or not, my kernel config was named KITTY. Well, starting with the config:

Configuring The FreeBSD Kernel

Firstly, in the installer, make sure to select the system sources in the "distribution sets" dialog. If not, well, there's a way to get the sources, but I don't know. Now, I'm gonna assume your default processor architecture is amd64, too. You can check your current arch with uname -m. Once you've got the sources, go to:

/usr/src/sys/amd64/conf

and copy the "GENERIC" (default) kernel to the name you want:

cp GENERIC KITTY

Then, open your custom kernel config with the text editor of your choice:

vim KITTY

To change the name of your kernel, change the line that says:

ident GENERIC

to, e.g.:

ident KITTY

Here comes the fun part: you can start customizing it. To disable stuff, use the hash (#) symbol.

For example, to disable Wi-Fi, change:

device wlan

to:

#device wlan

Or just remove the corresponding "device" or "options" line entirely (though that is more advanced).

You can also compile in-kernel support for a device:

device ath

or as a module (this is called optional):

device ath optional ath

The possibilities are literally endless, as there's just so much stuff you can do with a custom kernel config. I don't know everything, but this should do as a basic kernel customization guide.

Installing Your Custom Kernel

When you finish configuring it, navigate to the /usr/src directory, and run:

sudo make buildkernel KERNCONF=KERNELCONFNAME

Replace "KERNELCONFNAME" with your kernel config name, e.g.:

sudo make buildkernel KERNCONF=KITTY

It will take a few minutes to a few hours, it all depends on your hardware. In my 13th Gen Intel Core i3-1315U, it always takes an hour, and less than a minute to rebuild it.

When it finishes, run:

sudo make installkernel KERNCONF=KERNELCONFNAME DESTDIR=/

Again, replace "KERNELCONFNAME" with your kernel config name:

make installkernel KERNCONF=KITTY DESTDIR=/

It will install the kernel at /boot/kernel/kernel, and a copy of the old kernel will be placed at /boot/kernel/kernel.old.

Then, reboot:

sudo reboot

Your new kernel will load automatically from loader(8). If not, boot with the old kernel and fix the config (usually it's because you're missing some essential device drivers or stuff). Then, recompile (it won't take that long), reinstall and reboot.

That's it for now, hope it has been useful, see ya next time, take care, luv u! <3

Go back to the blog's main index.