恩山无线论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 359|回复: 5

分享个精简ipk包的shell脚本用来精简固件

[复制链接]
发表于 2020-2-16 19:33 | 显示全部楼层 |阅读模式
本帖最后由 dato 于 2020-2-16 20:36 编辑

本教程适合喜欢openwr.org官方固件,完全掌握了使用imagebuilder生成自定义固件的高级玩家。像咱这种菜鸟只会删软件包,还到达不了从源码精简掉help文件那种要求。
以前都是本地用7zip下载回来删除再上传回vps,无奈最近网络实在太慢了,今天花了点时间折腾了一下,挺好。这种比官方的好用,官方的方法做出来的固件最后用7zip是无法打开的。

使用方法
1,定义好自己需要精简的包
格式为
IPKrm stunnel  #用于shell grep IPKrm处理快速生成列表
stunnel.conf libstunnel.so ./usr/lib #定义需要删除的文件,目录以空格做分隔,保持1行用tr生成排除列表

2,将代码复制到imagebuilder/packages目录里处理就可以了,处理好的文件放在packages/IPKG_REBUILD目录
3,如果确认没问题就可以通过 cp -a IPKG_REBUILD/* ./packages 覆盖同名文件
4,重新用imagebuilder生成固件就可以了。

脚本对完整*.ipk解包data.tar.gz,排除掉不需要的文件重新打包成data.tar.gz,再重新打包成精简*.ipk。
通过删除不需要的文件来达到精简固件的目的。

原始脚本以及使用说明下载 精简ipk脚木.zip (1.02 KB, 下载次数: 0)
我的恩山、我的无线 The best wifi forum is right here.
 楼主| 发表于 2020-2-16 19:36 | 显示全部楼层
openwrt的原始方法,大家可以参考一下,最大的问题做完的镜像用7zip无法打开

  1. ===根目录建立files_remove
  2. 1. Create file 'files_remove' with full filenames:

  3. cat << EOF > ./files_remove1
  4. #多余目录
  5. /usr/lib/opkg/status
  6. #/usr/lib/opkg/info/*.list
  7. /usr/lib/opkg/info/*.control
  8. /usr/lib/opkg/info/*-pkg
  9. /usr/lib/opkg/info/*.conffiles
  10. /usr/lib/opkg/info/*.prerm
  11. #luci-mod-admin-full
  12. #/etc/uci-defaults/50_luci-mod-admin-full
  13. #/usr/bin/luci-bwc
  14. #/usr/lib/lua/luci/controller/admin/filebrowser.lua
  15. #/usr/lib/lua/luci/controller/admin/index.lua
  16. #/usr/lib/lua/luci/controller/admin/network.lua
  17. #/usr/lib/lua/luci/controller/admin/status.lua
  18. #/usr/lib/lua/luci/controller/admin/system.lua
  19. #/usr/lib/lua/luci/controller/admin/uci.lua
  20. /usr/lib/lua/luci/model/cbi/admin_network/dhcp.lua
  21. /usr/lib/lua/luci/model/cbi/admin_network/hosts.lua
  22. #/usr/lib/lua/luci/model/cbi/admin_network/iface_add.lua
  23. #/usr/lib/lua/luci/model/cbi/admin_network/ifaces.lua
  24. #/usr/lib/lua/luci/model/cbi/admin_network/network.lua
  25. #/usr/lib/lua/luci/model/cbi/admin_network/proto_ahcp.lua
  26. #/usr/lib/lua/luci/model/cbi/admin_network/routes.lua
  27. /usr/lib/lua/luci/model/cbi/admin_network/vlan.lua
  28. #/usr/lib/lua/luci/model/cbi/admin_network/wifi.lua
  29. #/usr/lib/lua/luci/model/cbi/admin_network/wifi_add.lua
  30. #/usr/lib/lua/luci/model/cbi/admin_status/processes.lua
  31. #/usr/lib/lua/luci/model/cbi/admin_system/admin.lua
  32. #/usr/lib/lua/luci/model/cbi/admin_system/backupfiles.lua
  33. #/usr/lib/lua/luci/model/cbi/admin_system/buttons.lua
  34. #/usr/lib/lua/luci/model/cbi/admin_system/crontab.lua
  35. /usr/lib/lua/luci/model/cbi/admin_system/fstab.lua
  36. /usr/lib/lua/luci/model/cbi/admin_system/fstab/mount.lua
  37. /usr/lib/lua/luci/model/cbi/admin_system/fstab/swap.lua
  38. /usr/lib/lua/luci/model/cbi/admin_system/ipkg.lua
  39. #/usr/lib/lua/luci/model/cbi/admin_system/leds.lua
  40. #/usr/lib/lua/luci/model/cbi/admin_system/startup.lua
  41. #/usr/lib/lua/luci/model/cbi/admin_system/system.lua
  42. #/usr/lib/lua/luci/view/admin_network/diagnostics.htm
  43. #/usr/lib/lua/luci/view/admin_network/iface_overview.htm
  44. #/usr/lib/lua/luci/view/admin_network/iface_status.htm
  45. #/usr/lib/lua/luci/view/admin_network/lease_status.htm
  46. /usr/lib/lua/luci/view/admin_network/switch_status.htm
  47. #/usr/lib/lua/luci/view/admin_network/wifi_join.htm
  48. #/usr/lib/lua/luci/view/admin_network/wifi_overview.htm
  49. #/usr/lib/lua/luci/view/admin_network/wifi_status.htm
  50. #/usr/lib/lua/luci/view/admin_status/bandwidth.htm
  51. #/usr/lib/lua/luci/view/admin_status/connections.htm
  52. #/usr/lib/lua/luci/view/admin_status/dmesg.htm
  53. #/usr/lib/lua/luci/view/admin_status/index.htm
  54. #/usr/lib/lua/luci/view/admin_status/iptables.htm
  55. #/usr/lib/lua/luci/view/admin_status/load.htm
  56. #/usr/lib/lua/luci/view/admin_status/routes.htm
  57. #/usr/lib/lua/luci/view/admin_status/syslog.htm
  58. #/usr/lib/lua/luci/view/admin_status/wireless.htm
  59. #/usr/lib/lua/luci/view/admin_system/applyreboot.htm
  60. #/usr/lib/lua/luci/view/admin_system/backupfiles.htm
  61. #/usr/lib/lua/luci/view/admin_system/clock_status.htm
  62. #/usr/lib/lua/luci/view/admin_system/flashops.htm
  63. /usr/lib/lua/luci/view/admin_system/ipkg.htm
  64. /usr/lib/lua/luci/view/admin_system/packages.htm
  65. #/usr/lib/lua/luci/view/admin_system/reboot.htm
  66. #/usr/lib/lua/luci/view/admin_system/upgrade.htm
  67. #/usr/lib/lua/luci/view/admin_uci/apply.htm
  68. #/usr/lib/lua/luci/view/admin_uci/changelog.htm
  69. #/usr/lib/lua/luci/view/admin_uci/changes.htm
  70. #/usr/lib/lua/luci/view/admin_uci/revert.htm
  71. #/usr/lib/lua/luci/view/cbi/wireless_modefreq.htm
  72. #/www/luci-static/resources/bandwidth.svg
  73. #/www/luci-static/resources/connections.svg
  74. #/www/luci-static/resources/load.svg
  75. #/www/luci-static/resources/wifirate.svg
  76. #/www/luci-static/resources/wireless.svg
  77. #luci-app-firewall
  78. #/usr/lib/lua/luci/controller/firewall.lua
  79. #/usr/lib/lua/luci/model/cbi/firewall/custom.lua
  80. #/usr/lib/lua/luci/model/cbi/firewall/forward-details.lua
  81. #/usr/lib/lua/luci/model/cbi/firewall/forwards.lua
  82. #/usr/lib/lua/luci/model/cbi/firewall/rule-details.lua
  83. #/usr/lib/lua/luci/model/cbi/firewall/rules.lua
  84. #/usr/lib/lua/luci/model/cbi/firewall/zone-details.lua
  85. #/usr/lib/lua/luci/model/cbi/firewall/zones.lua
  86. #/usr/lib/lua/luci/tools/firewall.lua
  87. #/usr/lib/lua/luci/view/firewall/cbi_addforward.htm
  88. #/usr/lib/lua/luci/view/firewall/cbi_addrule.htm
  89. #/usr/lib/lua/luci/view/firewall/cbi_addsnat.htm
  90. #usign
  91. #/usr/bin/usign
  92. #/usr/bin/signify
  93. #mtd
  94. /sbin/mtd
  95. #hostapd-utils
  96. #/usr/sbin/hostapd_cli
  97. /etc/rc.button/wps
  98. #dnsmasq
  99. /etc/dnsmasq.conf
  100. /etc/config/dhcp
  101. /etc/hotplug.d/ntp/25-dnsmasqsec
  102. /etc/init.d/dnsmasq
  103. /usr/sbin/dnsmasq
  104. #logd
  105. #/sbin/logread
  106. #/sbin/logd
  107. #/etc/init.d/log
  108. #kmod-ppp
  109. /lib/modules/4.9.120/ppp_generic.ko
  110. /etc/modules.d/ppp
  111. /lib/modules/4.9.120/ppp_async.ko
  112. /lib/modules/4.9.120/pppox.ko
  113. #luci-proto-ipv6
  114. /usr/lib/lua/luci/model/cbi/admin_network/proto_dslite.lua
  115. /usr/lib/lua/luci/model/cbi/admin_network/proto_6rd.lua
  116. /usr/lib/lua/luci/model/network/proto_hnet.lua
  117. /usr/lib/lua/luci/model/cbi/admin_network/proto_6to4.lua
  118. /usr/lib/lua/luci/model/cbi/admin_network/proto_map.lua
  119. /usr/lib/lua/luci/model/network/proto_aiccu.lua
  120. /usr/lib/lua/luci/model/network/proto_dhcpv6.lua
  121. /usr/lib/lua/luci/model/cbi/admin_network/proto_hnet.lua
  122. /usr/lib/lua/luci/model/network/proto_4x6.lua
  123. /usr/lib/lua/luci/model/cbi/admin_network/proto_464xlat.lua
  124. /usr/lib/lua/luci/model/network/proto_6x4.lua
  125. /usr/lib/lua/luci/model/cbi/admin_network/proto_aiccu.lua
  126. /usr/lib/lua/luci/model/cbi/admin_network/proto_6in4.lua
  127. /usr/lib/lua/luci/model/cbi/admin_network/proto_dhcpv6.lua
  128. #luci-proto-ppp
  129. /usr/lib/lua/luci/model/cbi/admin_network/proto_ppp.lua
  130. /usr/lib/lua/luci/model/cbi/admin_network/proto_pppoe.lua
  131. /usr/lib/lua/luci/model/cbi/admin_network/proto_p p t p.lua
  132. /usr/lib/lua/luci/model/cbi/admin_network/proto_pppossh.lua
  133. /usr/lib/lua/luci/model/cbi/admin_network/proto_l2tp.lua
  134. /usr/lib/lua/luci/model/cbi/admin_network/proto_pppoa.lua
  135. /usr/lib/lua/luci/model/network/proto_ppp.lua
  136. #ppp
  137. /lib/upgrade/keep.d/ppp
  138. /usr/sbin/pppd
  139. /etc/ppp/filter
  140. /lib/netifd/ppp-up
  141. /etc/ppp/options
  142. /etc/ppp/chap-secrets
  143. /lib/netifd/ppp-down
  144. /lib/netifd/proto/ppp.sh
  145. /etc/ppp/resolv.conf
  146. /lib/netifd/ppp6-up
  147. #kmod-pp?
  148. /usr/lib/pppd
  149. #softethervirtual**
  150. /usr/libexec/softethervirtual**/virtual**_bridge.config
  151. #/etc/init.d/softethervirtual**server
  152. /etc/init.d/softethervirtual**bridge
  153. #/usr/libexec/softethervirtual**/virtual**server
  154. #/usr/bin/virtual**cmd
  155. /usr/libexec/softethervirtual**/virtual**bridge
  156. /usr/libexec/softethervirtual**/virtual**_server.config
  157. #/usr/libexec/softethervirtual**/hamcore.se2
  158. /usr/libexec/softethervirtual**/virtual**_client.config
  159. #/usr/libexec/softethervirtual**/launcher.sh
  160. #/usr/libexec/softethervirtual**/lang.config
  161. #/usr/libexec/softethervirtual**/virtual**cmd
  162. /etc/init.d/softethervirtual**client
  163. /usr/libexec/softethervirtual**/virtual**client
  164. #kmod-nf-nat
  165. /lib/modules/4.9.120/nf_nat_masquerade_ipv4.ko
  166. /lib/modules/4.9.120/nf_nat_redirect.ko
  167. /etc/modules.d/nf-nat
  168. /lib/modules/4.9.120/nf_nat.ko
  169. /lib/modules/4.9.120/nf_nat_ipv4.ko
  170. #kmod-ipt-nat
  171. /lib/modules/4.9.120/xt_REDIRECT.ko
  172. /etc/modules.d/ipt-nat
  173. /lib/modules/4.9.120/xt_nat.ko
  174. /lib/modules/4.9.120/iptable_nat.ko
  175. /lib/modules/4.9.120/ipt_MASQUERADE.ko
  176. #mod-ipt-core
  177. /lib/modules/4.9.120/nf_log_common.ko
  178. #/lib/modules/4.9.120/ipt_REJECT.ko
  179. #/lib/modules/4.9.120/xt_multiport.ko
  180. #/lib/modules/4.9.120/xt_tcpudp.ko
  181. #/lib/modules/4.9.120/xt_limit.ko
  182. /lib/modules/4.9.120/xt_mark.ko
  183. /lib/modules/4.9.120/xt_LOG.ko
  184. /lib/modules/4.9.120/iptable_mangle.ko
  185. #/lib/modules/4.9.120/iptable_filter.ko
  186. /lib/modules/4.9.120/xt_mac.ko
  187. #/etc/modules.d/ipt-core
  188. /lib/modules/4.9.120/xt_time.ko
  189. /lib/modules/4.9.120/nf_log_ipv4.ko
  190. #/lib/modules/4.9.120/xt_comment.ko
  191. #/lib/modules/4.9.120/xt_TCPMSS.ko
  192. #kmod-nf-conntrack
  193. #/lib/modules/4.9.120/nf_defrag_ipv4.ko
  194. #/etc/modules.d/nf-conntrack
  195. #/lib/modules/4.9.120/nf_conntrack.ko
  196. #/lib/modules/4.9.120/nf_conntrack_ipv4.ko
  197. /lib/modules/4.9.120/nf_conntrack_rtcache.ko
  198. #kmod-ipt-conntrack
  199. #
  200. #/lib/modules/4.9.120/xt_CT.ko
  201. #/etc/modules.d/ipt-conntrack
  202. #/lib/modules/4.9.120/xt_conntrack.ko
  203. /lib/modules/4.9.120/xt_state.ko
  204. #kmod-ipt-raw
  205. #/etc/modules.d/ipt-raw
  206. #/lib/modules/4.9.120/iptable_raw.ko
  207. #kmod-stp
  208. #/etc/modules.d/10-stp
  209. #kmod-ebtables
  210. #/lib/modules/4.9.120/ebtables.ko
  211. /lib/modules/4.9.120/ebt_stp.ko
  212. #/etc/modules.d/ebtables
  213. #/lib/modules/4.9.120/ebt_limit.ko
  214. /lib/modules/4.9.120/ebt_among.ko
  215. #
  216. #/lib/modules/4.9.120/ebt_pkttype.ko
  217. /lib/modules/4.9.120/ebt_mark_m.ko
  218. /lib/modules/4.9.120/ebt_802_3.ko
  219. /lib/modules/4.9.120/ebtable_broute.ko
  220. /lib/modules/4.9.120/ebt_vlan.ko
  221. /lib/modules/4.9.120/ebt_redirect.ko
  222. /lib/modules/4.9.120/ebtable_nat.ko
  223. /lib/modules/4.9.120/ebt_mark.ko
  224. #/lib/modules/4.9.120/ebtable_filter.ko
  225. #kmod-ebtables-ipv4
  226. /lib/modules/4.9.120/ebt_snat.ko
  227. #/lib/modules/4.9.120/ebt_arp.ko
  228. /lib/modules/4.9.120/ebt_dnat.ko
  229. #
  230. #/lib/modules/4.9.120/ebt_arpreply.ko
  231. #/lib/modules/4.9.120/ebt_ip.ko
  232. #/etc/modules.d/ebtables-ipv4
  233. #kmod-ebtables-watchers
  234. /lib/modules/4.9.120/ebt_nflog.ko
  235. #/etc/modules.d/ebtables-watchers
  236. #/lib/modules/4.9.120/ebt_log.ko
  237. #kmod-slhc
  238. /lib/modules/4.9.120/slhc.ko
  239. #kmod-br-netfilter
  240. #
  241. #/lib/modules/4.9.120/br_netfilter.ko
  242. #/etc/modules.d/br-netfilter
  243. EOF
  244. grep -v "#" ./files_remove1 > ./files_remove
  245. cat ./files_remove
  246. 不能有空行产生,不然会出错
  247. ==
  248. 2. Patch Makefile

  249. ifneq ($(USER_FILES),)
  250. $(MAKE) copy_files
  251. endif
  252. +
  253. +ifneq ($(FILES_REMOVE),)
  254. +        @echo
  255. +        [url=home.php?mod=space&uid=3970]@ECHO[/url] Remove useless files
  256. +
  257. +        while read filename; do                                \
  258. +            rm -rfv $(TARGET_DIR)$filename;        \
  259. +        done < $(FILES_REMOVE);
  260. +endif
  261. +
  262. $(MAKE) package_postinst
  263. $(MAKE) build_image
复制代码


我的恩山、我的无线 The best wifi forum is right here.
发表于 2020-2-16 19:59 | 显示全部楼层
感谢分享
来自安卓客户端来自安卓客户端
我的恩山、我的无线 The best wifi forum is right here.
发表于 2020-2-16 19:59 | 显示全部楼层
厉害!能详细说下怎么使用呢?
我的恩山、我的无线 The best wifi forum is right here.
 楼主| 发表于 2020-2-16 20:10 | 显示全部楼层
本帖最后由 dato 于 2020-2-16 20:30 编辑
  1. cat << EOF > /tmp/IPKrmlst.tmp
  2. IPKrm softethervirtual**
  3. virtual**cmd

  4. IPKrm stunnel
  5. stunnel.conf libstunnel.so ./usr/lib

  6. IPKrm sexpect
  7. sexpect

  8. IPKrm vlmcsd
  9. ./usr ./etc/init.d
  10. EOF
  11. cat /tmp/IPKrmlst.tmp
复制代码

使用方法
1,定义好自己需要精简的包
格式为
IPKrm stunnel  #用于shell grep IPKrm处理快速生成列表
stunnel.conf libstunnel.so ./usr/lib #定义需要删除的文件,目录以空格做分隔,保持1行用tr生成排除列表

2,将代码复制到imagebuilder/packages目录里处理就可以了,处理好的文件放在packages/IPKG_REBUILD目录
3,如果确认没问题就可以通过 cp -a IPKG_REBUILD/* ./packages 覆盖同名文件
4,重新用imagebuilder生成固件就可以了。

脚本对完整*.ipk解包data.tar.gz,排除掉不需要的文件重新打包成data.tar.gz,再重新打包成精简*.ipk。
通过删除不需要的文件来达到精简固件的目的。
我的恩山、我的无线 The best wifi forum is right here.
发表于 2020-2-16 20:43 | 显示全部楼层
谢谢分享,谢谢分享,
我的恩山、我的无线 The best wifi forum is right here.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )|网站地图

GMT+8, 2020-10-25 18:49

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表