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.
Contents
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.
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,
cd ~/OpenWrt-ImageBuilder
Now check if the image builder is working properly or not.
make help
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 ~/OpenWrt-ImageBuilder/bin/ar71xx/
.
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.
Conclusion
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.
Ariyadi says
Do you have minimal firmware for TP-Link 3220 v2?
Dvijen Desai says
Hi Arnab
Glad I came across this webpage. I have Netgear WNR2000v4 (ar71xx) router converted to OpenWRT with the same problem of no space remaining to install openvpn packages. I would highly appreciate if you can help me with removing all ipv6 packages from LEDE 17.01.6 firmware or Openwrt 18.06.1 tiny firmware so that I can install Openvpn on it.
azuw says
can someone build me tl-wr1043nd-v2 Chaos Calmer 15.05.1 image without Luci and 192.168.1.174 as default ip
thanks
P Banerjee says
Dear Arnab,
Your posts are really helpful,l many thanks. I upgraded a TL-WR940N V6 to openWrt to run vpn connectivity, in put factory and upgrade firmware but I need to install 2 more additional packages for pptp connection. The router is out of space. Any idea how to achieve this. Unfortunately I have no access to any Linux machine.
Arnab Satapathi says
Which OpenWrt version you're using? Or LEDE?
Remove some unnecessary packages, if any.
Or reset the router to uninstall all pacxkages, then install only pptp vpn related packages.
Alternatively I could build a minimal firmware for you, excluding IPv6 related packages. Hopefully that will free up enough space.
But it will take few days.
P Banerjee says
Dear Arnab,
Thank you once again. It would be of great help if you can help me with a minimum openWrt package of TL-WR940N V6 with luci. I need to put two additional packages " ppp-mod-pptp" and "kmod-nf-nathelper-extra" on this to run the PPTP interface. Hopefully I will be able to do this with your package.
P Banerjee says
Dear Mr. Arnab,
Could you please help me with the minimum openWrt package of TL-WR940N V6 with luci. I need to put two additional packages " ppp-mod-pptp" and "kmod-nf-nathelper-extra" on this to run the PPTP interface.
Arnab Satapathi says
WR940N v6 released in 2018. OpenWrt or LEDE supported version 18.06 or later, only the tinybuilds.
I doubt that there's LuCI in built, though never tested the tiny builds.
The generic OpenWrt or LEDE image builder doesn't have any build profile for WR940N v6.
So, the tiny image is only easy option.
Here's the link to a minimal OpenWrt for WR940N v6. https://drive.google.com/open?id=1-XI4mT5W8aT2MD-VM4zU3ejnPwVWc54H
Removed the packages,
-ip6tables -odhcp6c -kmod-ipv6 -kmod-ip6tables -odhcpd-ipv6only
I hope there will be enough free space to install LuCI with those two extra packages.
Also please share your experience.
dwijonarko says
can you share your builds? so I can download it directly
Arnab Satapathi says
Which device?
I've some pre-built minimal firmware.
Saadat says
Can you help me with minimal firmware for TPLink MR3020. I can get to make it work. Thanks
Arnab Satapathi says
Yeah, @ evening.
And keep all IPv6 related packages or not?
Arnab Satapathi says
Here's the OpenWrt mini firmware for MR3020, ready for extroot, still there should be few KB free space left.
All IPv6 related packages included.
There's no build profile for MR 3020 on the LEDE image builder.
https://drive.google.com/open?id=1SLWHgDsZBlOFOV8ttMIxbhUvT52Pg2Bg
Andrey says
Hi, thanks for this.
I need to free up ~520Kb of flash space compared to stock OpenWRT build.
Is it possible?
Arnab Satapathi says
I think yes, drop all the IPv6 related packages, LuCI, and any other unnecessary package you have in mind.
My build had around 378 KB of free space.
Rustic says
Hello Arnab, I'm trying to configure some default configurations, I seuccessfully enabled wifi by default and changed SSID (file named mac80211.sh), but I can't find where to change the default ip 192.168.1.1, I looked into network files but no luck there.
To be clear, I'm doing this to change the default factory settings.
Arnab Satapathi says
I'm not very sure, but perhaps the default IP is set by UCI during boot, look at this file, build_dir/target-mips_34kc_uClibc-0.9.33.2/root-ar71xx/lib/functions/uci-defaults.sh
I've OpenWrt Image builed for ar71xx platform, the file could be different if you're building for another platform, but usually follows same structure.
Also please don't forget to share your experience here, sharing == knowledge.
Rustic says
Thanks Arnab,
I've changed the IP on that file, but it seems the file is generated after compile, the firmware still has 192.168.1.1.
I've also created a custom file in build_dir/target-mips_34kc_uClibc-0.9.33.2/root-ar71xx /files/etc/config/network, but it removes this file after compile.
I'm totally stuck.
Arnab Satapathi says
Yes, there's no /etc/config/network file anywhere, perhaps editing the squashfs file, bin/ar71xx/openwrt-15.05.1-ar71xx-generic-root.squashfs could help.
You should ask this question on the OpenWrt forum.
Rustic says
Ok, I found how to do it, you need to add the custom file into the build root, for example openwrt/files/etc/config/network (as the wiki says).
Arnab Satapathi says
Thanks ! I'll give it a try in future builds.
Lost Phoenix says
I build IMG for MR3420 v2 and I flashed it to my router. It has no Luci, I followed your tutorial. As no luci I have to work with SSH. But I tried to connect with SSH, password not working.
I tried with
User Name: root / admin
Password: password
Even I reset my router once, Still I can't connect ssh. What should I do?
Arnab Satapathi says
So you managed to sucesssfully build OpenWrt image ?
First you need to login via telnet and set your own password, then you can login via SSH.
It may be helpful, https://www.pcsuggest.com/configuring-extroot-with-openwrt-on-tp-link-mr-3220/
Look at the Initial OpenWrt setup section.
Shah says
I compiled the packages using the command above but this problem occured. What to do?
Copying /root/openwrt/OpenWrt-ImageBuilder-15.05.1-ar71xx-generic.Linux-x86_64/dl/libgcc_4.8-linaro-1_ar71xx.ipk.
make[2]: *** [package_install] Segmentation fault (core dumped)
make[2]: Leaving directory `/root/openwrt/OpenWrt-ImageBuilder-15.05.1-ar71xx-generic.Linux-x86_64'
make[1]: *** [_call_image] Error 2
make[1]: Leaving directory `/root/openwrt/OpenWrt-ImageBuilder-15.05.1-ar71xx-generic.Linux-x86_64'
make: *** [image] Error 2
Arnab Satapathi says
weird problem, perhaps reinstalling the OpneWrt imagebuilder could solve the problem.
Shah says
Thank you it worked perfectly!! i have another question, can we edit the Luci to remove certain package?
Arnab Satapathi says
Which part of LuCI you want to edit ?
Shah says
i want to make my own Luci package to add commands in /etc/config instead of configure it manually..
i want to add commands below using html form..
config redirect
option name 'test'
option src 'lan'
option proto 'tcp'
option dest_port '8888'
option dest_port '80-500'
option src_dip '!192.168.1.1'
option dest_ip '192.168.1.1.'
option start_time '15:00'
option stop_time '18:00'
option enabled '1'
Arnab Satapathi says
Then you need to put your configurations inside the files folder under your openwrt imagegenerator's folder.
Here's more, https://wiki.openwrt.org/doc/howto/obtain.firmware.generate
Look at the FILES variable section.
Shah says
thank you, I found the solution. I want to ask i more question, which package can be used to block inappropriate content using keyword blocking?
Arnab Satapathi says
I personally use DNS based blocking, downloads a host list and adds it to the dnsmasq configuration.
I doubt that any thing like squid can run on a little router to achive keyword based content blocking.
You may try pixelserv, though I never tested it.
Riho says
Big thanks for this tutorial!
Successfully built Chaos Calmer (15.05.01) firmware for WR703N with this and managed to perform extroot after.
Arnab says
You're most welcome ! Have a good day 🙂
Jason Woringen says
make info shows no profiles to make??? trying to compile bcm53xx chaos calmer build for r7000 with wifi drivers.
Arnab says
Probably something wrong with the bcm53xx image builder, try previous releases.
Frankly speaking, I've never used anything based on bcm53xx architecture.
Arsalan Shahid says
i format my usb to fat32 it will format in less than 1 minutes but for ext4, 4 hours
Arsalan Shahid says
if i succedded on raspberry pi then i will again try on openwrt router mr3220
Arsalan Shahid says
i'm now doing it with raspberry pi it also has same structure and i also have to make setting for booting with usb, the main problem is formatting the usb drive, it takes to much time (Windows 10, 64 bit, 4 Gb Ram)
Arnab says
I appreciate your effort, but I'd suggest move the discussion somewhere else rather than flooding this single post, may be FB.
Arsalan Shahid says
i send you request on fb, but you don't accept it
Arsalan Shahid says
one more question, the usb drive take to much time to format into ext4, size is 64 Gb 3.0. It takes 4 to 5 hours to format :/
Arnab says
Which software you're using to format ? I should take some time, about 30 Min in my experience, but definitely not 4-5 Hours !!!!
Arsalan Shahid says
i'm using mini tool partition wizard free in (Windows)
Arsalan Shahid says
now i'm trying it on my raspberry pi 3, shifting root on usb then will install web server.
Arsalan Shahid says
i became dis-heart and leave for some weeks, but i need a web server so i format another usb to ext4 and swap that is usb 2.0 8Gb, the usb i was trying on is 3.0 64 Gb. So, i am able to copy the root files on usb when it comes to fstab config, i was stuck on read ony file access, i can't write my config files on fstab after then i open terminal and boot with write access i am able to write on fstab file now the problem is i don't know how to save, i read on wiki page about esc and :qw! but it don't work. !
Arnab says
EXT4 has a little permission issue, you need same UID both on the pendrive and system, or use sudo, i.e. become root.
Use only :wq , and use sudo on your system, in OpenWrt, you're already root.
Arsalan Shahid says
i am unable to save the fstab file in terminal with vi editor, now i have out of free space so i have to factory restore it.
Saran says
hello Azazel,
were you able to get usb storage working on TPLINK 3220 V2. I am also having same problem. Do i need to format the usb drive in ext2 partion. Can you please guide me.
Arnab says
Yes, you need to format the USB drive to either ext4 or ext2, what error you're getting while trying to setup extroot ???
Saran says
I am not able to install kmod-ext4 package due to lack of space
Azazel says
Follow the steps
1) u need to format your pendrive/ usb drive with ext4 format
2) Download the file https://drive.google.com/open?id=0B0Sy87thl-LtdXpELWszNXZSU00
3) Revert back to tplink and then upgrade with the downloaded file.
4) Thanks to Arnab he has already provided us with all the neccessary packages so u wont need to install them. Just follow the tutorial
Feel free to email me if you still have a problem
ashishbhogesara@gmail.com
Arnab says
Thanks for the clarification, a little hint: Use
sysupgrade -n -v /path/to/firmware.bin
for easy OpenWrt installation, no need to revert back to TP-Link stock firmware.Saran says
Thanks Arnab and Ashish for quick tutorial. My actual requirement is I need to setup smtp in openwrt router. So will I be able to install any smtp server on the minimal binary provided by Arnab. Also can you suggest any portable smtp server which is easy to configure and able to send a log file to any email address.
Azazel says
Sorry Saran, I haven't tried SMTP yet. But Arnab I need your help please. I am working on a project to build a captive portal that would allow users to access a time leashed wifi and block there Mac Address after the time limit untill the next day .
Would appreciate your help alot
Arnab says
I've sent you a mail to the address you provided here, check it out.
Saran says
Hi Arnab, haven't received your email. Kindly send it again.
Arnab says
Sorry Saran for my unclear reply, it wasn't for you. Anyway now I can help you with your SMTP and mailing from your router. Check your inbox, I'll be writing a tutorial on this very soon.
Saran says
No need to apologise Arnab. I have received your email and will try out the config and let everyone know of outcome
Arnab says
A good proposal, but I too never tried SMTP, you should seek help on the OpenWrt forum.
Azazel says
thank you arnab its done i appologize for my ignorance .. Thank you alot
Arnab says
You're welcome !
Azazel says
I have the same router and same problem can you please provide me the image minimal image so i can use exroot Thank you
Arnab says
Which one ? MR3220 ???
Azazel says
MR 3220 and v2.4 please help me dude
Arnab says
Here you go 😀 , https://drive.google.com/open?id=0B0Sy87thl-LtdXpELWszNXZSU00
Package list> http://pastebin.com/c66ixkXh
Happy flashing 🙂
Azazel says
Thank you Arnab for your and i apologize i din stated my problem correctly " I want to use the exroot feature so i can expand my storage I have been following your tutorial for exroot "https://www.pcsuggest.com/configuring-extroot-with-openwrt-on-tp-link-mr-3220/" but am unable to install a packages that is mentioned Kmod-fs-ext4 to be exact . What am looking for is a openwrt image that has the least package needed and can install the packages in your tutorial and use the exroot please help me . Thank you for your precious time
Arsalan Shahid says
i format my usb on windows with mini tool partition. i use ext4 file system with swap. but i can't mount invalid argument error. what to do ?
Arnab says
What's the output of dmesg command while trying to mount ? You could try it again after formatting to ext2 . Post it to pastebin.
Arsalan Shahid says
anyhow i face problem mounting my usb drive, what to do ?
Arnab says
Just format it on a Linux machine to ext4, or if you need to use FAT32 filesystem, install those extara packages, around 60 KB in total.
opkg install kmod-fs-vfat kmod-nls-cp437 kmod-nls-iso8859-1
Arnab says
Installing e2fsprogs on a embedded system is just wasting precious storage.
Arsalan Shahid says
i request you to remove ipv6 package i will get another time memory issue 🙁
Arsalan Shahid says
i send your request on facebook
Arsalan Shahid says
bro please help, i badly need your help, i don't like to bother but i don't know what to do, help please
Arnab says
Here is your another firmware, https://drive.google.com/open?id=0B0Sy87thl-LtdXpELWszNXZSU00
Total 71 packages, Package list >> http://pastebin.com/c66ixkXh
But I kept the IPv6 related packages for learning purpose.
Arsalan Shahid says
i've checked the package of your min firmware it still has ppp and ppope packages, screenshot: http://prnt.sc/ce557p & http://prntscr.com/ce55h8 . so i can't do anything can you please build another firmware with min packages like remove: ppp packages, ppope packages, luci, ipv6 packages [kmod-nf-ipt6, kmod-ppp, kmod-pppoe, libip6tc, odhcp6c, ppp, ppp-mod-ppope, ip6tables, kmod-ip6tables, kmod-ipv6, kmod-nf-ipt6 ]
Arnab says
Let me check, I'm building another.
Arsalan Shahid says
i've read on https://wiki.openwrt.org/doc/howto/usb.storage screenshot: http://prntscr.com/ce541m when i installed no memory left and unable to install. screenshot: http://prnt.sc/ce54i5
Arnab says
OMG !!! Never try to install e2fsprogs, it needs around 1.2 MB free space !!!!!
Arsalan Shahid says
if i will not install e2fsprogs, so how i will mount my usb, according to openwrt wiki it is useful ? and i'm unable to mount my usb 🙁
Arsalan Shahid says
i've formatted my 64 gb usb to ext4 partition and swap partition, i have installed all the necessary packages but unable to mount usb drive, please help.
Arnab says
What's the output of the dmesg command after trying to mount the drive ? Post it somewhere like pastebin.com .
Arsalan Shahid says
bro, i'm having problems mounting USB drive, here's screen shot: http://prnt.sc/ce508h
Arsalan Shahid says
Thank you so much, i'll try it.
Arsalan Shahid says
Thank you so much, i want to run a web server on it. First time i change firmware then install necessary packages for usb then i'm not able to mount usb, i don't know why (all packages are installed properly). Then i reset, after resetting i can not install ext4 package, it shows low memory. then i do it again to check same problem.
Please make the firmware soon. I will also need your help in configuration.
Thanks
Arnab says
Hi Arsalan, here your minimal OpenWrt image for MR 3220 v2, without all the ppp packages.
Flash with confidence, I've tested it on my router.
https://drive.google.com/open?id=0B0Sy87thl-LtVXpYc1FLSmE1Z2M
Arsalan Shahid says
bro if you don't mind will you remove ppp packages ? i want stable firmware for tl mr 3220. i will use extroot on it to plug my usb. please make this please please i need it.
Arnab says
Yeah, I'll remove the ppp package before building the firmware.
Arsalan Shahid says
hi bro, i just wanted this thing. hours of searching for this i found your blog. i never build custom firmware. will you send me your firmware i barely need it.
please send me arsalanshahid1337@gmail.com
Arnab says
No prob. bro, I'll upload it to google drive and mail the link to you.
Jacques says
Can you send me a custom image cc1505 for TP link 3220 v2 for exroot please?
Arnab says
Yes, but wait please, I'm running low on data.
zee says
yes it work! i've done it, thanks a lot Arnab now my router works like a mini computer.
Thanks again, see ya,.. 😀
Arnab says
So, finally it worked !
zee says
hi, this is what i looking for. thanks for the info,but i don't understanding linux thing. can you email me custom image you make cc15.05.1 AR71xx for exroot.
Arnab says
Yes, why not ? Check the gmail inbox, which you supplied here, and thanks a lot 🙂