Saturday, October 01, 2011

Persistent USB mount locations on Pogoplug (and other Linux devices)

In a previous post, I talked about how I set up rsync on my Pogoplug Biz for church. I had mentioned a Couple of “Gotchas”, such as the way USB drives may be a different device name upon reboot. This makes it hard to find the Optware drive consistently. Here is my solution.

Basically, you want to get the e2fs libraries and programs, then use blkid and findfs to locate the drive. As of Oct 2011, the links below are correct, but be sure to check http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/stable/ and replace the file names as necessary.

The commands below will download and copy the necessary libraries and e2fs utilities for mounting your flash drive in the same location. I am assuming you are going to use the device UUID instead of the drive lable to locate the drive, but both are possible. I also assume that you want to modify the NAND (the Pogoplug internal flash drive) as little as possible. I am ONLY copying the files necessary for this task of finding and mounting specific USB drives to specific locations upon reboot.

Getting the e2fs libraries and utilities


cd /tmp
wget http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/stable/e2fslibs_1.41.14-1_arm.ipk
tar xvzf e2fslibs_1.41.14-1_arm.ipk
tar xvzf data.tar.gz


wget http://ipkg.nslu2-linux.org/feeds/optware/cs08q1armel/cross/stable/e2fsprogs_1.41.14-1_arm.ipk
tar xvzf e2fsprogs_1.41.14-1_arm.ipk
tar xvzf data.tar.gz


Copying the e2fs files to the internal flash memory
The following command makes it possible to change the Pogoplug flash memory, so be careful from here on out! Also, I am assuming that /usr/sbin is on your PATH.


mount / -o remount,rw,noatime


cd /tmp/opt/lib
mv libb* /usr/lib
mv libc* /usr/lib
mv libe* /usr/lib
mv libu* /usr/lib


cd /tmp/opt/sbin
mv blkid /usr/sbin
mv findfs /usr/sbin


OK, this puts the files on the NAND and I can use blkid to locate the optware flash drive by UUID, and use findfs use in /etc/init.d/rcS to mount it to /opt. Next I need to locate the actual device UUID for the startup script. Run blkid to get the UUID, and write this down.

blkid
/dev/sda1: UUID="2CB9-87AD" TYPE="vfat" LABEL="LeeJones"
/dev/sdb1: UUID="fc640330-9e49" TYPE="ext3" LABEL="OPTWARE"

NOTE: the UUID and LABEL are case sensitive.

In this case, my Optware drive has a UUID of fc640330-9349. Now we should be able to locate the Optware USB drive (or any particular drive) with the findfs command:


findfs UUID="fc640330-9e49"

This returns the result of /dev/sdb1


Editing the startup /etc/init.d/rcS script

Using your favorite text editor, add the following line to /etc/init.d/rcS before anything calls /opt

mount `findfs UUID="fc640330-9e49"` /opt

NOTE: The character before findfs is a back quote (`) not an apostrophe ('). Look for the back quote on the tilde key (~) next to your number 1 key.

Once you have saved the changes to rcS, reboot:

mount / -o remount,ro
sync
sync
reboot

Extra Credit

Personally, I want to minimize the changes to my copy of /etc/init.d/rcS, so mine is the factory default one plus the following two extra lines at the end:

mount `findfs UUID="fc640330-9e49"` /opt # mounts Optware USB
/opt/etc/init.d/optrun.sh # runs additional software

The contents of /opt/etc/init.d/optrun.sh are as follows:

#!/bin/sh
# runs optware startups in sort order
cd /opt/etc/init.d
for i in `ls S* | sort`
do
  ./$i start
done

This allows me to make minimal changes to /etc/init.d/rcS, just enough to find and properly mount Optware to /opt every single reboot. The optrun.sh command starts any additional things I want, such as rsync. Anything file in /opt/etc/init.d that is both executable and begins with a capital S will be ran at boot time.

Also, if I screw up on one on of my additions (been there) and disable my device, all I have to do is power off the Pogoplug, pull out the Optware USB drive and reboot. After a normal boot, I plug the drive back in and fix my mistake.