On the weekend I’ve been hacking a TP-Link MR3220 for my friend Penya. The router has a USB port and I wanted to use a USB flash drive to expand the storage space available on the router. I had two flash drives, one noname 1GB and a Sandisk Cruzer 8GB. I had problems with the noname drive, random disconnects during data writing etc. so I used the Sandisk one.

First I formatted the drive to ext4 under Ubuntu, then plugged it in the router. After logging in with SSH, I installed the needed USB storage modules: opkg update; opkg install kmod-usb-storage kmod-fs-ext4. After that I was able to mount the drive under /mnt/pendrive1 (I had to create that directory to mount to): mount /dev/sda1 /mnt/pendrive1

If it says that there’s no /dev/sda1 device, look at dmesg to find out the newly attached flash drive’s device name. I wanted automount, so I installed the needed packages: opkg install blkid block-mount e2fsprogs

I edited /etc/config/fstab:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
config global automount
    option from_fstab 1
    option anon_mount 1

config global autoswap
    option from_fstab 1
    option anon_swap 0

config mount
    option target   /mnt/pendrive1
#   option device   /dev/sda1
    option uuid "88e22364-e0c5-42ca-b4e1-d5e9fa9d21ab"
    option fstype   ext4
    option options  rw,sync
    option enabled  1
    option enabled_fsck 1

config swap
    option device   /dev/sda2
    option enabled  0

Note that I set the UUID instead of the device name. It’s useful if the drive comes up under a different device name. UUID uniquely identifies it. To find out your drive’s UUID, run blkid. If you have a swap partition on your drive and want to use it as swap space, you can set it here.

After finishing with the config I ran the following commands:

1
2
3
4
rm -f /etc/fstab
ln -s /tmp/fstab /etc/fstab
/etc/init.d/fstab enable
/etc/init.d/fstab start

If the last command freezes for some reason, run rm /var/lock/fstab.lck before it. If all goes well, now you have your flash drive automounting if it’s plugged in.

To install packages on the drive, you have to add it to the opkg destination list. Edit /etc/opkg.conf:

1
2
3
4
5
6
src/gz snapshots http://downloads.openwrt.org/snapshots/trunk/ar71xx/packages
dest root /
dest ram /tmp
dest pendrive /mnt/pendrive1
lists_dir ext /var/opkg-lists
option overlay_root /overlay

(Notice the dest pendrive line, I added only that to the file.)

After that you can install packages using the drive this way: opkg install -d pendrive packagename.

It’s usefule to add the bin and sbin directories on the flash drive to the PATH, so edit it in /etc/profile:

1
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/mnt/pendrive1/bin:/mnt/pendrive1/sbin:/mnt/pendrive1/usr/bin:/mnt/pendrive1/usr/sbin

You’ll need to configure ldconfig for the dynamic libraries on the drive to work, if you don’t have ldconfig yet, install it: opkg install -d pendrive ldconfig

Add these lines to ld.so.conf:

1
2
/mnt/pendrive1/lib
/mnt/pendrive1/usr/lib

And then run ldconfig every time you install a lib.

Installing Midnight Commander on OpenWRT

It’s nice to have mc on the router, so let’s install it:

1
2
3
4
5
opkg install -d pendrive mc librpc
ln -s /mnt/pendrive1/etc/mc /etc/mc
touch /etc/mc/sfs.ini
mkdir -p /usr/lib/mc/extfs.d
touch /root/.mc/cedit/Syntax

If mc says error opening terminal: xterm, then make sure you have these lines in /etc/profile:

1
2
export TERMINFO=/mnt/pendrive1/usr/share/terminfo
export TERM=linux

Using a webcam on OpenWRT

Install the needed kernel modules (for my webcam, kmod-video-uvc) and the capture application (in this case fswebcam) with opkg install -d pendrive kernel kmod-video-uvc fswebcam. Create the module loader shell script /etc/init.d/webcam:

1
2
3
4
5
#!/bin/sh
insmod /mnt/pendrive1/lib/modules/2.6.39.4/i2c-dev.ko
insmod /mnt/pendrive1/lib/modules/2.6.39.4/videodev.ko
insmod /mnt/pendrive1/lib/modules/2.6.39.4/v4l2-common.ko
insmod /mnt/pendrive1/lib/modules/2.6.39.4/uvcvideo.ko

If you want it to autostart at boot, run chmod +x /etc/init.d/webcam. To capture an image, run: fswebcam –jpeg 100 –save c.jpeg -r 640×480 -v

Luis Moreira 2012-06-20 21:18:38

Hi, I just followed your tutorial! thanks a lot! But I’m having a small dificultie, all the packages that I install, when I try to run them I get Permission denied! Also to try to run them I must go to /etc/mc for instance. Am I doing anything wrong?

Nonoo 2012-06-20 22:42:40

I think you doesn’t have a Linux filesystem (like ext2/3/4) on your flash drive. FAT32 or NTFS doesn’t handle Unix permissions (like execute).

 
 
Name (required)
E-mail (required - never shown publicly)
Webpage URL
Comment:
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> in your comment.

Trackback responses to this post

About me

Nonoo
I'm Nonoo. This is my blog about music, sounds, filmmaking, amateur radio, computers, programming, electronics and other things I'm obsessed with. ... »

Twitter

Listening now

My favorite artists