wikiroute

networking recipes

User Tools

Site Tools


mr3020_with_openwrt

Introduction

The TP-LINK MR-3020 has gained a growing success recently. This portable wireless router supports IEEE 802.11 b/g/n standards and has one 100 Mbps LAN/WAN port, a USB 2.0 Port for 3G/4G modem, and a mini USB Port for power supply. The portability of the MR-3020 made it an excellent solution for the PirateBox project and, as recently announced by RIPE NCC, the future measurement probe of the ATLAS project.

Basic Configuration

Start by getting the Attitude Adjustment build of the OpenWRT firmware and proceed as in the following. Connect to the TL-MR3020 router via Ethernet cable at IP address 192.168.0.254, log in to the router's web GUI (default login/password: admin / admin) and overwrite the factory firmware by installing the downloaded firmware image like a regular firmware update. Wait for the progress bar to finish twice (the device will reset itself in the process), and proceed with basic configuration as with any fresh OpenWRT install. With OpenWRT the default IP address of the router is 192.168.1.1. Connect to the router via Ethernet cable using telnet or web GUI. The router should now be configured to connect to the Internet. The following example supposes that the MR-3020 router is connected to a gateway configured with 192.168.1.1.

root@OpenWrt:~# vi /etc/config/network
config interface 'lan'
        option ifname 'eth0'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.1.66'
        option netmask '255.255.255.0'
        option gateway '192.168.1.1'
        list dns '192.168.1.1'
        list dns '8.8.8.8'

root@OpenWrt:~#vi /etc/config/wireless
config wifi-device 'radio0'
        option type 'mac80211'
        option channel '11'
        option macaddr 'f8:d1:11:bd:62:ce'
        option hwmode '11ng'
        option htmode 'HT20'
        list ht_capab 'SHORT-GI-20'
        list ht_capab 'SHORT-GI-40'
        list ht_capab 'RX-STBC1'
        list ht_capab 'DSSS_CCK-40'
        option disabled '0'
        option txpower '27'
        option country 'FR'

config wifi-iface
        option device 'radio0'
        option network 'lan'
        option mode 'ap'
        option ssid 'addroute'
        option encryption 'psk2'
        option key 'hello'

Reboot the routeur by typing reboot or simply unplugging the USB cable. Connect via SSH at 192.168.1.66 and verify that the internet connection is active.

Upgrading from a previous version

If you are upgrading from a previous version of OpenWRT, you can follow this tutorial. If something goes wrong, do not forget that a failsafe mode exists for the MR3020. Start by powering on the TL-MR3020. When the WPS Button starts to blink , push it until it blinks faster. The device is now in Failsafe-Mode. You may access it by using telnet 192.168.1.1. Then, clean up any installed packages:

root@OpenWrt:~# mount_root
root@OpenWrt:~# firstboot

Extroot configuration

Start by removing the luci graphical interface in order to free some space for future package updates. Type the following command multiple times in order to remove all dependencies.

root@OpenWrt:~# opkg remove luci*

Update the packages and install the necessary tools to migrate rootfs on external storage

root@OpenWrt:~# opkg update && opkg install kmod-usb-core kmod-usb2 kmod-usb-storage kmod-fs-ext4 block-mount kmod-usb-uhci kmod-usb-ohci

On a linux machine, plug a usb external drive or a memory stick. Start by wiping existing partition table from USB memory stick. In order to identify the name of the corresponding device, take a look at /var/log/syslog. Type dd if=/dev/zero of=/dev/sda bs=64k count=1

Partition USB memory stick with 64M swap, 256M root and rest as third partition

cat | fdisk /dev/sda <<__EOF__
n
p
1
1
+64M
t
82
n
p
2

+256M
n
p
3


w
q
__EOF__

Verify the created partitions:

root@OpenWrt:~# fdisk -l /dev/sda

Disk /dev/sda: 4206 MB, 4206886912 bytes
130 heads, 62 sectors/track, 1019 cylinders
Units = cylinders of 8060 * 512 = 4126720 bytes
Disk identifier: 0xcb85d70e

 Device Boot Start End Blocks Id System
/dev/sda1 1 17 68479 82 Linux swap / Solaris
/dev/sda2 18 80 253890 83 Linux
/dev/sda3 81 1019 3784170 83 Linux

Create swap and filesystems, also set unique label in addition to automatically generated uuid

mkfs.ext3 /dev/sda2 -L ow_root_`dd if=/dev/urandom bs=1k count=1|tr -dc "a-f0-9"|cut -c1-6`
mkfs.ext3 /dev/sda3 -L ow_data_`dd if=/dev/urandom bs=1k count=1|tr -dc "a-f0-9"|cut -c1-6`

Get back to your router and activate swap:

root@OpenWrt:~# mkswap /dev/sda1 -L ow_swap_`dd if=/dev/urandom bs=1k count=1|tr -dc "a-f0-9"|cut -c1-6`

Check label and uuid with blkid command

root@OpenWrt:~# blkid
/dev/mtdblock2: TYPE="squashfs"
/dev/sda1: TYPE="swap" LABEL="ow_swap_53bdb3" UUID="3ebd4c59-fffd-47b5-b598-136ff740a20f"
/dev/sda2: LABEL="ow_root_f479b3" UUID="0b4dfe19-3f7d-4579-983c-452ed9e4bc83" SEC_TYPE="ext2" TYPE="ext3"
/dev/sda3: LABEL="ow_data_8505fb" UUID="a6ca6666-7639-4825-9eee-727718affd19" SEC_TYPE="ext2" TYPE="ext3" 

Configure swap to be enabled on next boot

/etc/init.d/fstab stop
uci delete fstab.@swap[0]
uci commit fstab
uci add fstab swap
# Works with /dev/sda1 as device
#uci set fstab.@swap[-1].device=/dev/sda1
# Fails with label
#uci set fstab.@swap[-1].label=`blkid -s LABEL /dev/sda1 | cut -d\" -f2`
# Fails with uuid
uci set fstab.@swap[-1].uuid=`blkid -s UUID /dev/sda1 | cut -d\" -f2`
uci set fstab.@swap[-1].enabled=1
uci commit fstab

Configure extroot to be mounted on next boot

uci delete fstab.@mount[0]
uci commit fstab
uci add fstab mount
# Works with /dev/sda2 as device
#uci set fstab.@mount[-1].device=/dev/sda2
# Fails with label
#uci set fstab.@mount[-1].label=`blkid -s LABEL /dev/sda2 | cut -d\" -f2`
# Fails with uuid
uci set fstab.@mount[-1].uuid=`blkid -s UUID /dev/sda2 | cut -d\" -f2`
uci set fstab.@mount[-1].options=rw,sync,noatime
uci set fstab.@mount[-1].fstype=ext3
uci set fstab.@mount[-1].enabled_fsck=1
uci set fstab.@mount[-1].enabled=1
uci set fstab.@mount[-1].target=/
# or with target=/overlay if using overlay mode
uci commit fstab # Configure data partition to be mounted on next boot
mkdir -p /mnt/data
uci add fstab mount
# Works with /dev/sda3 as device
#uci set fstab.@mount[-1].device=/dev/sda3
# Fails with label
#uci set fstab.@mount[-1].label=`blkid -s LABEL /dev/sda3 | cut -d\" -f2`
# Fails with uuid
uci set fstab.@mount[-1].uuid=`blkid -s UUID /dev/sda3 | cut -d\" -f2`
uci set fstab.@mount[-1].options=rw,sync,noatime
uci set fstab.@mount[-1].fstype=ext3
uci set fstab.@mount[-1].enabled_fsck=1
uci set fstab.@mount[-1].enabled=1
uci set fstab.@mount[-1].target=/mnt/data
uci commit fstab 
# Disable anon mount feature
uci set fstab.automount.anon_mount=0
uci commit fstab

Check the resulting /etc/config/fstab:

root@OpenWrt:~# cat /etc/config/fstab
config 'global' 'automount'
 option 'from_fstab' '1'
 option 'anon_mount' '0'
config 'global' 'autoswap'
 option 'from_fstab' '1'
 option 'anon_swap' '0'
config 'swap'
 option 'uuid' '3ebd4c59-fffd-47b5-b598-136ff740a20f'
 option 'enabled' '1'
config 'mount'
 option 'uuid' '0b4dfe19-3f7d-4579-983c-452ed9e4bc83'
 option 'options' 'rw,sync,noatime'
 option 'fstype' 'ext3'
 option 'enabled_fsck' '1'
 option 'enabled' '1'
 option 'target' '/'
config 'mount'
 option 'uuid' 'a6ca6666-7639-4825-9eee-727718affd19'
 option 'options' 'rw,sync,noatime'
 option 'fstype' 'ext3'
 option 'enabled_fsck' '1'
 option 'enabled' '1'
 option 'target' '/mnt/data'

Populate new rootfs with content of existing rootfs

mkdir -p /mnt/sda2 /tmp/cproot
mount --bind / /tmp/cproot
mount /dev/sda2 /mnt/sda2
tar -C /tmp/cproot -cvf - . | tar -C /mnt/sda2 -xf -
sync; umount /mnt/sda2 ; umount /tmp/cproot

Activate extroot on next boot

/etc/init.d/fstab enable
/etc/init.d/fstab start
/etc/init.d/fstab whole_root_enable
# or if using overlay mode
#/etc/init.d/fstab overlay_enable

Reboot router reboot # Login and check mounts after restart Looks like extroot is not working but data partition was properly mounted with uuid

root@OpenWrt:~# df -h
Filesystem Size Used Available Use% Mounted on
rootfs 1.5M 848.0K 688.0K 55% /
/dev/root 1.5M 1.5M 0 100% /rom
tmpfs 14.4M 64.0K 14.3M 0% /tmp
tmpfs 512.0K 0 512.0K 0% /dev
/dev/mtdblock3 1.5M 848.0K 688.0K 55% /overlay
overlayfs:/overlay 1.5M 848.0K 688.0K 55% /
/dev/sda2 240.1M 12.0M 215.7M 5% /tmp/whole_root-disabled
/dev/sda3 3.6G 71.3M 3.3G 2% /mnt/data

Check that uuid's are still in place with blkid

root@OpenWrt:~# blkid
/dev/mtdblock2: TYPE="squashfs"
/dev/sda1: TYPE="swap" LABEL="ow_swap_53bdb3" UUID="3ebd4c59-fffd-47b5-b598-136ff740a20f"
/dev/sda2: LABEL="ow_root_f479b3" UUID="0b4dfe19-3f7d-4579-983c-452ed9e4bc83" SEC_TYPE="ext2" TYPE="ext3"
/dev/sda3: LABEL="ow_data_8505fb" UUID="a6ca6666-7639-4825-9eee-727718affd19" SEC_TYPE="ext2" TYPE="ext3"

Swap seems to be enabled

root@OpenWrt:~# free
 total used free shared buffers
Mem: 29436 17936 11500 0 2244
-/+ buffers: 15692 13744
Swap: 68472 0 68472

Switch from uuid's to device names

uci delete fstab.@swap[-1].uuid
uci set fstab.@swap[-1].device=/dev/sda1
uci delete fstab.@mount[0].uuid
uci set fstab.@mount[0].device=/dev/sda2
uci delete fstab.@mount[1].uuid
uci set fstab.@mount[1].device=/dev/sda3
uci commit

Resulting /etc/config/fstab

root@OpenWrt:~# cat /etc/config/fstab
config 'global' 'automount'
 option 'from_fstab' '1'
 option 'anon_mount' '0'
config 'global' 'autoswap'
 option 'from_fstab' '1'
 option 'anon_swap' '0'
config 'swap'
 option 'enabled' '1'
 option 'device' '/dev/sda1'
config 'mount'
 option 'options' 'rw,sync,noatime'
 option 'fstype' 'ext3'
 option 'enabled_fsck' '1'
 option 'enabled' '1'
 option 'target' '/'
 option 'device' '/dev/sda2'
config 'mount'
 option 'options' 'rw,sync,noatime'
 option 'fstype' 'ext3'
 option 'enabled_fsck' '1'
 option 'enabled' '1'
 option 'target' '/mnt/data'
 option 'device' '/dev/sda3'

Re-enable extroot

/etc/init.d/fstab enable
/etc/init.d/fstab start
/etc/init.d/fstab whole_root_enable

Reboot and check if extroot is working

root@OpenWrt:~# df -h
Filesystem Size Used Available Use% Mounted on
rootfs 240.1M 12.0M 215.7M 5% /
/dev/root 1.5M 1.5M 0 100% /rom
tmpfs 14.4M 60.0K 14.3M 0% /tmp
tmpfs 512.0K 0 512.0K 0% /dev
/dev/sda2 240.1M 12.0M 215.7M 5% /
/dev/sda3 3.6G 71.3M 3.3G 2% /mnt/data

Yes, seems to work now !

mr3020_with_openwrt.txt · Last modified: 2014/01/11 05:28 by 127.0.0.1