Solved Building the kernel after small changes?

Hello!
I use FreeBSD 13.0 stable and I followed the instructions from the book FreeBSD Developers' Handbook Revision: eab1c5d1f6 2021-01-12 19:33:23. Chapter 9. Building and Installing a FreeBSD Kernel.
I've managed to compile a custom kernel before, but I can't figure out how to compile it when I make small changes. I have followed the instructions in the above chapter but the document appears to be out of date:
Code:
1. Run config(8) to generate the kernel source code:
# /usr/sbin/config MYKERNEL
2. Change into the build directory. config(8) will print the name of this directory after being run as above.
# cd ../compile/ MYKERNEL
3. Compile the kernel:
# make depend
# make
After running:
:/usr/src # /usr/sbin/config /usr/src/sys/i386/conf/MYKERNEL
I get
Specify machine type, e.g. ``machine i386''
I read man for config() and tried various combinations and I can't handle it?
 
Thank you all very much!
As soon as I have time, I will try everything you gave me here, so I will report the results.

I did my best to find a solution before I asked for help here. I'm ashamed I didn't come across this Thread 51888.
 
The result from two ways after small changes at some x.c file:

1.
Code:
:/usr/src # make -j4 buildkernel -DKERNFAST KERNCONF=MYKERN
--------------------------------------------------------------
>>> Kernel(s)  MYKERN built in 90 seconds, ncpu: 2, make -j4
--------------------------------------------------------------

2. making file /etc/src-env.conf with content: WITH_META_MODE=YES
Code:
:/usr/src # kldload filemon
:/usr/src # make -j4 buildkernel KERNCONF=MYKERN
--------------------------------------------------------------
>>> Kernel(s)  MYKERN built in 74 seconds, ncpu: 2, make -j4
--------------------------------------------------------------
So the second way is a little bit faster.
 
Last edited by a moderator:
During my experiments, when I often change one file and compile it without linking, I discovered another faster way where compilation takes about 1-3 seconds.
Namely, after the first time where I definitely have to compile the source code of the kernel, I do it in the way number 2. as shown in the previous post.
2. making file /etc/src-env.conf with content: WITH_META_MODE=YES
Code:
:/usr/src # kldload filemon
:/usr/src # make -j4 buildkernel KERNCONF=MYKERN
Everywhere in the /usr/obj/ folders appear *.meta files containing all the information about the compilation and path for compiled objects. For example, if I frequently configure and compile the file /usr/src/sys/i386/i386/locore.s,
then I go to the folder /usr/obj/usr/src/i386.i386/sys/MYKERN where Makefile is already formed and I just set the:
Code:
:/usr/obj/usr/src/i386.i386/sys/MYKERN # make locore.o
The compilation takes a few seconds and you immediately see the errors or it is successful. This method is very useful for me as a beginner and speeds up development on my weak machine. When I compile it without errors, I can run general make that links it where needed:
Code:
:/usr/src # make -j4 buildkernel KERNCONF=MYKERN
--------------------------------------------------------------
>>> Kernel(s) MYKERN built in 74 seconds, ncpu: 2, make -j4
--------------------------------------------------------------
Forgive my beginner's "courage". Maybe this is a funny way, but it is useful to me and I hope it will be useful to someone else.
 
There's nothing to forgive; that's how you learn. Do enjoy.
It's reasonable approach. Recently I spent few hours in stand/ and I noticed my changes were not always propagated properly. I had to remove stand/ from obj/ to make it happen. Didn't find out why, my focus was on a problem itself.
With WITH_META_MODE I suggested I was able to get reasonable times in my VM too.

If I'm not patient enough to wait I tend to build kernel on my stronger machine and rsync the results back to VM for debugging. I'm not saying it's perfect but it's a way. :) Especially on a same architecture.
 
The "FreeBSD entry point" to metamode or meta mode or META_MODE is:
Meta mode (and its origins) explained by Simon Gerraty (text & video), you can find here. FreeBSD make(1) has a rich history involving pmake & bmake & fmake & make; it may be helpfull to know how they relate to each other when using the references in the wiki.
 
Back
Top