Custom FreeBSD Kernel compilation
at Monday, June 04, 2007
I normally use this way of building custom FreeBSD Kernel. Make sure that you are a root to continue with this.
Kernel source path:
Default path for FreeBSD kernel sources is /usr/src/sys. We can have kernel sources anywhere in the file system (it can be our home directories). I assume that the kernel sources are at /usr/src/sys in the below example.
Architecture:
Architecture can be i386, amd64, sparc etc. Through uname command you can find out the archicture under use. In the below example, I assume that the architecture is amd64.
Kernel Configuration:
Kernel configuration files are located at /usr/src/sys/amd64/conf directory. GENERIC is the kernel configuration which will be used most of the time. You can add or delete certain configurations based on the requirement. Some of the configurations which will be enabled in CURRENT (pre-release) and which result in reduced performance are WITNESS, INVARIANTS, DIAGNOSTIC etc. To build kernel excluding some options either remove those lines or comment out them (by prefixing a # symbol at the start of line). It is a good practice to have a copy of original GENERIC file. So I prefer to have a copy of it and update new file rather than GENERIC file itself.
I assume that the new configuration file has name "MYKERNEL". Run "config MYKERNEL" in /usr/src/sys/amd64/conf directory. This creates a directory with name "MYKERNEL" (name same as kernel configuration file) under compile in architecture directory. Now, change directory to "/usr/src/sys/amd64/compile/MYKERNEL" directory. Run "make cleandepend && make depend && make" to build kernel.
If there are any failures in any of those steps, you will get built kernel in the same directory. You can install newly built kernel using "make install" in the same directory. Reboot now, to boot your machine with newly build kernel.
Kernel source path:
Default path for FreeBSD kernel sources is /usr/src/sys. We can have kernel sources anywhere in the file system (it can be our home directories). I assume that the kernel sources are at /usr/src/sys in the below example.
Architecture:
Architecture can be i386, amd64, sparc etc. Through uname command you can find out the archicture under use. In the below example, I assume that the architecture is amd64.
Kernel Configuration:
Kernel configuration files are located at /usr/src/sys/amd64/conf directory. GENERIC is the kernel configuration which will be used most of the time. You can add or delete certain configurations based on the requirement. Some of the configurations which will be enabled in CURRENT (pre-release) and which result in reduced performance are WITNESS, INVARIANTS, DIAGNOSTIC etc. To build kernel excluding some options either remove those lines or comment out them (by prefixing a # symbol at the start of line). It is a good practice to have a copy of original GENERIC file. So I prefer to have a copy of it and update new file rather than GENERIC file itself.
I assume that the new configuration file has name "MYKERNEL". Run "config MYKERNEL" in /usr/src/sys/amd64/conf directory. This creates a directory with name "MYKERNEL" (name same as kernel configuration file) under compile in architecture directory. Now, change directory to "/usr/src/sys/amd64/compile/MYKERNEL" directory. Run "make cleandepend && make depend && make" to build kernel.
If there are any failures in any of those steps, you will get built kernel in the same directory. You can install newly built kernel using "make install" in the same directory. Reboot now, to boot your machine with newly build kernel.




