Clean kernel ompilation

  • In this section, you are going to learn

  • How to do clean kernel compilation

#

Version

Freebsd

14.1.0

  • To compile the kernel source code user should change the user access to root previlege mode

  • Execute below command to redirect to root access

test:~$ su
  • Run the below command to change the directory to kernel source code location

test:~$ cd /usr/src/
  • Note: By Default “/usr/src directory contain the exist version kernel source code. if you want to compile from externally, follow steps 3.1 and 3.2

test:~$ rm -rf /usr/src/* & rm -rf /usr/src/.*

test:~$ cd /usr
  • NOTE: git branch name “release/14.1.0” is for user validate. Based on user requirement clone the respective branch and compile it.

test:~$ git clone -b release/14.1.0 https://github.com/freebsd/freebsd-src.git
  • Copy all the directories and files from freebsd-src to src directory

test:~$ cp -rf freebsd-src/* src/ & cp -rf freebsd-src/.* src/
  • Run the below command to move to the sys directory

test:~$ cd /sys
  • Run the below command to move to the platform directory

  • Many platform source code available in the “/usr/src/sys” directory, based on requirement select platform directory and compile it.

test:~$ cd amd64
  • Run the below command to move to the conf directory

test:~$ cd conf
  • TESTCONF is custom configuration file name, you can mention any name

test:~$ cp GENERIC TESTCONF
  • Modify the configuration file which is required for the systems

  • Open TESTCONF file and add copy below lines to TESTCONF file

test:~$ vi TESTCONF

ident       GENERIC
ident       TESTCONF
test:~$ cd /usr/src/
  • Run below command to build the kernel source code

test:~$ make -j8 buildkernel KERNCONF=TESTCONF
  • Before running make command take backup of the all prebuild modules and binaries

test:~$ cp -rf /boot/kerenel /boot/kernel_14_1_0

test:~$ make -j8 installkernel KERNCONF=TESTCONF
  • Reboot the system

  • Once kernel loaded run the below command and confirm, system loaded with proper kernel changes

  • Observe the Configuration file name will appear on this line

test:~$ uname -a
FreeBSD sysadmin 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 TESTCONF amd64
  • Run kldstat command to check the loaded module on systems

test:~$ kldstat
Id Refs Address                Size Name
 1   29 0xffffffff80200000  1f6c698 kernel
 2    1 0xffffffff8216d000     7850 cryptodev.ko
 3    1 0xffffffff82176000   772c70 zfs.ko
 4    1 0xffffffff83218000     3220 intpm.ko
 5    1 0xffffffff8321c000     2178 smbus.ko
 6    1 0xffffffff8321f000     3360 uhid.ko
 7    1 0xffffffff83223000     3360 wmt.ko
test:~$ ps
  PID TT  STAT    TIME COMMAND
89708 v0  Is+  0:00.00 /usr/libexec/getty Pc ttyv0
89952 v1  Is+  0:00.00 /usr/libexec/getty Pc ttyv1
90039 v2  Is+  0:00.00 /usr/libexec/getty Pc ttyv2
90117 v3  Is+  0:00.00 /usr/libexec/getty Pc ttyv3
90205 v4  Is+  0:00.00 /usr/libexec/getty Pc ttyv4
90556 v5  Is+  0:00.00 /usr/libexec/getty Pc ttyv5
90630 v6  Is+  0:00.00 /usr/libexec/getty Pc ttyv6
91095 v7  Is+  0:00.00 /usr/libexec/getty Pc ttyv7
14538  0  I    0:00.01 su
14664  0  I+   0:00.05 su (sh)
12462  1  S    0:00.01 su
12586  1  S    0:00.01 su (sh)
12895  1  R+   0:00.00 ps
test:~$ ifconfig
wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=0
ether 0c:9a:3c:9f:17:71
inet 192.168.3.20 netmask 0xffffff00 broadcast 192.168.3.255
groups: wlan
ssid TP_link_11ax_5G channel 36 (5180 MHz 11a) bssid 50:d4:f7:00:51:de
regdomain FCC country US authmode WPA2/802.11i privacy ON
deftxkey UNDEF AES-CCM 2:128-bit txpower 17 bmiss 7 mcastrate 6
mgmtrate 6 scanvalid 60 wme roaming MANUAL
parent interface: iwlwifi0
media: IEEE 802.11 Wireless Ethernet OFDM/36Mbps mode 11a
status: associated
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
test:~$ ifconfig
em0: flags=1008843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500
options=60251b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,TSO4,LRO,WOL_MAGIC,RXCSUM_IPV6,TXCSUM_IPV6>
ether 7c:8a:e1:98:43:82
inet 10.91.229.72 netmask 0xffffff00 broadcast 10.91.229.255
inet6 fe80::7e8a:e1ff:fe98:4382%re0 prefixlen 64 scopeid 0x1
media: Ethernet autoselect (100baseTX <full-duplex>)
status: active
nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>