What's new

USB drive mounting twice as different devices

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

macdis

Occasional Visitor
I have a setup with two USB drives, which I mount as /tmp/mnt/front and /tmp/mnt/back. /tmp/mnt/front is a time machine drive and /tmp/mnt/back is where my Entware install resides. I use a post-mount script to create the symlink to the Entware install and to start /opt/etc/init.d/rc.unslung (I have also tried the default method using services-start, but this doesn't seem to change anything).

The problem is that the Entware drive is frequently (but not always) inaccessible after boot. The reason seems to be that the system mounts the drive to /tmp/mnt/back twice, first as /dev/sda1 and then again as /dev/sdc1. I can see this happening at boot time by running mount repeatedly from the command prompt. Here is an example where I saw them both mounted at once:

Code:
admin@R7000:/tmp/home/root# mount
[blah blah blah]
/dev/sda1 on /tmp/mnt/back type ext4 (rw,nodev,relatime,barrier=1,data=ordered)
/dev/sdc1 on /tmp/mnt/back type ext4 (rw,nodev,relatime,barrier=1,data=ordered)

After a while, the mounting process settles down and the system unmounts /dev/sda1, and mount returns the final result:

Code:
admin@R7000:/tmp/home/root# mount
[blah blah blah]
/dev/sdc1 on /tmp/mnt/back type ext4 (rw,nodev,relatime,barrier=1,data=ordered)

So what seems to be happening is this: the rear drive mounts as /dev/sda1, the post-mount script links to and starts Entware, but then the system unmounts /dev/sda1 and remounts it as /dev/sdc1, which breaks Entware: /opt appears empty and so nothing related to Entware works.

To make sure the drives mount correctly at boot time, I currently mount them using init-start, which makes the mount points and creates /etc/fstab using the two drive UUIDs. (I've also tried two other methods: by using partition labels and by creating /jffs/configs/fstab rather than using init-start to create /etc/fstab, but the results seem to be the same in all cases. I've also tried an ext3 file system for the Entware install with the same results.)

I suppose I could probably add something like this to my post-mount script, with the first grep referencing the UUID of the rear drive (I abbreviated the UUID for readability):

Code:
RAWDEVICE=$(blkid | grep 72203fcc | awk '{ print $1 }' | tr -d :)
MOUNTED=$(mount | grep /tmp/mnt/back | awk '{ print $1 } ')
if [ "$RAWDEVICE" != "$MOUNTED" ] ; then
  umount /tmp/mnt/back && mount -a
fi

But this seems kludgey. (***EDIT: This does not work in this form, never mind.***)

So my question is: Why is the system mounting the drive twice, first as /dev/sda1 and then as /dev/sdc1? Is there a way to get it to mount it once only, correctly?

Thanks!

P.S. My post-mount script (adapted from somewhere here) is this:

Code:
#!/bin/sh

logger -t $(basename $0) "started [$@]"

if [ "$1" = "/tmp/mnt/back" ] ; then
  sleep 10
  ln -sf $1/entware /tmp/opt
  # Wait up to 30 seconds to make sure /tmp/mnt/back is mounted
  i=0
  while [ $i -le 30 ]
  do
    if [ -d /tmp/mnt/back ] ; then
      logger -t $(basename $0) "USB drive mounted, starting Entware services"
      break
    fi
    sleep 1
    i=`expr $i + 1`
  done
  /opt/etc/init.d/rc.unslung start
fi

And my init-start script is this:

Code:
#!/bin/sh
mkdir -p /tmp/mnt/back
mkdir -p /tmp/mnt/front
echo "UUID=72203fcc /tmp/mnt/back ext4 defaults,nodev 0 0" > /etc/fstab
echo "UUID=59bb1d05 /tmp/mnt/front ext3 defaults,nodev 0 0" >> /etc/fstab
 
Last edited:

Similar threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top