节省固件空间
移除软件包
对于仅有4M闪存的设备,闪存空间是稀有的。您在使用imagebuilder编译自己的固件镜像文件时,可以移除一些不会使用到的软件包来节省一些空间。如想完全移除IPv6支持和相关的软件包,您可以在imagebuilder的make命令中通过“CONFIG_IPV6=n”来实现。
作用 | 相关软件包 |
---|---|
移除pppoe | -ppp -ppp-mod-pppoe |
移除IPv6 | -ip6tables -odhcp6c -kmod-ipv6 -kmod-ip6tables -odhcpd-ipv6only |
移除dhcp server | -odhcpd |
移除iptables | -iptables |
移除opkg | -opkg |
添加精减的LuCI | uhttpd uhttpd-mod-ubus libiwinfo-lua luci-base luci-app-firewall luci-mod-admin-full luci-theme-bootstrap |
添加zram¹ | zram-swap |
¹ 备注: 4M闪存的设备请不要使用 zram-swap,因为这会增加固件所需的闪存空间。这里之所以会列出,是因为它对于低内存设备很有用。
为仅有4M闪存的设备构建镜像
镜像构建命令行示例
备注: 您需要根据设备修改下方命令行中的PROFILE=tl-wr941nd-v6
,使用make info
命令可显示可用的设备清单。
是否集成LuCI | 作用 | Imagebuilder命令行 |
---|---|---|
集成LuCI | 移除pppoe和IPv6,包含必需的LuCI组件而非完整的LuCI软件包 | make image PROFILE=tl-wr941nd-v6 \
PACKAGES=“uhttpd uhttpd-mod-ubus libiwinfo-lua luci-base luci-app-firewall luci-mod-admin-full luci-theme-bootstrap \
-ppp -ppp-mod-pppoe -ip6tables -odhcp6c -kmod-ipv6 -kmod-ip6tables -odhcpd-ipv6only” |
不集成LuCI | 移除pppoe和IPv6 | make image PROFILE=tl-wr941nd-v6 PACKAGES=“-ppp -ppp-mod-pppoe -ip6tables -odhcp6c -kmod-ipv6 -kmod-ip6tables -odhcpd-ipv6only” |
相关资源:
Build image for devices with only 16/32MB RAM
If the device has 16MB or less of RAM, then it should only be used as Internal AP (e.g. to extend Wi-Fi coverage).
Example image builder command line
Note: In the command line shown below, you need to adjust PROFILE=tl-wr941nd-v6
to your device. Use make info
to list possibilities.
RAM | Action | Imagebuilder commandline |
---|---|---|
16MB | - remove pppoe and IPv6 - remove all related elements to iptables - remove dhcp servers + add LUCI + add zram-swap - remove opkg - not needed after making these adjustments | make image PROFILE=tl-wr941nd-v6 \
PACKAGES=“uhttpd uhttpd-mod-ubus libiwinfo-lua luci-base luci-app-firewall luci-mod-admin-full luci-theme-bootstrap zram-swap \
-ppp -ppp-mod-pppoe -iptables -ip6tables -odhcp6c -kmod-ipv6 -kmod-ip6tables -odhcpd-ipv6only -odhcpd -opkg” |
32MB | - remove pppoe and IPv6 + add LUCI + add zram-swap - remove opkg - not needed after making these adjustments | make image PROFILE=tl-wr941nd-v6 \
PACKAGES=“uhttpd uhttpd-mod-ubus libiwinfo-lua luci-base luci-app-firewall luci-mod-admin-full luci-theme-bootstrap zram-swap \
-ppp -ppp-mod-pppoe -ip6tables -odhcp6c -kmod-ipv6 -kmod-ip6tables -odhcpd-ipv6only -opkg” |
Resources:
Making all kernel modules built-in
This option compiles the kernel modules inside the kernel, you can either pick what modules you think can be integrated and make them built-in by pressing “y” on them when in the menuconfig, or do a quick-and-dirty change of the kernel config with (adjust the path in this example to point to your target's actual kernel config)
sed -i -e "s/=m/=y/g" build_dir/target-mipsel_24kc_musl/linux-ramips_mt7620/linux-4.14.63/.config
This will work only if your device's kernel partition is big enough to accomodate the slightly larger kernel, or if the device is using dynamic partitions.
This was reported by Daniel Santos in an email in the OpenWrt Devel mailing list, 30 Oct 2018 (currently the mailing list archive server is unavailable so I cannot link directly to the mail in the archive).
His comments:
I did a quick experiment of this and instead of saving 4k, my *image* is a full 256k smaller. I haven't analysed the specifics, but also this means less RAM consumed because squashfs uses the page cache for uncompressed files. Further, modules inherently have greater overhead, even after __init sections have been discarded. The only downside is that built-ins cannot be unloaded and will always occupy a portion of RAM. But having them built into the kernel is far more efficient.
(The “surprising” change in image size may be due to the block size of the squashfs image. See, for example include/image-commands.mk
and include/image.mk
in November, 2018 sources)
In a follow up mail by Phillip Prindeville pointed out the main drawback of this method.
Some hardware (it’s rare but not unheard of) can only be reset by unloading and reloading the module that controls it. Otherwise, you have to reboot the box. If you build all of your drivers in, then rebooting is all you have.
Modifying build configuration variables
You can also save space by changing configuration variables using make menuconfig
. In addition to the ones mentioned here you can save a tiny bit of space by disabling commands in busybox.
Options that can be disabled to save space.
Config variable | Menu path | Estimated savings |
---|---|---|
CONFIG_KERNEL_PRINTK | Global build settings / Kernel build options / Enable support for printk | |
CONFIG_KERNEL_CRASHLOG | Global build settings / Kernel build options / Crash logging | |
CONFIG_KERNEL_SWAP | Global build settings / Kernel build options / Support for paging of anonymous memory (swap) | |
CONFIG_KERNEL_KALLSYMS | Global build settings / Kernel build options / Compile the kernel with symbol table information | |
CONFIG_KERNEL_DEBUG_INFO | Global build settings / Kernel build options / Compile the kernel with debug information | |
CONFIG_KERNEL_ELF_CORE | Global build settings / Kernel build options / Enable process core dump support | |
CONFIG_IPV6 | Global build settings / Enable IPv6 support in packages | |
CONFIG_KERNEL_MAGIC_SYSRQ | Global build settings / Kernel build options / Compile the kernel with SysRq support | |
CONFIG_KERNEL_PRINTK_TIME | Global build settings / Kernel build options / Enable printk timestamps | |
CONFIG_PACKAGE_MAC80211_DEBUGFS | Kernel modules / Wireless Drivers / kmod-mac80211 / Export mac80211 internals in DebugFS | 21 KB |
CONFIG_PACKAGE_MAC80211_MESH | Kernel modules / Wireless Drivers / kmod-mac80211 / Enable 802.11s mesh support | 29 KB |
Options that can be enabled to save space.
Config variable | Menu path |
---|---|
CONFIG_STRIP_KERNEL_EXPORTS | Global build settings / Strip unnecessary exports from the kernel image |
CONFIG_USE_MKLIBS | Global build settings / Strip unnecessary functions from libraries |
make kernel_menuconfig
options that can save space.
Config variable | Menu path | Comments |
---|---|---|
CONFIG_SERIAL_8250 | Device Drivers / Character devices / Serial drivers / 8250/16550 and compatible serial support | This will also save RAM by preventing /sbin/askfirst from running |
CONFIG_EARLY_PRINTK | Kernel hacking / Early printk |
To build a kernel that only works with a specific device, run make kernel_menuconfig CONFIG_TARGET=subtarget
to edit target/linux/<platform>/*/config-default
and go to Machine selection / <Platform> machine selection
and disable all devices except for the specific device. This can save some disk space and RAM.
Increase block size from the default 256 KB to improve compression. Warning: By default 3 blocks will be cached so this will also make the router use more RAM (if 3 blocks are cached, and a block size of 1024 KB is used, this will use 2,304 KB more RAM (3 * 1024 KB - 3 * 256 KB)). It may also make the router use more CPU to decompress the larger blocks.
Config variable | Menu path |
---|---|
TARGET_SQUASHFS_BLOCK_SIZE | Target Images / squashfs / Block size |
Options that can be enabled to save RAM.
Config variable | Menu path |
---|---|
PACKAGE_zram-swap | Base system |
PROCD_ZRAM_TMPFS | Base system / procd Configuration |
Reduce the number of cached blocks by running make kernel_menuconfig
.
Config variable | Menu path |
---|---|
CONFIG_SQUASHFS_FRAGMENT_CACHE_SIZE | File systems / Miscellaneous filesystems / Additional option for memory-constrained systems / Number of fragments cached |
Replace LuCI icons with a blank pixel
The icons in LuCI are not strictly necessary and replacing them with a blank image will save about 15 KB. This bash script will take an OpenWrt git path as parameter and replace the images with a blank using the files path: