Openwrt uci: Parse error (invalid command) at line, byte

While setting up wifi on my MR3020 and doing a uci show i got the following error

root@LEDE:~# uci show
uci: Parse error (invalid command) at line 2, byte 0

So obviously I messed up a config file somewhere but the error wasn’t very informative. So after some googling i found the following command which will tell you which file/line is the issue.

root@LEDE:~# for CONF in /etc/config/* ; do uci show "${CONF##*/}" > /dev/null || echo "${CONF}"; done

uci: Parse error (invalid command) at line 2, byte 0
/etc/config/wireless

Checked the /etc/config/wireless file and i had made a typo.

Continue Reading

TP-Link MR3020 Openwrt Rootfs On External Storage / Extroot Usb Flash

I had a little project suitable for openwrt planned and had a spare tp-link MR3020 V1 but their limited flash of only 4MB would cause me problems so thought I’d set one up to use external usb storage.

This article assumes you have have prior knowledge of flashing openwrt to the device and ability to use ssh commands via the shell.

**** I accept no responsibility for any data loss/bricking etc as a result of using this guide ****

You will need….
MR3020 V1
USB flash drive of your choosing (I used a 32Gb San Cruzer Fit)

Insert flash drive into a linux machine with fdisk installed (I had a pi booted up so used that)

Firstly you need to find your drive mine was /dev/sdg

pi@raspberrypi:~ $ sudo fdisk -l

This listed all my disks and after scrolling through it I found one that matched my usb flash.

Disk /dev/sdg: 29.3 GiB, 31406948352 bytes, 61341696 sectors
Disk model: Cruzer Fit
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Now you need to check if the drive has been auto mounted and if so unmount it

mount

/dev/sdg1 on /media/pi/CCDE-DC77 type vfat (rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022,
codepage=437,iocharset=ascii,shortname=mixed,showexec,utf8,flush,errors=remount-ro,uhelper=udisks2)

umount /dev/sdg1

CONFIRM YOU HAVE THE CORRECT DEVICE IT’S LIKELY IT WILL BE DIFFERENT TO MINE /DEV/SDG THE FOLLOWING STEPS WILL DELETE/CREATE NEW PARITIONS SO IF YOU HAVE THE WRONG DEVICE DATA LOSS WILL OCCUR!

Next run the fdisk utility

YOU HAVE THE CORRECT DEVICE RIGHT?

sudo fdisk /dev/sdg

Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Get current partition layout

Command (m for help): p
Disk /dev/sdg: 29.3 GiB, 31406948352 bytes, 61341696 sectors
Disk model: Cruzer Fit
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device Boot Start End Sectors Size Id Type
/dev/sdg1 32 61341695 61341664 29.3G c W95 FAT32 (LBA)

This is the default partition that comes from the factory and is no good to use so we delete it using

Command (m for help): d
Selected partition 1
Partition 1 has been deleted.

Next up we create the swap partition (adjust the size to suit your requirements I’m using 512MB)

Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):

Using default response p.
Partition number (1-4, default 1):
First sector (2048-61341695, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-61341695, default 61341695): +512M

Created a new partition 1 of type 'Linux' and of size 512 MiB.

Next create Linux partition that fills the remainder of the drive

Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p):

Using default response p.
Partition number (2-4, default 2):
First sector (1050624-61341695, default 1050624):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1050624-61341695, default 61341695):

Created a new partition 2 of type 'Linux' and of size 28.8 GiB.

Now display the partitions you have just created

Command (m for help): p

Disk /dev/sdg: 29.3 GiB, 31406948352 bytes, 61341696 sectors
Disk model: Cruzer Fit
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device Boot Start End Sectors Size Id Type
/dev/sdg1 2048 1050623 1048576 512M 83 Linux
/dev/sdg2 1050624 61341695 60291072 28.8G 83 Linux

Great both there BUT the first one we created to use for swap has the “type” Linux so we need to change this using

Command (m for help): t
Partition number (1,2, default 2): 1
Hex code (type L to list all codes): 82

Changed type of partition 'Linux' to 'Linux swap / Solaris'.

Again print the partitions and the first one should now display Type Linux swap / Solaris

Command (m for help): p
Disk /dev/sdg: 29.3 GiB, 31406948352 bytes, 61341696 sectors
Disk model: Cruzer Fit
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device Boot Start End Sectors Size Id Type
/dev/sdg1 2048 1050623 1048576 512M 82 Linux swap / Solaris
/dev/sdg2 1050624 61341695 60291072 28.8G 83 Linux

That is all that needs to be done for this part so type “w” to save the changes.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Now format the swap partition with

pi@raspberrypi:~ $ sudo mkswap /dev/sdg1
Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
no label, UUID=469ce4c2-824e-4195-8d4d-f7ffd99c9b8d

And the same for the ext4 partition

pi@raspberrypi:~ $ sudo mkfs.ext4 /dev/sdg2
mke2fs 1.44.5 (15-Dec-2018)
Creating filesystem with 7536384 4k blocks and 1884160 inodes
Filesystem UUID: 4c33797a-ce68-480f-bfcc-5e2b0f13e4fe
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

We have now prepared our storage drive to use with linux and can now be safely removed from your machine.

In order to be able to use this drive with openwrt some packages need to be installed. To make life easier I created a custom image via the image builder with the following extra packages (i’ve also included fdisk should you wish to partition your drive directly on your openwrt device). If you don’t use the custom image you will need to install these packages on your MR3020 yourself using opkg.

block-mount kmod-fs-ext4 kmod-usb-storage kmod-usb-ohci kmod-usb-uhci f2fsck fdisk

A copy of the images can be found here….
Factory – Use when flahsing openwrt for the first time from stock tp-link firmware
Sysupgrade – Use when upgrading an existing openwrt installation

NOTE: Luci is not installed as we will do that later so all configuration must be done via ssh/command line.

Connect and ethernet cable from your chosen device to the MR3020, insert the usb flash drive and power on, open a terminal/putty and ssh to the default openwrt ip of 192.168.1.1 the username is root and with no password.

Let’s see if the drive was detected….

root@LEDE:~# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2

Great! now we can mount the drive

mkdir /mnt/sda2
mount /dev/sda2 /mnt/sda2

Check it’s mounted

mount | grep sda2
/dev/sda2 on /mnt/sda2 type ext4 (rw,relatime,data=ordered)

Copy existing fs to the usb flash drive

tar -C /overlay -cvf - . | tar -C /mnt/sda2 -xf -

Backup fstab

cp /etc/config/fstab /etc/config/fstab.orig

Update fstab to reflect changes (delete existing contents and paste below assuming your device is sda)

root@LEDE:~# vi /etc/config/fstab

config 'global'
option anon_swap '0'
option anon_mount '0'
option auto_swap '1'
option auto_mount '1'
option delay_root '5'
option check_fs '0'

config swap
option device '/dev/sda1'
option enabled '1'

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

Save & Exit

Reboot (and cross your fingers)

Reconnect via ssh

Check usb flash is mounted on /overlay

root@LEDE:~# df -h /overlay
Filesystem Size Used Available Use% Mounted on
/dev/sda2 28.2G 44.1M 26.7G 0% /overlay

Check swap is present

root@LEDE:~# free
total used free shared buffers cached
Mem: 27912 20232 7680 60 2412 6044
-/+ buffers/cache: 11776 16136
Swap: 524284 0 524284

And there you have it, you’ve now increased your strangled MR3020 form 4MB flash to 32GB (ish) and RAM from 8MB to 512MB.

Continue Reading