Blog by Saw Win Naung

Official

Building Freebsd Kernel


Building and installing freebsd custom kernel

Freebsd used a monolithic kernel which contained modules that can be load dynamically.Freebsd come with GENERIC kernel which support wide range of hardware.Building custom kernel can tailored to your system.Which can make faster boot time and lower memory usage.That’s why some people build custom kernel.

List down System Hardware

First need to perform inventory of system. When freebsd was booted use dmesg to find system hardweare. Example

bge0: <Broadcom NetXtreme Gigabit Ethernet Controller, ASIC rev. 0x006002> mem 0xefcf0000-0xefcfffff irq 18 at device 0.0 on pci2
bge0: CHIP ID 0x00006002; ASIC REV 0x06; CHIP REV 0x60; PCI-E
miibus0: <MII bus> on bge0

Another tool pciconf for finding hardware provide more info. Example

# pciconf -lv
bge0@pci0:9:0:0:        class=0x020000 card=0x02011028 chip=0x160014e4 rev=0x02 hdr=0x00
    vendor     = 'Broadcom Limited'
    device     = 'NetXtreme BCM5752 Gigabit Ethernet PCI Express'
    class      = network
    subclass   = ethernet

Config and Compile

Kernel config file was located in /usr/src/sys/amd64/conf it’s depen on architecture. If /usr/src/ doesn’t exit, need to install source using svn as this guide. Copy GENERIC to different name then edit this. Remove unnecessary in config and compile with make buildkernel KERNCONF=swnkernel

Install

# cd /usr/src
# make buildkernel KERNCONF=MYKERNEL
# make installkernel KERNCONF=MYKERNEL

Shutdown or reboot if your kernel doesn’t boot reboot with old kernel and fix the errror.

ref:https://www.freebsd.org/doc/handbook/