FreeBSD 8.0 Kernel Size Reduction

This document aims to customize the kernel for reducing its size and use additional files to cause the reduction.


du -cHA, top, perl files to compress the size of /bin and /sbin

The following table shows the effect of each kernel size changes

Different Changes


Kernel Size before Changing

Kernel Size After Changing


Useful Links


Machine Type Determination

145670 KB

143339 KB

2331 KB

Show Kernels Sizes

See Section1


143339 KB

142848 KB

491 KB

Show Kernels Sizes



142848 KB

141177 KB

1671 KB

Show Kernels Sizes


Using Dynamic Executables and Remove Static Ones

/bin ==> 971 KB & /sbin ==> 3607 KB

/bin ==> 971 KB & /sbin ==> 2978

629 KB

1.Size of /bin directory before applying Changes
2.Size of /sbin directory before applying changes
3.Show The directories sizes After Applying changes

See Section2

Sysctl maxusers=4

1./var ==> 70582 KB
2.Free Available Memory = 445

1./var ==> 70556 KB
2. Free Available Memory = 446

1. /var ==> 26 KB
2. For Available Memory = 1MB

Show /var Before Changing maxusers Sizes
Show /var Before Changing maxusers Sizes
Show /var After Changing maxusers Sizes
Show Available Memory at maxusers=243
Show /var Available Memory at maxusers=4

See Section3

Using Perl Files

/bin ==> 728 KB

/bin ==> 1367 KB

639 KB

Show /bin before using the perl file
Show /bin after using the perl file
Download perl files with snapshots

See Section4

Sysctl net.inet.tcp.msl="5000"

Does not affect kernel size




See Section5


There were three different machines loaded in the kernel configuration file and minimized to only the exact machine type.Be Careful, if you don't know your machine type, you may get a kernel crash.


  1. Steps : # cd /usr/src

    • # make buildworld
      # make buildkernel
      # make installkernel
      # shutdown -r now

    1. Notice that if you get any problem with your current binaries, you won't be able to retrieve the ones.


  1. You will face a problem in Kernel Building or compilation if you set maxusers to 2 & you were running X Windows System

  2. To use this at each boot process ==> I. recompile it inside the configuration file. or II. put it inside /etc/sysctl.conf


  1. Steps : # use names.files to include all the binaries you need

    • # run
      # you can use this command at startup by running it from load.conf file
      # don't forget to use the to compress all the files again and you can run it combined with the shutdown process
      # see snapshots for more details about how to run the document.
      # This process reduces the directory size for half the size approximately.

  2. The same process can be done for /sbin directory but don't forget to include the the sbins needed in the names.files file


Lessen max segment life to conserve resources ==> ACK waiting time in miliseconds to 5000

Important Notes

1. You can use extra kernel size reduction by using the options MUTEX_NOINLINE, RWLOCK_NOINLINE & SX_NOINLINE which reduce the kernel text segment.
2. Don't use any debug options when you recompile the kernel.
3. Don't try to remove any configurations used to mount root at kernel compilation process or you will face a problem during your next boot

4. You can perform only one executable for all bins using crunchgen().
5. Using -O3 debug option for CFLAGS or COPTFLAGS doesn't guarantee producing unbroken kernel so its better to avoid it.


FreeBSD Handbook

Comments and Suggestions

You can send your comments and suggestions to

CategoryHomepage CategoryHomepage

FreeBSD 8.0 Kernel Size Reduction (last edited 2010-07-30 21:15:35 by MohammedFarrag)