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.
Tools
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 |
|||||
Change |
Kernel Size before Changing |
Kernel Size After Changing |
Difference |
Useful Links |
Notes |
Machine Type Determination |
145670 KB |
143339 KB |
2331 KB |
See Section1 |
|
MSDOSFS, UFS_DIRHASH, UFS_GJOURNAL |
143339 KB |
142848 KB |
491 KB |
-- |
|
INET6, SYSVSHM, SYSVMSG, SYSVSEM, KTRACE |
142848 KB |
141177 KB |
1671 KB |
-- |
|
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 |
See Section2 |
Sysctl maxusers=4 |
1./var ==> 70582 KB |
1./var ==> 70556 KB |
1. /var ==> 26 KB |
Show /var Before Changing maxusers Sizes |
See Section3 |
Using Perl Files |
/bin ==> 728 KB |
/bin ==> 1367 KB |
639 KB |
Show /bin before using the perl file |
See Section4 |
Sysctl net.inet.tcp.msl="5000" |
Does not affect kernel size |
-- |
-- |
-- |
See Section5 |
Section1
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.
Section2
Steps : # cd /usr/src
# make buildworld
# make buildkernel
# make installkernel
# shutdown -r now
- Notice that if you get any problem with your current binaries, you won't be able to retrieve the ones.
Section3
You will face a problem in Kernel Building or compilation if you set maxusers to 2 & you were running X Windows System
To use this at each boot process ==> I. recompile it inside the configuration file. or II. put it inside /etc/sysctl.conf
Section4
Steps : # use names.files to include all the binaries you need
# run loadbin.pl
# you can use this command at startup by running it from load.conf file
# don't forget to use the termination.pl 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.
- The same process can be done for /sbin directory but don't forget to include the the sbins needed in the names.files file
Section5
Lessen max segment life to conserve resources ==> ACK waiting time in milliseconds to 5000
Important Notes
You can use extra kernel size reduction by using the options MUTEX_NOINLINE, RWLOCK_NOINLINE & SX_NOINLINE which reduce the kernel text segment.
- Don't use any debug options when you recompile the kernel.
- 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 Some of these processes are FFS, GEOM_GPT, ..etc
- You can perform only one executable for all bins using crunchgen().
- Using -O3 debug option for CFLAGS or COPTFLAGS doesn't guarantee producing unbroken kernel so its better to avoid it.
Resources
Comments and Suggestions
You can send your comments and suggestions to <mfarrag AT FreeBSD DOT org>
Published by: MohammedFarrag
Reviewed by: WarnerLosh