Nov 142016
 

I recently had to create my own custom OpenWRT image. I had only 4MB of space available on the device itself and needed stunnel. I could not add it due to lack of free space and I did not want to add a USB drive as overlay filesystem. I wanted to remove luci (the web interface) and add stunnel instead, because I don’t use luci. The following was done on Kali Linux, but should work on other Linux distributions. You may have to add some packages like gcc and make etc. Luckily the OpenWRT documentation is very good and creating an image yourself takes only 4 commands (replace ramips/rt305x with your target architecture):

(Warning: The ImageBuilder file is 1.5GB!)

wget http://downloads.openwrt.org/chaos_calmer/15.05/ramips/rt305x/OpenWrt-ImageBuilder-15.05-ramips-rt305x.Linux-x86_64.tar.bz2
tar xfj OpenWrt-ImageBuilder-15.05-ramips-rt305x.Linux-x86_64.tar.bz2
cd OpenWrt-ImageBuilder-15.05-ramips-rt305x.Linux-x86_64
make image PROFILE="A5-V11"

or in my case
make image PROFILE="A5-V11" PACKAGES="stunnel"

Custom images do not have repositories configured, so you cannot opkg update or install new one’s. You have to manually add them. In my case (Chaos Calmer 15.05 and rt305x arch) I had to add these to repositories.conf in the main directory of the unpacked .tar.bz2 file.

src/gz chaos_calmer_base http://downloads.openwrt.org/chaos_calmer/15.05/ramips/rt305x/packages/base
src/gz chaos_calmer_luci http://downloads.openwrt.org/chaos_calmer/15.05/ramips/rt305x/packages/luci
src/gz chaos_calmer_packages http://downloads.openwrt.org/chaos_calmer/15.05/ramips/rt305x/packages/packages
src/gz chaos_calmer_routing http://downloads.openwrt.org/chaos_calmer/15.05/ramips/rt305x/packages/routing
src/gz chaos_calmer_telephony http://downloads.openwrt.org/chaos_calmer/15.05/ramips/rt305x/packages/telephony
src/gz chaos_calmer_management http://downloads.openwrt.org/chaos_calmer/15.05/ramips/rt305x/packages/management
## This is the local package repository, do not remove!
src imagebuilder file:packages

After making the images you will find the im the build_dir folder. In my case the file was:

./build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_rt305x/openwrt-15.05-ramips-rt305x-a5-v11-squashfs-sysupgrade.bin

and after I copied it to the /tmp directory (had 32MB RAM) I could simply upgrade my OpenWRT without stunnel to a custom one without luci, but with stunnel using:
sysupgrade -v /tmp/openwrt-15.05-ramips-rt305x-a5-v11-squashfs-sysupgrade.bin

The output might look like this:

root@P00519301:/tmp# sysupgrade -v openwrt-15.05-ramips-rt305x-a5-v11-squashfs-sysupgrade.bin 
Saving config files...
etc/config/dhcp
etc/config/dropbear
etc/config/firewall
etc/config/luci
etc/config/network
etc/config/rpcd
etc/config/system
etc/config/ucitrack
etc/config/uhttpd
etc/config/wireless
etc/dnsmasq.conf
etc/dropbear/dropbear_dss_host_key
etc/dropbear/dropbear_rsa_host_key
etc/firewall.user
etc/group
etc/hosts
etc/inittab
etc/opkg.conf
etc/opkg/customfeeds.conf
etc/opkg/keys/53bad1233d4c98c5
etc/opkg/keys/de98a2dd1d0f8a07
etc/passwd
etc/ppp/chap-secrets
etc/ppp/filter
etc/ppp/options
etc/profile
etc/protocols
etc/rc.local
etc/services
etc/shadow
etc/shells
etc/sysctl.conf
etc/sysupgrade.conf
killall: watchdog: no process killed
Sending TERM to remaining processes ... dnsmasq ubusd askfirst logd rpcd netifd odhcpd uhttpd ntpd 
Sending KILL to remaining processes ... askfirst 
Switching to ramdisk...
Performing system upgrade...
Unlocking firmware ...

Writing from <stdin> to firmware ...     
Appending jffs2 data from /tmp/sysupgrade.tgz to firmware...
Writing from <stdin> to firmware ...     
Upgrade completed
Rebooting system...
packet_write_wait: Connection to 192.168.0.171 port 22: Broken pipe
root@kali:~/openwrt# ssh 192.168.0.171
root@192.168.0.171's password: 

BusyBox v1.23.2 (2015-07-25 04:17:43 CEST) built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 CHAOS CALMER (15.05, r46767)
 -----------------------------------------------------
  * 1 1/2 oz Gin            Shake with a glassful
  * 1/4 oz Triple Sec       of broken ice and pour
  * 3/4 oz Lime Juice       unstrained into a goblet.
  * 1 1/2 oz Orange Juice
  * 1 tsp. Grenadine Syrup
 -----------------------------------------------------
root@P00519301:~# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                  896.0K    240.0K    656.0K  27% /
/dev/root                 2.0M      2.0M         0 100% /rom
tmpfs                    14.3M     64.0K     14.2M   0% /tmp
/dev/mtdblock6          896.0K    240.0K    656.0K  27% /overlay
overlayfs:/overlay      896.0K    240.0K    656.0K  27% /
tmpfs                   512.0K         0    512.0K   0% /dev
root@P00519301:~# opkg list-installed
base-files - 157-r46767
busybox - 1.23.2-1
dnsmasq - 2.73-1
dropbear - 2015.67-1
firewall - 2015-07-27
fstools - 2015-05-24-09027fc86babc3986027a0e677aca1b6999a9e14
hostapd-common - 2015-03-25-1
ip6tables - 1.4.21-1
iptables - 1.4.21-1
iw - 3.17-1
jshn - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
jsonfilter - 2014-06-19-cdc760c58077f44fc40adbbe41e1556a67c1b9a9
kernel - 3.18.20-1-c8b57a131072a3198e594822481af3e0
kmod-cfg80211 - 3.18.20+2015-03-09-3
kmod-crypto-aes - 3.18.20-1
kmod-crypto-arc4 - 3.18.20-1
kmod-crypto-core - 3.18.20-1
kmod-eeprom-93cx6 - 3.18.20-1
kmod-gpio-button-hotplug - 3.18.20-1
kmod-ip6tables - 3.18.20-1
kmod-ipt-conntrack - 3.18.20-1
kmod-ipt-core - 3.18.20-1
kmod-ipt-nat - 3.18.20-1
kmod-ipv6 - 3.18.20-1
kmod-leds-gpio - 3.18.20-1
kmod-lib-crc-ccitt - 3.18.20-1
kmod-lib-crc-itu-t - 3.18.20-1
kmod-mac80211 - 3.18.20+2015-03-09-3
kmod-nf-conntrack - 3.18.20-1
kmod-nf-conntrack6 - 3.18.20-1
kmod-nf-ipt - 3.18.20-1
kmod-nf-ipt6 - 3.18.20-1
kmod-nf-nat - 3.18.20-1
kmod-nf-nathelper - 3.18.20-1
kmod-nls-base - 3.18.20-1
kmod-ppp - 3.18.20-1
kmod-pppoe - 3.18.20-1
kmod-pppox - 3.18.20-1
kmod-rt2800-lib - 3.18.20+2015-03-09-3
kmod-rt2800-mmio - 3.18.20+2015-03-09-3
kmod-rt2800-soc - 3.18.20+2015-03-09-3
kmod-rt2x00-lib - 3.18.20+2015-03-09-3
kmod-rt2x00-mmio - 3.18.20+2015-03-09-3
kmod-slhc - 3.18.20-1
kmod-usb-core - 3.18.20-1
kmod-usb-ohci - 3.18.20-1
kmod-usb2 - 3.18.20-1
libblobmsg-json - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
libc - 0.9.33.2-1
libgcc - 4.8-linaro-1
libip4tc - 1.4.21-1
libip6tc - 1.4.21-1
libjson-c - 0.12-1
libjson-script - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
libnl-tiny - 0.1-4
libubox - 2015-06-14-d1c66ef1131d14f0ed197b368d03f71b964e45f8
libubus - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
libuci - 2015-04-09.1-1
libxtables - 1.4.21-1
mtd - 21
netifd - 2015-06-08-8795f9ef89626cd658f615c78c6a17e990c0dcaa
odhcp6c - 2015-07-13-024525798c5f6aba3af9b2ef7b3af2f3c14f1db8
odhcpd - 2015-05-21-2ebf6c8216287983779c8ec6597d30893b914a7c
opkg - 9c97d5ecd795709c8584e972bfdf3aee3a5b846d-7
ppp - 2.4.7-6
ppp-mod-pppoe - 2.4.7-6
procd - 2015-08-16-0da5bf2ff222d1a499172a6e09507388676b5a08
swconfig - 10
ubox - 2015-07-14-907d046c8929fb74e5a3502a9498198695e62ad8
ubus - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
ubusd - 2015-05-25-f361bfa5fcb2daadf3b160583ce665024f8d108e
uci - 2015-04-09.1-1
usign - 2015-05-08-cf8dcdb8a4e874c77f3e9a8e9b643e8c17b19131
wpad-mini - 2015-03-25-1
root@P00519301:~#

I found the documentation here and here very helpful.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)