OpenWrt needs no further introduction, straight to the point, as OpenWrt is bloating day by day, so how to build OpenWrt minimal image that will fit in routers with 4 MB flash storage, with enough free space to install some other packages later.
- One solution is to use extroot when a USB port is available on the router, but it's not always possible or you may want to use the USB port for some other purpose, like adding a USB Wi-Fi dongle. Though using a USB hub is possible, but I think this will create a reliability issue.
- Now another problem, with OpenWrt Chaos Calmer 15.05 or 15.05.1 or any above release, you can't just use extroot on routers with 4 MB flash, even the router have a USB port. Simply there is not enough space to install necessary packages for extroot on the default OpenWrt build, at least in my case.
So that's the point, let's get started.
1. Download the OpenWrt image builder
First you need to determine your router platform, i.e. the CPU architecture, MIPS or ARM or x86 etc. etc.
In my case, the router is TP-Link MR3220, AR9331 SoC, where the CPU is 32bit MIPS big endian. In OpenWrt this platform is called ar71xx.
So I've to download the OpenWrt Chaos Calmer 15.05.1 image builder for the ar71xx platform, and the router falls under generic category.
You can download the image builder for other different platforms here > https://downloads.openwrt.org/chaos_calmer/15.05.1/
2. Get image builder working
You're going to need a working 64 bit Linux distro to get the image builder working, most probably you are running one, and basic knowledge of using command line tools of course.
Extract the image builder to wherever you want, i.e. under the home folder of the Linux distro.
tar -xf OpenWrt-ImageBuilder-15.05.1-ar71xx-generic.Linux-x86_64.tar.bz2 -C ~/
You can rename the folder to get rid of it's unnecessarily long name.
Now install some software like GNU make and others, necessary for compiling linking and building the firmware.
Enjoy free shipping and One-Day delivery, cancel any time.
For Debian, Ubuntu or any other Debian based distro, install
build-essential package, this will install the rest.
sudo apt-get install build-essential
Now go to the folder where you extracted the OpenWrt image builder,
Now check if the image builder is working properly or not.
If everything properly configured, it should print few lines of help text.
3. Choose which packages to add and remove
This step is important one, you've to find out which packages you want to add or remove, without compromising stability.
I'm removing the LuCI and related packages to build OpenWrt custom firmware small, i.e. few hundred KB extra free space after installing. Bellow the package list I want to remove.
libiwinfo-lua liblua libubus-lua libuci-lua lua luci luci-app-firewall luci-base luci-lib-ip luci-lib-nixio luci-mod-admin-full luci-proto-ipv6 luci-proto-ppp luci-theme-bootstrap uhttpd uhttpd-mod-ubus
You can safely remove all IPv6 related packages instead of LuCI to save some free space on the router.
I also want to add few extra packages to get extroot working right after the flashing without installing anything extra. Here are these extra packages.
kmod-fs-ext4 kmod-usb-storage kmod-scsi-core block-mount kmod-lib-crc32c kmod-crypto-crc32c
Note: The two package, kmod-lib-crc32c and kmod-crypto-crc32c are required if you want to use ext4 filesystem.
4. Build the installable OpenWrt image
Now build the openwrt minimal image, use the
make info command to get available build profile and select a suitable profile.
The PACKAGES variable is used to add or remove the packages to the final build, add a minus(
-) sign before the package you want to exclude.
A complete make command, don't forget to change it according to your configuration and router.
make -j4 image PROFILE=TLMR3220 PACKAGES="-libiwinfo-lua -liblua -libubus-lua -libuci-lua -lua -luci -luci-app-firewall -luci-base -luci-lib-ip -luci-lib-nixio -luci-mod-admin-full -luci-proto-ipv6 -luci-proto-ppp -luci-theme-bootstrap -uhttpd -uhttpd-mod-ubus kmod-fs-ext4 kmod-usb-storage kmod-scsi-core block-mount kmod-lib-crc32c kmod-crypto-crc32c"
The above command is very long, better to copy it to somewhere for analysis. Bellow the same command, but broken down into parts.
make -j4 image PROFILE=TLMR3220 PACKAGES=\ "-libiwinfo-lua -liblua -libubus-lua -libuci-lua -lua \ -luci -luci-app-firewall -luci-base -luci-lib-ip \ -luci-lib-nixio -luci-mod-admin-full -luci-proto-ipv6 \ -luci-proto-ppp -luci-theme-bootstrap -uhttpd -uhttpd-mod-ubus \ kmod-fs-ext4 kmod-usb-storage kmod-scsi-core block-mount \ kmod-lib-crc32c kmod-crypto-crc32c"
When the build is complete you can get the flashable OpenWrt images under the image builder's bin folder, in my case it's under
5. Before flashing the OpenWrt custom firmware
Before flashing openwrt, check the size of the flashable bin file, the squashfs factory image is around 3.8 MB for routers with 4 MB flash, precisely 3932160 bytes, double check it before flashing.
du -b openwrt-15.05.1-ar71xx-generic-tl-mr3220-v2-squashfs-factory.bin
Flash the new openwrt minimal build the way you like to do it, from the web interface or via
sysupgrade command or whatever.
Now you can see few hundred KB more free space after SSH login to the router.
Also don't forget to use an UPS to power up the router if you are facing frequent power cuts, as I have to, if power goes middle of the flashing, that will surely brick the router.
So that's it how to build your own custom OpnWrt firmware, and hopefully this guide is easy to understand for everyone. Also don't forget to share this if you thinks it's helpful.