Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
docs:guide-user:additional-software:saving_space [2020/09/30 14:10] – [Excluding packages] add internal links to packages in rest of table (except kmod-ipv6 which I could not locate). Adding these links allows reader to quickly assess size impact of each choice. pcryandocs:guide-user:additional-software:saving_space [2021/03/03 07:12] – header levels vgaetera
Line 1: Line 1:
-====== Saving firmware space ======+====== Saving firmware space and RAM ======
 ===== Excluding packages ===== ===== Excluding packages =====
-Flash space is scarce on devices with only 4MB flash. You can save some space while compiling your own image (e.g. with the [[docs:guide-user:additional-software:imagebuilder|imagebuilder]]) by removing packages that are not needed for your usecase. +Flash space is scarce on devices with only 4MB flash. 
-In order to completely remove IPv6 support and related packages you also need to ask the imagebuilder to do so by also passing this option to the make command: "CONFIG_IPV6=n".+You can save some space while compiling your own image (e.g. with the [[docs:guide-user:additional-software:imagebuilder|imagebuilder]]) by removing packages that are not needed for your usecase. 
 +In order to completely remove IPv6 support and related packages you also need to ask the imagebuilder to do so by also passing this option to the make command: ''CONFIG_IPV6=n''.
  
-^ Action               ^ Packages                  ^ Menu path                                                                                  +^ Action ^ Packages ^ Menu path ^ 
-| remove pppoe         | ''-[[packages:pkgdata:ppp|ppp]] -[[packages:pkgdata:ppp-mod-pppoe|ppp-mod-pppoe]]''   | Network                                                                            +| remove pppoe | ''-[[packages:pkgdata:ppp]] -[[packages:pkgdata:ppp-mod-pppoe]]'' | Network | 
-| remove IPv6          | ''-[[packages:pkgdata:ip6tables|ip6tables]] -[[packages:pkgdata:odhcp6c|odhcp6c]] -kmod-ipv6 -[[packages:pkgdata:kmod-ip6tables|kmod-ip6tables]] -[[packages:pkgdata:odhcpd-ipv6only|odhcpd-ipv6only]]'' | Global build settings / Enable IPv6 support in packages                                                             +| remove IPv6 | ''-[[packages:pkgdata:ip6tables|ip6tables]] -[[packages:pkgdata:odhcp6c]] -kmod-ipv6 -[[packages:pkgdata:kmod-ip6tables]] -[[packages:pkgdata:odhcpd-ipv6only]]'' | Global build settings / Enable IPv6 support in packages | 
-| remove dhcp server   | ''-[[packages:pkgdata:odhcpd|odhcpd]]''               | Network                                                                                      +| remove dhcp server | ''-[[packages:pkgdata:odhcpd]]'' | Network | 
-| remove  iptables     | ''-[[packages:pkgdata:iptables|iptables]]''             | Network / Firewall                                                                                      +| remove iptables | ''-[[packages:pkgdata:iptables]]'' | Network / Firewall | 
-| remove opkg          | ''-[[packages:pkgdata:opkg|opkg]]''                 | Base system                                                                                      +| remove opkg | ''-[[packages:pkgdata:opkg]]'' | Base system | 
-| add LuCI minimal     | ''[[packages:pkgdata:uhttpd|uhttpd]] [[packages:pkgdata:uhttpd-mod-ubus|uhttpd-mod-ubus]]''| Network / Web Servers/Proxies | +| add LuCI minimal | ''[[packages:pkgdata:uhttpd]] [[packages:pkgdata:uhttpd-mod-ubus]]''| Network / Web Servers/Proxies | 
-                     | ''[[packages:pkgdata:libiwinfo-lua|libiwinfo-lua]]''         | Languages / Lua | +| | ''[[packages:pkgdata:libiwinfo-lua]]'' | Languages / Lua | 
-                     | ''[[packages:pkgdata:luci-base|luci-base]] [[packages:pkgdata:luci-app-firewall|luci-app-firewall]] [[packages:pkgdata:luci-mod-admin-full|luci-mod-admin-full]] [[packages:pkgdata:luci-theme-bootstrap|luci-theme-bootstrap]]''   | LuCI | +| | ''[[packages:pkgdata:luci-base]] [[packages:pkgdata:luci-app-firewall]] [[packages:pkgdata:luci-mod-admin-full]] [[packages:pkgdata:luci-theme-bootstrap]]'' | LuCI | 
-| add zram¹            | ''[[packages:pkgdata:zram-swap|zram-swap]]''             | Base system                                                                                      |+| add zram | ''[[packages:pkgdata:zram-swap]]'' | Base system |
  
-¹ Note: Do not use zram-swap for 4MB flash devices as it //increases// the amount of firmware space used. It is listed here as it is helpful on machines with very little RAM memory.+:!: Do not use zram-swap for 4MB flash devices as it //increases// the amount of firmware space used. 
 +It is listed here as it is helpful on machines with very little RAM memory.
  
 +:?: The minus ''-PACKAGE_NAME'' prefix removes a package, no prefix adds one.
  
 ==== Build image for devices with only 4MB flash ==== ==== Build image for devices with only 4MB flash ====
 +**Example image builder command line**
  
-**Example image builder command line**\\ +**Note:** In the command line shown below, you need to adjust ''PROFILE=tl-wr941nd-v6'' to your device. 
-**Note:** In the command line shown below, you need to adjust ''PROFILE=tl-wr941nd-v6'' to your device. Use ''make info'' to list possibilities.+Use ''make info'' to list possibilities.
  
-^ LuCI    ^ Action ^ Imagebuilder commandline ^+^ LuCI ^ Action ^ Imagebuilder commandline ^
 | with LuCI | - remove pppoe and IPv6\\ + include only needed luci components, not full luci package. | ''make image PROFILE=tl-wr941nd-v6 \ | with LuCI | - remove pppoe and IPv6\\ + include only needed luci components, not full luci package. | ''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 \ +PACKAGES="uhttpd uhttpd-mod-ubus libiwinfo-lua luci-base 
--ppp -ppp-mod-pppoe -ip6tables -odhcp6c -kmod-ipv6 -kmod-ip6tables -odhcpd-ipv6only"''+luci-app-firewall luci-mod-admin-full luci-theme-bootstrap \ 
-| without LuCI | - remove pppoe and IPv6 | ''make image PROFILE=tl-wr941nd-v6 PACKAGES="-ppp -ppp-mod-pppoe -ip6tables -odhcp6c -kmod-ipv6 -kmod-ip6tables -odhcpd-ipv6only"'' | +-ppp -ppp-mod-pppoe -ip6tables -odhcp6c 
 +-kmod-ipv6 -kmod-ip6tables -odhcpd-ipv6only"''
 +| without LuCI | - remove pppoe and IPv6 | ''make image PROFILE=tl-wr941nd-v6 
 +PACKAGES="-ppp -ppp-mod-pppoe -ip6tables -odhcp6c 
 +-kmod-ipv6 -kmod-ip6tables -odhcpd-ipv6only"'' |
  
 Resources: Resources:
Line 36: Line 43:
   * [[https://forum.openwrt.org/t/tp-link-tl-mr-3420-v3-build/855/8]]   * [[https://forum.openwrt.org/t/tp-link-tl-mr-3420-v3-build/855/8]]
   * [[https://forum.openwrt.org/t/possible-ppp-removal-from-base-image/42024/3]]   * [[https://forum.openwrt.org/t/possible-ppp-removal-from-base-image/42024/3]]
 +  * Talk [[https://youtu.be/M3yUjHKvde8?t=846|Fight for the bytes! Fun with Four Megabytes Flash]]
  
 ==== Build image for devices with only 16/32MB RAM ==== ==== 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).\\ 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**\\ +**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 ^ +**Note:** In the command line shown below, you need to adjust ''PROFILE=tl-wr941nd-v6'' to your device. 
- 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 \ +Use ''make info'' to list possibilities. 
-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"''+^ RAM ^ Action ^ Imagebuilder commandline ^ 
- 32MB  | - remove pppoe and IPv6\\ + add LUCI\\ + add zram-swap\\ - remove opkg - not needed after making these adjustments | ''make image PROFILE=tl-wr941nd-v6 \ +| 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 \ +PACKAGES="uhttpd uhttpd-mod-ubus libiwinfo-lua 
--ppp -ppp-mod-pppoe -ip6tables -odhcp6c -kmod-ipv6 -kmod-ip6tables -odhcpd-ipv6only -opkg"'' |+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: Resources:
Line 58: Line 72:
  
 ===== Making all kernel modules built-in ===== ===== 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) 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)
  
Line 71: Line 84:
 His comments: 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.+//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 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)+(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. 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.//+//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 ===== ===== 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.
  
-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.+==== Saving space ==== 
 +^ Config variable\\ (''n'' = disable, ''y'' = enable) ^ Menu path ^ Comments ^ 
 +| ''CONFIG_KERNEL_PRINTK=n'' | Global build settings / Kernel build options / Enable support for printk | 
 +| ''CONFIG_KERNEL_CRASHLOG=n'' | Global build settings / Kernel build options / Crash logging | 
 +| ''CONFIG_KERNEL_SWAP=n'' | Global build settings / Kernel build options / Support for paging of anonymous memory (swap) | 
 +| ''CONFIG_KERNEL_KALLSYMS=n'' | Global build settings / Kernel build options / Compile the kernel with symbol table information | 
 +| ''CONFIG_KERNEL_DEBUG_INFO=n'' | Global build settings / Kernel build options / Compile the kernel with debug information | 
 +| ''CONFIG_KERNEL_ELF_CORE=n'' | Global build settings / Kernel build options / Enable process core dump support | 
 +| ''CONFIG_IPV6=n'' | Global build settings / Enable IPv6 support in packages | 
 +| ''CONFIG_KERNEL_MAGIC_SYSRQ=n'' | Global build settings / Kernel build options / Compile the kernel with SysRq support | 
 +| ''CONFIG_KERNEL_PRINTK_TIME=n'' | Global build settings / Kernel build options / Enable printk timestamps | 
 +| ''CONFIG_PACKAGE_MAC80211_DEBUGFS=n'' | Kernel modules / Wireless Drivers / kmod-mac80211 / Export mac80211 internals in DebugFS | Estimated savings: 21 KB | 
 +| ''CONFIG_PACKAGE_MAC80211_MESH=n'' | Kernel modules / Wireless Drivers / kmod-mac80211 / Enable 802.11s mesh support | Estimated savings: 29 KB | 
 +| ''CONFIG_STRIP_KERNEL_EXPORTS=y'' | Global build settings / Strip unnecessary exports from the kernel image | 
 +| ''CONFIG_USE_MKLIBS=y'' | Global build settings / Strip unnecessary functions from libraries | 
 +| ''CONFIG_SERIAL_8250=n'' | Device Drivers / Character devices / Serial drivers / 8250/16550 and compatible serial support | This will also save RAM by preventing /sbin/askfirst from running. However, this will break sysupgrade. This menu is available only via ''make kernel_menuconfig'' 
 +| ''CONFIG_EARLY_PRINTK=n'' | Kernel hacking / Early printk | This menu is available only via ''make kernel_menuconfig''
 +| ''KERNEL_SQUASHFS_FRAGMENT_CACHE_SIZE'' :!:| Global build settings / Kernel build options / Number of squashfs fragments cached | Reduce the number of cached blocksThis menu is available only via ''make kernel_menuconfig''
 +| ''TARGET_SQUASHFS_BLOCK_SIZE'' :!:| Target Images / squashfs / Block size | Increase block size from the default 256 KB to improve compression |
  
-=== Options that can be disabled to save space: ===+:!: Block size must be a power of 2, between 4096 bytes and 1 Megabyte. 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                       ^ Estimated savings                                                                                      ^ +:!: 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. 
-| CONFIG_KERNEL_PRINTK     | Global build settings Kernel build options Enable support for printk | +[[https://forum.openwrt.org/t/building-a-smaller-kernel-for-a-specific-device/30370/8|This can save some disk space and RAM]].
-| 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: === +==== Saving RAM ==== 
- +^ Config variable\\ (''n''disable, ''y''enable) ^ Menu path ^ 
-^ Config variable      ^ Menu path                                                                                                       ^ +''CONFIG_PACKAGE_zram-swap=y'' | Base system / zram-swap | 
-| CONFIG_STRIP_KERNEL_EXPORTS | Global build settings / Strip unnecessary exports from the kernel image | +''CONFIG_PROCD_ZRAM_TMPFS=y'' | Base system / procd Configuration / Mount ///tmp// using zram | 
-| CONFIG_USE_MKLIBS           | Global build settings / Strip unnecessary functions from libraries | +''CONFIG_KERNEL_SWAP=y'' | Global build settings / Kernel build options / Support for paging of anonymous memory (swap) |
- +
-=== ''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. Howeverthis will break sysupgrade. | +
-| CONFIG_EARLY_PRINTK | Kernel hacking / Early printk | +
- +
-<WRAP center round info 60%> +
-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. [[https://forum.openwrt.org/t/building-a-smaller-kernel-for-a-specific-device/30370/8|This can save some disk space and RAM]]. +
-</WRAP> +
- +
-=== Increase block size from the default 256 KB to improve compression: === +
- +
-^ Config variable ^ Menu path  ^ +
-| TARGET_SQUASHFS_BLOCK_SIZE | Target Images / squashfs / Block size | +
-<WRAP center round important 60%> +
-Block size must be a power of 2, between 4096 bytes and 1 Megabyte. +
-</WRAP> +
-<WRAP center round alert 60%> +
-**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. +
-</WRAP> +
- +
-=== Options that can be enabled to save RAM: === +
- +
-^ Config variable ^ Menu path  +
-PACKAGE_zram-swap | Base system / zram-swap | +
-PROCD_ZRAM_TMPFS | Base system / procd Configuration / Mount ///tmp// using zram | +
- +
-=== Reduce the number of cached blocks by running ''make kernel_menuconfig'': === +
- +
-^ Config variable ^ Menu path  ^ +
-| KERNEL_SQUASHFS_FRAGMENT_CACHE_SIZE | Global build settings / Kernel build options / Number of squashfs fragments cached |+
  
 ===== Replace LuCI icons with a blank pixel ===== ===== 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. 
-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 [[docs:guide-developer:build-system:use-buildsystem#custom_files|files]] path:+This bash script will take an OpenWrt git path as parameter and replace the images with a blank using the [[docs:guide-developer:build-system:use-buildsystem#custom_files|files]] path:
  
 <hidden> <hidden>
  • Last modified: 2022/09/24 18:48
  • by bkil