Howto install OpenWRT on an TP-Link MR3020 mini router with external filesystem on a USB stick running a local webserver (lighttpd) to serve up webpages to act as an info point e.g. in a exhibition.

Inspired by the Piratebox Project:

Basic Install of OpenWRT

download OpenWRT firmware

open MR3020 webinterface on , username “admin”, password empty

flash OpenWrt firmware like a regular firmware update

wait for progress bar to finish twice

from now on the OpenWrt router can be reached at

$ telnet
root@OpenWrt:~# passwd

set a password for root user, now telnet gets disabled an ssh enabled

root@OpenWrt:~# reboot

Network configuration

$ ssh -l root

Edit the network file with vi (vi cheat sheet):

NOTE: As most gateway (e.g. your home network) router’s IP address are, we will use for the TP-Link MR3020.

root@OpenWrt:~# vi /etc/config/network

The modified file should look like this:

config interface 'loopback'
	option ifname 'lo'
	option proto 'static'
	option ipaddr ''
	option netmask ''

config interface 'lan'
	option ifname 'eth0'
	option type 'bridge'
	option proto 'static'
	option ipaddr ''
	option netmask ''
	option gateway ''
	list dns ''
	list dns ''

config interface 'wan'
	option ifname 'eth0.1'
	option proto 'dhcp'
	option gateway ''
	option netmask ''
	list dns ''
	list dns ''

config interface 'wifi'
	option proto 'static'
	option ipaddr ''
	option netmask ''

Firewall settings

Backup firewall config file:

root@OpenWrt:~# cp /etc/config/firewall /etc/config/firewall.bak

Open the firewall config file:

root@OpenWrt:~# vi /etc/config/firewall

Modify first 23 lines to look like this. Leave the rest of the file alone.

config defaults                                                                       
        option syn_flood        '1'                                                   
        option input            'ACCEPT'                                              
        option output           'ACCEPT'                                              
        option forward          'ACCEPT'                                              
# Uncomment this line to disable ipv6 rules                                           
#       option disable_ipv6     1                                                     

config zone                                                                           
        option name             'lan'                                                 
        option network          'lan'                                                 
        option input            'ACCEPT'                                              
        option output           'ACCEPT'                                              
        option forward          'ACCEPT'                                              

config zone                                                                           
        option name             'wan'                                                 
        option network          'wan'                                                 
        option input            'ACCEPT'                                              
        option output           'ACCEPT'                                              
        option forward          'ACCEPT'                                              
        option masq             '1'                                                   
        option mtu_fix          '1'

config zone
	option name		'wifi'
	option input		'ACCEPT'
	option output		'ACCEPT'
	option forward		'REJECT'

config forwarding 
	option src      	'wifi'
	option dest     	'wan'

config forwarding
	option src		'wifi'
	option src		'lan'

# We need to accept udp packets on port 68,
# see

Wireless settings

Enable wireless by modifying the wireless config:

root@OpenWrt:~# vi /etc/config/wireless

Change Line 12 to:

# option disabled 0
config wifi-iface
	option device   radio0
	option network  wifi
	option mode     ap
	option ssid     OpenWrt
	option encryption none

Misc settings

Edit /etc/sysupgrade.conf to prevent system upgrades to overwrite your config files:

root@OpenWrt:~# vi /etc/sysupgrade.conf

should look like this

## This file contains files and directories that should
## be preserved during an upgrade.
# /etc/example.conf
# /etc/openvpn/

Power cycle the router by unplugging the AC power.

Install additional packages

Connect the MR3020 to your gateway router (e.g. your home network router) with an ethernet cable and plug the power back in. Wait a couple of minutes until the router boots up. With your computer connected to your home network, try sshing into the router (Note: use the IP address you assigned in step 9):

$ ssh root@

Ping google to ensure your firewall settings are correct:

root@OpenWrt:~# ping

Add USB support to OpenWrt by installing and enabling the following packages:

root@OpenWrt:~# opkg update
root@OpenWrt:~# opkg install kmod-usb-uhci
root@OpenWrt:~# insmod uhci
root@OpenWrt:~# opkg install kmod-usb-ohci
root@OpenWrt:~# insmod usb-ohci

Filesystem on a USB stick (Rootfs on External Storage / extroot)

first we need to install basic USB support for EXT4 and FAT32 formatted USB sticks

root@OpenWrt:~# opkg update
root@OpenWrt:~# opkg install kmod-usb-storage block-mount kmod-fs-ext4 kmod-fs-vfat
kmod-nls-cp437 kmod-nls-cp850 kmod-nls-iso8859-1 kmod-nls-iso8859-15 kmod-scsi-core
e2fsprogs fdisk

[important]I had a lot of troubles trying to use a FAT32 formatted USB stick! The problem was that obviously FAT32 is not supported by the extroot pivot /overlay method! After using EXT4 for the USB stick, everything worked as described in the howto’s.[/important]

check if the USB stick was recognized

root@OpenWrt:~# ls /dev/sd*

you should see one or more devices like sda1, sdb1, sdb2, …

partition the USB stick

root@OpenWrt:~# fdisk
Command (m for help): m (displays actions)
Command (m for help): p (display partition table)
Command (m for help): d (delete partion - had only 1 on my stick)
Command (m for help): n (new partition)
Command action
e extended
p primary partition (1-4)
Partition number (1-4): 1
First cylinder (1-621, default 1): RETURN
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-nnnn, default nnn):
Command (m for help): a (make partition bootable) RETURN
Partition number (1-4): 1 Command (m for help): w (write to disk)

format USB stick with ext4 filesystem

root@OpenWrt:~# mkfs.ext4 /dev/sda1

mount the USB stick and copy the flash /overlay to the USB stick

root@OpenWrt:~# mkdir -p /mnt/usb
root@OpenWrt:~# mount -t vfat /dev/sda1 /mnt/usb
root@OpenWrt:~# tar -C /overlay -cvf - . | tar -C /mnt/usb -xvf -
root@OpenWrt:~# vi /etc/config/fstab

the ‘config mount’ block should look like this

config 'mount'
        option target   /overlay
        option device   /dev/sda1
        option fstype   ext4
        option options  rw,sync
        option enabled  1
        option enabled_fsck 0

restart the router and check if everything’s ok

root@OpenWrt:~# df
Filesystem           1K-blocks      Used Available Use% Mounted on
rootfs                 1962212     65100   1798716   3% /
/dev/root                 1536      1536         0 100% /rom
tmpfs                    14600        72     14528   0% /tmp
tmpfs                      512         0       512   0% /dev
/dev/sda1              1962212     65100   1798716   3% /overlay
overlayfs:/overlay     1962212     65100   1798716   3% /

[warning]please double check that the rootfs has a very low Use% – if it’s still at 50% oder higher it’s likely that the extroot on /overlay is not working![/warning]

LuCI Webinterface and LightHTTPD webserver

Now we can proceed and install LuCI and LightHTTPD

root@OpenWrt:~# opkg update
root@OpenWrt:~# opkg install lighttpd lighttpd-mod-cgi luci-mod-admin-full
luci-theme-openwrt libiwinfo libwinfo-lua

edit /etc/lighttpd/lighttpd.conf

make the first block look like this (or change it to your taste when you know what you’re doing):

server.modules = (
#       "mod_rewrite",
#       "mod_redirect",
#       "mod_alias",
#       "mod_auth",
#       "mod_status",
#       "mod_setenv",
#       "mod_fastcgi",
#       "mod_proxy",
#       "mod_simple_vhost",
#       "mod_ssi",
#       "mod_usertrack",
#       "mod_expire",
#       "mod_webdav"


#server.document-root = "/www/"


server.document-root = "/website"


#server.port = 81


server.port = 80

At the end of the file add:

$SERVER["socket"] == ":88" {
    server.document-root = "/www/"
    cgi.assign = ( "luci" => "/usr/bin/lua" )

create the /website directory (/www is needed by LuCI) and add some test content

# mkdir /website
# echo "

It works!

” >> /website/index.html

enable lighttpd and start it

root@OpenWrt:~# /etc/init.d/lighttpd start
root@OpenWrt:~# /etc/init.d/lighttpd enable

[important]From now on you can reach the router’s webserver at from your lan or from your wireless clients[/important]

[important]The LuCI webinterface is at from your lan or from your wireless clients[/important]

[notice]TODO: Splashpage for free WLAN access[/notice]

[notice]TODO: reroute internet access to local website (firewall, dhcp settings[/notice]

[notice]TODO: whitelist for websites that should be accesible[/notice]

[notice]TODO: use a virtual disk on a FAT32 formatted USB stick instead of formatting the USB stick with ext4 filesystem[/notice]

[notice]TODO: next steps to do with this router after having lighttpd up and running[/notice]

If something’s getting messed up … fresh start

To start over you can emtpy the /overlay folder containing all your configurations, installed packages, etc.

# rm -rf /overlay/*

and upgrade the kernel / firmware

# cd /tmp
# wget
# sysupgrade -v /tmp/openwrt-ar71xx-generic-tl-mr3020-v1-squashfs-factory.bin


TP-Link TL-MR3020 on OpenWRT:

Piratebox on MR3020 (useful links and tips):

OpenWRT LuCI Webinterface install:

OpenWRT LightHTTPD install:

OpenWRT first login:

OpenWRT extroot:

OpenWRT USB storage:

OpenWRT Routed AP:

Kernel / firmware upgrade problems solved:,2988,2988

OpenWRT sysupgrade: