Saturday, February 11, 2012

OpenWRT and USB mounting

OpenWrt is a very nice open source router firmware. It runs Linux and is more like a distro than a typical router firmware. I have a Linksys WRT160NL with a USB port so I wanted to hook up a disk to have a SMB share. OpenWRT supports ext4 and this is the recommended filesystem.

To start install the packages required to access the USB and mount the filesystem. You can use uci command or LuCI web interface to configure the mount point.

Here comes the tricky part. The default priority order of init scripts starts usb after mounting fstab. This is a problem since mounting will fail. The results is hdd not mounting at startup but if you restart the fstab init script the mount works.

To overcome this problem simply change the priority of fstab init script:
cd /etc/init.d/
vi fstab

Change top line containing the START variable to:
START=59

Now just run:
./fstab disable
./fstab enable

This will setup correct symlinks in:
/etc/rc.d

Now the mounting works correctly on startup.

Thursday, February 9, 2012

How to grep a binary file

Usually grep is used while working with text files. It can also be used with binary files. However a line or line number is probably note very useful in this case.

To get the byte offset you can use:
grep -boa "$PATTERN"