Pimp your TL-MR3020 mobile router
The One-Watt Server
Many devices now run Linux – but mostly as a closed source firmware that you cannot access. We show how to use OpenWrt to free the TL-MR3020 router from its proprietary firmware and convert it into an all-around server for your home network.
TP-Link  manufactures routers in various performance classes. The TL-MR3020 (Figure 1) is marketed by the manufacturer as a mobile router because it is small and light. However, it does not support 3G (see the "Hardware" box), although you can upgrade via the USB port. Thus, the router is aimed at people who do not need 3G or have a UMTS stick and therefore do not want to invest in an expensive mobile UMTS router. However, the "normal" use of the router is not the focus of this article; instead, I will describe how to convert it into a mini-server.
The TL-MR3020 is a small, white plastic box (Figure 1) measuring 7.4 x 6.7 x 2.2 centimeters and weighing only 60 grams. A mini-USB connector is used for the power supply, and the AC adapter provided supplies 1 watt. Moreover, the router will also work without any problems on a USB port. Additionally, the TL-MR3020 includes a USB 2.0 port and an RJ45 Ethernet port (100Mbps). TP-Link provides a short, flat patch cable for the latter. On the wireless side, the small router supports IEEE 802.11b/g/n at up to 150Mbps.
The TL-MR3020 uses five LEDs to indicate its status, four of which can be programmed. There is also a button for the wireless setup via WPS and a slide switch with three positions (3G/WISP/AP). Inside, the router has a 400MHz ARM CPU and 32MB RAM. The operating system resides on a 4MB flash chip. The USB port is used with the original firmware to connect a UMTS stick for operation as a mobile 3G router. Without a stick, the device acts as a wireless access point.
As a useful addition to the TL-MR3020, I would recommend a mini-USB hub by Pearl (Figure 1). This device integrates a micro-SDHC reader and thus provides the advanced root filesystem described in this article on a memory card without blocking the USB port.
The router board contains additional ports, but TP-Link does not route them out. If you can use a soldering iron, you could attach other components, such as a serial console, an I2C interface, or an external antenna. The OpenWrt wiki shows some pictures and links to relevant instructions on its TL-MR3020 pages .
To do this, you'll replace the existing firmware with OpenWrt , a special Linux distribution for microdevices. OpenWrt has a package management system that is in no way inferior to that of classical distributions; thus, only the limitations of the hardware can curb your creativity.
The TL-MR3020 is well-suited to this purpose for two reasons: On one hand, it costs EUR 30 (US$ 40) – which is not too much, if you happen to "brick" the device. On the other hand, the manufacturer does not put any obstacles in the way of installing third-party firmware.
To begin, download the correct version of OpenWrt  and follow the brief, but perfectly sufficient, instructions that come with the router to connect to the device's web interface. When you get there, upload the new firmware to the TL-MR3020 by selecting Upgrade in the new web form (Figure 2).
Uploading the firmware is the only really critical step in the whole process. A defective firmware image will send the router off to the happy hunting grounds – your only chance is a soldering iron. Thus, before loading the image, it is essential to check out the postings on the OpenWrt wiki  and follow the appropriate instructions.
After installing OpenWrt, the next step is the basic configuration, particularly for the network. Then, you need to set up a number of software packages that upgrade USB support for data media (USB sticks or hard disks). This step lets you boot the router from an external disk. On the now-extended root filesystem, you then add more software packages from the OpenWrt repository for the actual application.
After the firmware upgrade and device reboot, you can connect your PC or laptop to the router with the use of a cable. Configure the network (you can normally use the network manager for this) and login via Telnet on 192.168.1.1 (Figure 3). The router runs a DHCP server that supplies a suitable address to your PC or laptop.
At this point, you should set a password for root. OpenWrt then switches off the Telnet server for safety reasons and starts the SSH server. Next, adjust the network configuration so that the router is on your home network; then, you can move on and add more software. For details of the OpenWrt configuration system, see the "Configuring OpenWrt" box.
The OpenWrt configuration system remains very consistent across all system-related packages. All configuration files are located in
/etc/config and are simply structured plaintext files that are most easily changed in an editor.
For production operation of the router later on, the web interface is the preferred alternative to the editor: Here, you can conveniently modify individual configuration parameters and query the system state (Figure 4). Another alternative is an interface for the command line. The command
$ uci get system.slider.handler
reads the value of the
handler option in the
slider section of the
/etc/config/system file. For scripts, the
/lib/functions.sh library offers a few utilities that significantly facilitate the handling of settings.
To use the router as a server on your home network, the network configuration should look like Listing 1 (
/etc/config/network) and Listing 2 (
/etc/config/wireless). Lines 9-15 in Listing 1 configure the WLAN interface. In Listing 2, line 19 ensures that the server is integrated into the network as a WLAN client rather than as an access point or router.
01 # /etc/config/network ----------------- 02 03 config interface 'loopback' 04 option ifname 'lo' 05 option proto 'static' 06 option ipaddr '127.0.0.1' 07 option netmask '255.0.0.0' 08 09 config interface 'wifi' 10 option proto 'static' 11 option ipaddr '192.168.3.100' 12 option netmask '255.255.255.0' 13 option gateway '192.168.3.1' 14 list dns '192.168.3.1' 15 list dns '126.96.36.199'
01 # /etc/config/wireless --------------- 02 03 config wifi-device radio0 04 option type mac80211 05 option channel 11 06 option macaddr 90:f6:52:e6:d7:b2 07 option hwmode 11ng 08 option htmode HT20 09 list ht_capab SHORT-GI-20 10 list ht_capab SHORT-GI-40 11 list ht_capab RX-STBC1 12 list ht_capab DSSS_CCK-40 13 # REMOVE THIS LINE TO ENABLE WIFI: 14 # option disabled 1 15 16 config wifi-iface 17 option device radio0 18 option network wifi 19 option mode sta 20 option ssid 'my-ssid' 21 option encryption psk2 22 option key 'secret'
After a reboot, the device should be found at the configured network address. If not, emergency mode can help: During the boot process, press the WPS button once it starts flashing. If the LED light flashes quickly, then release it again. Now the device is in Failsafe mode with the default address 192.168.1.1 and running the Telnet daemon. You can connect to Telnet and make the necessary corrections. However, no DHCP server is available on the router in this mode. You must assign a matching IP address to your own computer manually.
The original firmware image does not contain all the components that are necessary for running the root filesystem on a USB stick, so you will need to add them now. After successfully completing the network configuration, the mini-router can access the Internet and use the convenient package management system to install additional software retroactively.
The pivotal point is the
opkg command, which you need to run as root. To do so, first call
opkg update to upgrade the package list. Then, install the specified packages using the following command:
# opkg install <package>
If you are looking for a particular package, the
list subcommand outputs a package list with brief descriptions. For the USB installation, you primarily need a set of kernel packages (Listing 3). It's best to partition and format the USB stick (
/dev/sdb in the listing – you might need to adjust this) on your PC. Besides the root partition, you'll want a home partition and, above all, swap space.
Preparing the USB Stick
01 # Set up the root filesystem on a USB stick 02 # Basic USB support (USB 1.1 and USB 2) 03 opkg update 04 opkg install kmod-usb-uhci kmod-usb-ohci kmod-usb2 05 insmod uhci 06 insmod usb-ohci 07 insmod usbcore 08 insmod ehci-hcd 09 10 # USB Storage (FAT requires additional modules 11 # that you can upgrade later, however) 12 opkg install kmod-usb-storage-mount block kmod-fs-ext4-core kmod-scsci 13 14 # Prepare USB stick (on the PC) 15 # -> Partition with three partitions (root, home, swap) 16 # fdisk /dev/sdb etc. 17 # -> Format partitions with ext4 or swap 18 # mkfs.ext4 /dev/sdb1 19 # mkfs.ext4 /dev/sdb2 20 # mkswap /dev/sdb3 21 22 # Prepare root on USB (copies old root file system) 23 mkdir -p /mnt/usb 24 mount /dev/sda1 /mnt/usb 25 tar -cvf - -C /overlay . | tar -xf - -C /mnt/usb 26 umount /mnt/usb
Then, you can simply plug the stick into the router and change the configuration of the mountpoints in the
/etc/config/fstab file. Lines 10-16 in Listing 4 are important. The last line of Listing 3 copies the entire root filesystem to the stick. Creating a backup now is advisable. The system will still boot, even without the stick inserted: In this case, it simply ignores the nonexisting devices.
01 # Configure mountpoints 02 config global automount 03 option from_fstab 1 04 option anon_mount 1 05 06 config global autoswap 07 option from_fstab 1 08 option anon_swap 0 09 10 config mount 11 option target /overlay 12 option device /dev/sda1 13 option fstype ext4 14 option options rw,sync 15 option enabled 1 16 option enabled_fsck 0 17 18 config mount 19 option target /home 20 option device /dev/sda2 21 option fstype ext4 22 option options rw,sync 23 option enabled 1 24 option enabled_fsck 1 25 26 config swap 27 option device /dev/sda3 28 option enabled 1
After a reboot with a stick attached, you finally have more disk space. Any packages you now add can be stored there. All told, having the root filesystem on a USB device is handy. You can modify the configuration with the usual editors on a PC and easily copy data between locations (e.g., for backups).
At this point, the basic configuration is complete except for a few things, such as the hostname. The remainder of the procedure depends on how you will be using the router, and you can use the package manager to retrieve and configure the required software. The procedure on OpenWrt is no different from that of any other distribution.
Buy this article as PDF
Founder of ownCloud launches the Nextcloud project.
Will The Machine change the way future programmers think about memory?
The new Torus distributed storage system is available under an open source license on GitHub
Juries decides Google’s use of Java APIs Was Fair Use
But if you are not using the latest Linux kernel, your system is insecure.
Home routers will give room for custom firmware but still comply with FCC rules
Frank Karlitschek will continue to lead the open source ownCloud project
“Xenial Xerus” comes with a new packages format and several improvements for the enterprise.
Linux users can now download and install the Windows code editor
New initiative will address security and interoperability concerns around container technology.