linux内核编译选项模块大小,Linux内核编译,模块尺寸变大的解决办法

本文探讨了Linux内核编译后模块大小增加的现象。通过对比不同内核版本的ext3.ko模块,发现新版本的模块大小显著增加。分析指出,这是由于默认配置支持更多硬件导致的。解决方法包括精简内核配置,移除不必要的驱动和选项,并在编译模块安装时使用INSTALL_MOD_STRIP=1选项来剥离调试符号,从而显著减小模块大小。
摘要由CSDN通过智能技术生成

现象:

最近在研究Linux的裁剪定制,编译内核的时候发现编译后同样的模块比以前内核版本的大好多,比如下面这个例子:

[root@CentOS5 ~]# find /lib/modules/ -name ext3.ko

/lib/modules/3.8.8-chensh3.0/kernel/fs/ext3/ext3.ko

/lib/modules/2.6.18-308.el5/kernel/fs/ext3/ext3.ko

[root@CentOS5 ~]# ll -h /lib/modules/3.8.8-chensh3.0/kernel/fs/ext3/ext3.ko

-rw-r--r-- 1 root root 3.7M 09-08 07:33 /lib/modules/3.8.8-chensh3.0/kernel/fs/ext3/ext3.ko

[root@CentOS5 ~]# ll -h /lib/modules/2.6.18-308.el5/kernel/fs/ext3/ext3.ko

-rwxr--r-- 1 root root 226K 2012-02-22 /lib/modules/2.6.18-308.el5/kernel/fs/ext3/ext3.ko

[root@CentOS5 ~]#

问题分析和解决办法:

The default kernel configuration is configured to support as many hardware as possible. A non-stripped kernel with default configuration resulted in a size of 1897996 kB (including kernel + modules). When stripping many unnecessary drivers and options, it resulted in a size of 892892 kB which is a size reduction of 53% compared to the stock kernel.

When installing the kernel modules, append the INSTALL_MOD_STRIP=1 option. This will strip all debugging symbols and reduced the size by 92% for me (from 892892 kB to 69356 kB). Note this will only affects modules to be installed and not the kernel (vmlinuz) itself.

Use the INSTALL_MOD_STRIP option for removing debugging symbols:

# make INSTALL_MOD_STRIP=1 modules_install

Similarly, for building the deb packages:

# make INSTALL_MOD_STRIP=1 deb-pkg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值