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: http://wiki.daviddarts.com/PirateBox_DIY_OpenWrt
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: http://wiki.daviddarts.com/PirateBox_DIY_OpenWrt
Basic Install of OpenWRT
download OpenWRT firmware
open MR3020 webinterface on http://192.168.1.254/ , 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 http://192.168.1.1/
$ telnet 192.168.1.1
root@OpenWrt:~# passwd
set a password for root user, now telnet gets disabled an ssh enabled
root@OpenWrt:~# reboot
Network configuration
$ ssh -l root 192.168.1.1
Edit the network file with vi (vi cheat sheet):
NOTE: As most gateway (e.g. your home network) router’s IP address are 192.168.1.1, we will use 192.168.1.11 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 '127.0.0.1' option netmask '255.0.0.0' config interface 'lan' option ifname 'eth0' option type 'bridge' option proto 'static' option ipaddr '192.168.1.11' option netmask '255.255.255.0' option gateway '192.168.1.1' list dns '192.168.1.1' list dns '8.8.8.8' config interface 'wan' option ifname 'eth0.1' option proto 'dhcp' option gateway '192.168.1.1' option netmask '255.255.255.0' list dns '192.168.1.1' list dns '8.8.8.8' config interface 'wifi' option proto 'static' option ipaddr '192.168.2.1' option netmask '255.255.255.0'
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 https://dev.openwrt.org/ticket/4108
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/ /etc/config/
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@192.168.1.11
Ping google to ensure your firewall settings are correct:
root@OpenWrt:~# ping google.com
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
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) p 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% /
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_cgi",
# "mod_ssi",
# "mod_usertrack",
# "mod_expire",
# "mod_webdav"
)
OLD:
#server.document-root = "/www/"
NEW:
server.document-root = "/website"
OLD:
#server.port = 81
NEW:
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
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 http://downloads.openwrt.org/snapshots/trunk/ar71xx/openwrt-ar71xx-generic-tl-mr3020-v1-squashfs-factory.bin # sysupgrade -v /tmp/openwrt-ar71xx-generic-tl-mr3020-v1-squashfs-factory.bin
Resources
TP-Link TL-MR3020 on OpenWRT: http://wiki.openwrt.org/toh/tp-link/tl-mr3020
Piratebox on MR3020 (useful links and tips): http://www.disk91.com/2012/technology/networks/piratebox-creation-based-on-tp-link-mr3020/
OpenWRT LuCI Webinterface install: http://wiki.openwrt.org/doc/howto/luci.essentials
OpenWRT LightHTTPD install: http://wiki.openwrt.org/doc/howto/http.lighttpd
OpenWRT first login: http://wiki.openwrt.org/doc/howto/firstlogin
OpenWRT extroot: http://wiki.openwrt.org/doc/howto/extroot
OpenWRT USB storage: http://wiki.openwrt.org/doc/howto/usb.storage
OpenWRT Routed AP: http://wiki.openwrt.org/doc/recipes/routedap
Kernel / firmware upgrade problems solved: http://forum.daviddarts.com/read.php?2,2988,2988
OpenWRT sysupgrade: http://wiki.openwrt.org/doc/howto/generic.sysupgrade

Deutsch
8 comments
5 pings
Skip to comment form ↓
Fred
09.05.2012 at 00:07 (UTC 2) Link to this comment
Hello,
I have a issue with this command line :
root@OpenWrt:~# tar -C /overlay -cvf – . | tar -C /mnt/usb -xvf -
Some files are not copied ..;
Are you any idea ?
thank you
Wolfgang
09.05.2012 at 09:55 (UTC 2) Link to this comment
hi,
that’s normal i think because i had the same “problem” but it seems that it doesn’t matter because everything’s running fine – at least i couldn’t find any real problems.
Fred
09.05.2012 at 21:31 (UTC 2) Link to this comment
As you said about troubles trying to use a FAT32 formatted USB stick, I confim one more time.
It’s mandatory to have ext4 format.
root@OpenWrt:~# tar -C /overlay -cvf – . | tar -C /mnt/usb -xvf –
Run without problem and it’s the same for /overlay mount.
Thanks again.
ari
29.05.2012 at 02:59 (UTC 2) Link to this comment
have anyone experienced usb 3g connection unstable ?
3g connection disconnect after few minutes.
Chris Hoogenboom
21.09.2012 at 17:57 (UTC 2) Link to this comment
Thanks for the nice instructions. While one can find this on a variety of pages from openwrt and piece it together its nice to have it organized in one place. Is this correct?
mount -t vfat /dev/sda1 /mnt/usb
seems like it should be
mount -t ext4 /dev/sda1 /mnt/usb
Wolfgang
21.09.2012 at 23:41 (UTC 2) Link to this comment
yes, vfat as format is right, because it’s a good idea that the USB Stick is FAT32 formatted. So it’s possible to mount the USB stick on Windows or Mac OS X to upload webpages or mediafiles to it – making it easier to add content to the webpage for non Linux Users.
Dan
17.11.2012 at 22:28 (UTC 2) Link to this comment
Hello,
I’m trying to do something very similar, but use a loop mount /overlay to a .img file. I posted some more details about it on the OpenWrt forum. I’m trying to keep the USB drive readable on OS X (vfat), but then mount in a ext4 /overlay hosted *on* the vfat partition. I’m not too surprised it didn’t work the first time, but I’m wondering if this is even worth debugging further. Maybe it just doesn’t work the way I want it to.
Thanks,
Dan
ivo
03.01.2013 at 00:45 (UTC 2) Link to this comment
thanks for the great info. i thinks ‘libwinfo-lua’ should be ‘libiwinfo-lua’.
OpenWrt on a TP-Link TL-MR3020 Router
15.05.2012 at 11:51 (UTC 2) Link to this comment
[...] blog post on the MR3020: http://wolfgang.reutz.at/2012/04/12/openwrt-on-tp-link-mr3020-as-infopoint-with-local-webserver/ VN:F [1.9.17_1161]please wait…Rating: 0.0/10 (0 votes cast)Found it useful? Share [...]
????????????? TP-Link TL-MR3020 « Mac Mini Home
03.06.2012 at 21:14 (UTC 2) Link to this comment
[...] http://wiki.openwrt.org/toh/tp-link/tl-mr3020 https://forum.openwrt.org/viewtopic.php?id=33429 http://wolfgang.reutz.at/2012/04/12/openwrt-on-tp-link-mr3020-as-infopoint-with-local-webserver/ http://blog.philippklaus.de/2012/03/openwrt-on-a-tp-link-tl-mr3020-router/ [...]
OpenWrt on a TP-Link TL-MR3020 Router
23.09.2012 at 14:57 (UTC 2) Link to this comment
[...] Another blog post on the MR3020: http://wolfgang.reutz.at/2012/04/12/openwrt-on-tp-link-mr3020-as-infopoint-with-local-webserver/ [...]
Central heating control on the cheap – 32leaves
29.01.2013 at 13:44 (UTC 2) Link to this comment
[...] a USB power supply itself. Getting OpenWRT to run on this little white box is really easy, and described plenty elsewhere. Once the OS is setup, the only thing missing is the HTTP-to-Serial relay part.First, we need to be [...]
From Cool to Useful: Incorporating hobby projects into library work « information. games.
17.03.2013 at 21:45 (UTC 2) Link to this comment
[...] is to install a light-weight web server (lighttpd) on the hardware currently running LibraryBox. (Fortunately, someone has already done this and left directions.) It’s possible, but unlikely, that will meet our needs. After that we’re going to test [...]