之前用的 2 种方法
1.这种会导致最终生成的固件无法用 7zip 打开
===根目录建立 files_remove
1. Create file 'files_remove' with full filenames:
cat << EOF > ./files_remove1
#多余目录
/usr/lib/opkg/status
#/usr/lib/opkg/info/*.list
/usr/lib/opkg/info/*.control
/usr/lib/opkg/info/*-pkg
/usr/lib/opkg/info/*.conffiles
/usr/lib/opkg/info/*.prerm
#dnsmasq
/etc/dnsmasq.conf
/etc/config/dhcp
/etc/hotplug.d/ntp/25-dnsmasqsec
/etc/init.d/dnsmasq
/usr/sbin/dnsmasq
#logd
#/sbin/logread
#/sbin/logd
#/etc/init.d/log
#kmod-ppp
/lib/modules/4.9.120/ppp_generic.ko
/etc/modules.d/ppp
/lib/modules/4.9.120/ppp_async.ko
/lib/modules/4.9.120/pppox.ko
#luci-proto-ipv6
/usr/lib/lua/luci/model/cbi/admin_network/proto_dslite.lua
/usr/lib/lua/luci/model/cbi/admin_network/proto_6rd.lua
/usr/lib/lua/luci/model/network/proto_hnet.lua
/usr/lib/lua/luci/model/cbi/admin_network/proto_6to4.lua
/usr/lib/lua/luci/model/cbi/admin_network/proto_map.lua
/usr/lib/lua/luci/model/network/proto_aiccu.lua
/usr/lib/lua/luci/model/network/proto_dhcpv6.lua
/usr/lib/lua/luci/model/cbi/admin_network/proto_hnet.lua
/usr/lib/lua/luci/model/network/proto_4x6.lua
/usr/lib/lua/luci/model/cbi/admin_network/proto_464xlat.lua
/usr/lib/lua/luci/model/network/proto_6x4.lua
/usr/lib/lua/luci/model/cbi/admin_network/proto_aiccu.lua
/usr/lib/lua/luci/model/cbi/admin_network/proto_6in4.lua
/usr/lib/lua/luci/model/cbi/admin_network/proto_dhcpv6.lua
#luci-proto-ppp
/usr/lib/lua/luci/model/cbi/admin_network/proto_ppp.lua
/usr/lib/lua/luci/model/cbi/admin_network/proto_pppoe.lua
/usr/lib/lua/luci/model/cbi/admin_network/proto_pptp.lua
/usr/lib/lua/luci/model/cbi/admin_network/proto_pppossh.lua
/usr/lib/lua/luci/model/cbi/admin_network/proto_l2tp.lua
/usr/lib/lua/luci/model/cbi/admin_network/proto_pppoa.lua
/usr/lib/lua/luci/model/network/proto_ppp.lua
#ppp
/lib/upgrade/keep.d/ppp
/usr/sbin/pppd
/etc/ppp/filter
/lib/netifd/ppp-up
/etc/ppp/options
/etc/ppp/chap-secrets
/lib/netifd/ppp-down
/lib/netifd/proto/
ppp.sh/etc/ppp/resolv.conf
/lib/netifd/ppp6-up
#kmod-pp?
/usr/lib/pppd
#softethervpn
/usr/libexec/softethervpn/vpn_bridge.config
#/etc/init.d/softethervpnserver
/etc/init.d/softethervpnbridge
#/usr/libexec/softethervpn/vpnserver
#/usr/bin/vpncmd
/usr/libexec/softethervpn/vpnbridge
/usr/libexec/softethervpn/vpn_server.config
#/usr/libexec/softethervpn/hamcore.se2
/usr/libexec/softethervpn/vpn_client.config
#/usr/libexec/softethervpn/
launcher.sh#/usr/libexec/softethervpn/lang.config
#/usr/libexec/softethervpn/vpncmd
/etc/init.d/softethervpnclient
/usr/libexec/softethervpn/vpnclient
#kmod-nf-nat
/lib/modules/4.9.120/nf_nat_masquerade_ipv4.ko
/lib/modules/4.9.120/nf_nat_redirect.ko
/etc/modules.d/nf-nat
/lib/modules/4.9.120/nf_nat.ko
/lib/modules/4.9.120/nf_nat_ipv4.ko
#kmod-ipt-nat
/lib/modules/4.9.120/xt_REDIRECT.ko
/etc/modules.d/ipt-nat
/lib/modules/4.9.120/xt_nat.ko
/lib/modules/4.9.120/iptable_nat.ko
/lib/modules/4.9.120/ipt_MASQUERADE.ko
#mod-ipt-core
/lib/modules/4.9.120/nf_log_common.ko
#/lib/modules/4.9.120/ipt_REJECT.ko
#/lib/modules/4.9.120/xt_multiport.ko
#/lib/modules/4.9.120/xt_tcpudp.ko
#/lib/modules/4.9.120/xt_limit.ko
/lib/modules/4.9.120/xt_mark.ko
/lib/modules/4.9.120/xt_LOG.ko
/lib/modules/4.9.120/iptable_mangle.ko
#/lib/modules/4.9.120/iptable_filter.ko
/lib/modules/4.9.120/xt_mac.ko
#/etc/modules.d/ipt-core
/lib/modules/4.9.120/xt_time.ko
/lib/modules/4.9.120/nf_log_ipv4.ko
#/lib/modules/4.9.120/xt_comment.ko
#/lib/modules/4.9.120/xt_TCPMSS.ko
#kmod-nf-conntrack
#/lib/modules/4.9.120/nf_defrag_ipv4.ko
#/etc/modules.d/nf-conntrack
#/lib/modules/4.9.120/nf_conntrack.ko
#/lib/modules/4.9.120/nf_conntrack_ipv4.ko
/lib/modules/4.9.120/nf_conntrack_rtcache.ko
#kmod-ipt-conntrack
#
#/lib/modules/4.9.120/xt_CT.ko
#/etc/modules.d/ipt-conntrack
#/lib/modules/4.9.120/xt_conntrack.ko
/lib/modules/4.9.120/xt_state.ko
#kmod-ipt-raw
#/etc/modules.d/ipt-raw
#/lib/modules/4.9.120/iptable_raw.ko
#kmod-stp
#/etc/modules.d/10-stp
#kmod-ebtables
#/lib/modules/4.9.120/ebtables.ko
/lib/modules/4.9.120/ebt_stp.ko
#/etc/modules.d/ebtables
#/lib/modules/4.9.120/ebt_limit.ko
/lib/modules/4.9.120/ebt_among.ko
#
#/lib/modules/4.9.120/ebt_pkttype.ko
/lib/modules/4.9.120/ebt_mark_m.ko
/lib/modules/4.9.120/ebt_802_3.ko
/lib/modules/4.9.120/ebtable_broute.ko
/lib/modules/4.9.120/ebt_vlan.ko
/lib/modules/4.9.120/ebt_redirect.ko
/lib/modules/4.9.120/ebtable_nat.ko
/lib/modules/4.9.120/ebt_mark.ko
#/lib/modules/4.9.120/ebtable_filter.ko
#kmod-ebtables-ipv4
/lib/modules/4.9.120/ebt_snat.ko
#/lib/modules/4.9.120/ebt_arp.ko
/lib/modules/4.9.120/ebt_dnat.ko
#
#/lib/modules/4.9.120/ebt_arpreply.ko
#/lib/modules/4.9.120/ebt_ip.ko
#/etc/modules.d/ebtables-ipv4
#kmod-ebtables-watchers
/lib/modules/4.9.120/ebt_nflog.ko
#/etc/modules.d/ebtables-watchers
#/lib/modules/4.9.120/ebt_log.ko
#kmod-slhc
/lib/modules/4.9.120/slhc.ko
#kmod-br-netfilter
#
#/lib/modules/4.9.120/br_netfilter.ko
#/etc/modules.d/br-netfilter
EOF
grep -v "#" ./files_remove1 > ./files_remove
cat ./files_remove
不能有空行产生,不然会出错
==
2. Patch Makefile
ifneq ($(USER_FILES),)
$(MAKE) copy_files
endif
+
+ifneq ($(FILES_REMOVE),)
+ @
echo+ @
echo Remove useless files
+
+ while read filename; do \
+ rm -rfv $(TARGET_DIR)$$filename; \
+ done < $(FILES_REMOVE);
+endif
+
$(MAKE) package_postinst
$(MAKE) build_image
2.精简 ipk 用的,自己都看不懂了。。。自己建个子目录谨慎操作,可能不同的 linux 系统在命令参数调用上会有差别
cat << EOF > /tmp/IPKrmlst.tmp
IPKrm softethervpn-base
./usr/bin/vpncmd ./usr/libexec/softethervpn/vpncmd
IPKrm ebtables_201
IPKrm kmod-ebtables_
ebt_stp.ko ebt_among.ko ebt_mark_m.ko ebt_802_3.ko ebtable_broute.ko ebt_vlan.ko ebt_redirect.ko ebtable_nat.ko ebt_mark.ko
IPKrm kmod-ebtables-ipv4_
ebt_snat.ko ebt_dnat.ko
IPKrm kmod-ebtables-watchers
ebt_nflog.ko
IPKrm kmod-slhc
./lib
IPKrm luci-proto-ipv6
./www
IPKrm luci-proto-ppp
proto_ppp.lua proto_pptp.lua proto_pppossh.lua proto_l2tp.lua proto_pppoa.lua roto_ppp.lua l2tp.js ppp.js pppoa.js pptp.js
EOF
cat /tmp/IPKrmlst.tmp
#!/bin/sh
IPKlst=/tmp/ipklst.tmp
ls *.ipk > $IPKlst
IPKrmlst=/tmp/IPKrmlst.tmp
rebuild_dir=./IPKG_REBUILD
mkd