Wait for USB

Having installed Debian GNU/Linux 5.0 (“lenny”) on a PC Engines Alix 2D3 system I ran into problems with the external USB disk drive not being mounted at boot-up.

Mounting local filesystems…mount: special device UUID=… does not exist

These error messages were coming when /etc/rcS.d/S35mountall.sh was attempting to mount all the local filesystems from /etc/fstab. In my case the USB subsystem had not yet initialised and so the entries in /dev had not been created yet.

I could simply wait until booting has finished and mount the partitions manually, or add them to /etc/rc.local, but I was after a more elegant solution.

The answer is to introduce a deliberate pause into the boot sequence to allow the USB subsystem to initialise before the mounts are started.

# Script to force boot sequence to wait for USB disk detection
# Copy to /etc/init.d/waitforusb
# ln -s /etc/init.d/waitforusb /etc/rcS.d/S25waitforusb
# Disk drive mount we're waiting on
# Max time to wait (in seconds)
case "$1" in
  echo "Waiting for USB disk drive $usbdrive"
  for (( i = 0; i <= $maxwait; i++ ))
    [ -b $usbdrive ] && exit 0
    echo -n "."
    sleep 1
  exit 1

Copy this startup file to /etc/init.d and then create a symbolic link in /etc/rcS.d just before the filesystem checks:

ln -s /etc/init.d/waitforusb /etc/rcS.d/S25waitforusb

The script will check for the disk drive entries in /dev every second and allow boot execution to continue when it’s there. There is a safety timeout which allows execution to continue regardless after 30 seconds.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s