linux 内核代码精简

本文介绍了一种用于Linux内核编译的方法,并详细说明了如何通过特定的命令来更新文件的时间戳,选择合适的配置选项进行调试,以及如何在编译完成后清理不必要的文件以节省磁盘空间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#为了提高性能,文件系统一般都是以 relatime形式挂载进来的,见:/etc/fstab
#更新一下mtime,这样,编译过程中用到的文件的atime都会被更新
find . -exec touch -m {} \; && touch ../tag

make mrproper && make allnoconfig && make menuconfig
#在allnoconfig的基础下,通过menuconfig加入如下配置,以方便调试
************************************************************
General setup
  --Initial RAM filesystem and RAM disk (initramfs/initrd) support
Executable file formats / Enulations
  --Kernel support for ELF binaries
Networking support
Kernel hacking
  --Kernel debugging
  --Compile the kernel with debug info
  --Compile the kernel with frame pointers
************************************************************

make #编译,大约需要10分钟

#删除编译过程中没有用到的文件 
find . -type f ! -anewer ../tag | grep -v '/\.svn' | xargs rm

#删除所有空目录
loop=found; while [ ! -z $loop ]; do loop=$(find . -type d | grep -v '/\.svn' | while read dirname; do cnt=$(ls $dirname | wc -l); if [ 0 -eq $cnt ]; then rm -rf $dirname; echo -n found; fi; done;); done;

结果上面处理的代码可以再次变量

清理不包含源文件和头文件的目录:
find . -type d | while read dirname; do cnt=`find $dirname -name '*.[cSh]' | wc -l`; if [ 0 -eq $cnt ]; then rm -rf $dirname; fi; done;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值