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:
config global automount
option from_fstab 1
option anon_mount 1
config global autoswap
option from_fstab 1
option anon_swap 0
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
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:
rm -f /etc/fstab
ln -s /tmp/fstab /etc/fstab
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:
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:
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:
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:
opkg install -d pendrive mc librpc
ln -s /mnt/pendrive1/etc/mc /etc/mc
mkdir -p /usr/lib/mc/extfs.d
If mc says error opening terminal: xterm, then make sure you have these lines in /etc/profile:
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:
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