====== 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 | [[https://www.opendrive.com/files/6728801_z8i8B_0ee6|Show Kernels Sizes]] | See Section1 | | MSDOSFS, UFS_DIRHASH, UFS_GJOURNAL | 143339 KB | 142848 KB | 491 KB | [[https://www.opendrive.com/files/6728797_8zmzz_6ade|Show Kernels Sizes]] | -- | | INET6, SYSVSHM, SYSVMSG, SYSVSEM, KTRACE | 142848 KB | 141177 KB | 1671 KB | [[https://www.opendrive.com/files/6728786_Px3vp_90ef|Show Kernels Sizes]] | -- | | Using Dynamic Executables and Remove Static Ones | /bin ==> 971 KB & /sbin ==> 3607 KB | /bin ==> 971 KB & /sbin ==> 2978 | 629 KB | [[https://www.opendrive.com/files/6728764_5rv98_763e|1.Size of /bin directory before applying Changes]]\\ [[https://www.opendrive.com/files/6728765_ZN7uj_43be|2.Size of /sbin directory before applying changes]] \\ [[https://www.opendrive.com/files/6728763_pZURj_9849|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 | [[https://www.opendrive.com/files/6728735_1LDXp_8146|Show /var Before Changing maxusers Sizes]] \\ [[https://www.opendrive.com/files/6728735_1LDXp_8146|Show /var Before Changing maxusers Sizes]]\\ [[https://www.opendrive.com/files/6728691_H88Gn_ac0c|Show /var After Changing maxusers Sizes]] \\ [[https://www.opendrive.com/files/6728737_q6emt_eb56|Show Available Memory at maxusers=243]] \\ [[https://www.opendrive.com/files/6728738_jJDlU_02f8|Show /var Available Memory at maxusers=4]] | See Section3 | | Using Perl Files | /bin ==> 728 KB | /bin ==> 1367 KB | 639 KB | [[https://www.opendrive.com/files/6728800_kIzJ5_27ac|Show /bin before using the perl file]] \\ [[https://www.opendrive.com/files/6728799_133al_9ab1|Show /bin after using the perl file]] \\ [[http://www.mediafire.com/?acq2iy7nq66ayyc|Download perl files with snapshots]] | 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 ===== [[http://www.freebsd.org/doc/en/books/handbook/index.html|FreeBSD Handbook]]\\ ===== Comments and Suggestions ===== You can send your comments and suggestions to * Published by: [[/MohammedFarrag|MohammedFarrag]] * Reviewed by: [[/WarnerLosh|WarnerLosh]]