{"id":5966,"date":"2026-07-10T20:46:29","date_gmt":"2026-07-11T00:46:29","guid":{"rendered":"https:\/\/dft.wiki\/?p=5966"},"modified":"2026-07-10T15:01:13","modified_gmt":"2026-07-10T19:01:13","slug":"compiling-and-running-a-kernel-linux-and-freebsd","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=5966","title":{"rendered":"Compiling and Running a Kernel &#8211; Linux and FreeBSD"},"content":{"rendered":"<p>Compiling a custom FreeBSD kernel gives you the ability to bake in specific drivers and modules, or tweak settings from what ships out of the box.<\/p>\n<p>This guide covers pulling the source, configuring, compiling, and running your own Linux and FreeBSD kernels.<\/p>\n<hr \/>\n<p><strong>DEBIAN-BASED DISTROS<\/strong><\/p>\n<p>Install dependencies and get the source code.<\/p>\n<pre>sudo apt update\r\nsudo apt install build-essential libncurses-dev bison flex libssl-dev libelf-dev bc ccache dwarves git\r\ngit clone --depth 1 --branch v7.1 https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/stable\/linux.git \/usr\/src\/linux\r\ncd \/usr\/src\/linux<\/pre>\n<p>Configure the kernel.<\/p>\n<pre>cp \/boot\/config-$(uname -r) .config\r\nscripts\/config --disable SYSTEM_TRUSTED_KEYS\r\nscripts\/config --disable SYSTEM_REVOCATION_KEYS\r\nmake olddefconfig\r\nmake menuconfig<\/pre>\n<p>Compile and install the kernel and modules.<\/p>\n<pre>make -j$(nproc)\r\nsudo make modules_install\r\nsudo make install<\/pre>\n<p>Update GRUB (bootloader).<\/p>\n<pre>sudo update-grub<\/pre>\n<p>Reboot and verify.<\/p>\n<pre>sudo reboot\r\nuname -r<\/pre>\n<hr \/>\n<p><strong>FREEBSD<\/strong><\/p>\n<p>Get the source code.<\/p>\n<pre>pkg install git-lite\r\ngit clone --branch releng\/15.1 https:\/\/git.freebsd.org\/src.git \/usr\/src<\/pre>\n<p>Create your custom configuration.<\/p>\n<pre>cd \/usr\/src\/sys\/amd64\/conf\r\ncp GENERIC MYKERNEL\r\nnano MYKERNEL<\/pre>\n<p>Compile the kernel.<\/p>\n<pre>cd \/usr\/src\r\nmake buildkernel KERNCONF=MYKERNEL -j$(sysctl -n hw.ncpu)<\/pre>\n<p>Install the kernel.<\/p>\n<pre>make installkernel KERNCONF=MYKERNEL<\/pre>\n<p>Reboot and verify.<\/p>\n<pre>shutdown -r now\r\nuname -a<\/pre>\n<hr \/>\n<p><strong>REFLECTIONS<\/strong><\/p>\n<p><strong>For Both<\/strong><\/p>\n<p>While the kernel itself is monolithic, both operating systems support Kernel Objects (<strong>.ko<\/strong> files) that can be loaded at boot time or at runtime (<code>modprobe<\/code> on Linux, <code>kldload<\/code> on FreeBSD) to extend functionality without requiring recompilation each time.<br \/>\n<strong>For Linux<\/strong><br \/>\nThe kernel (<code>\/boot<\/code>) and its modules (<code>\/lib\/modules\/<\/code>) live in two separate parts of the filesystem.<br \/>\nLinux also creates an <code>initramfs<\/code> \/ <code>initrd<\/code> (Initial RAM Filesystem): a small, temporary root filesystem loaded into RAM that contains just enough .ko drivers to initialize your storage and hand off control to the real root filesystem.<br \/>\n<strong>For FreeBSD<\/strong><br \/>\nThe kernel and its modules are kept together in a single directory (<code>\/boot\/kernel\/<\/code>).<br \/>\nThe kernel itself is the core monolithic binary, but you will also find many <strong>.ko<\/strong> files alongside it for loadable drivers (e.g., <code>zfs.ko<\/code> for the ZFS filesystem).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Compiling a custom FreeBSD kernel gives you the ability to bake in specific drivers and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-5966","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/5966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5966"}],"version-history":[{"count":5,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/5966\/revisions"}],"predecessor-version":[{"id":5972,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/5966\/revisions\/5972"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}