Welcome! Log In Create A New Profile

Advanced

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

Posted by cdlenfert 
Persistent USB mount locations on Pogoplug (and other Linux devices)
August 08, 2017 10:09PM
I have a Pogoplug that's running Optware and an SMB share which shares 2 external drives on my LAN.

In the past rebooting the Pogo and getting back to where I want to be in terms of the SMB setup has involved
  1. ejecting the drives
  2. unplugging the drives
  3. rebooting the pogoplug
  4. plugging the drives in 1 x 1 so they get mounted on the right location

A while back I remember seeing this guide about getting persistent mount locations on the Pogo. http://www.leeandcathy.com/2011/10/persistent-usb-mount-locations-on.html

It wasn't until recently that I understood what it was doing, and how it accomplished the task of mounting the USB on /opt every time

I thought I could apply the same approach to my standard USBs (as I have the /opt directory on my internal flash on my E-02).
And the following commands work to mount my drives to the proper point on my root if I run them manually, but don't work after a reboot in the startup script: I threw in the /opt mount command and the samba start command to show where they these findfs commands live in my /etc/init.d/rcS script.

mount /dev/mtdblock3 /opt
mount `findfs UUID="A6A0CA0F20419853"` /pogo1
mount `findfs UUID="21E599BF9F0F2CAB"` /pogo2

opt/etc/init.d/S08samba start

Is it possible it's failing because the drives aren't recognized quickly enough to be mounted properly before Samba starts? Is there any way to fix this, like delaying the samba startup, or maybe forcing the mount commands to execute successfully before moving to the next step.

Thanks for any ideas. If nothing else, it's nice to know I can reboot and run those mount command manually and regardless of which drive the Pogoplug mounts first, I can assign them to the right points, restart Samba and they will be properly mapped.
Re: Persistent USB mount locations on Pogoplug (and other Linux devices)
August 09, 2017 12:36AM
cdlenfert,

> I have a Pogoplug that's running Optware and an SM
> B share which shares 2 external drives on my LAN.

> I thought I could apply the same approach to my st
> andard USBs (as I have the /opt directory on my in
> ternal flash on my E-02).

When you run Debian, there is really no need for Optware. But I understood that you just want to use the same setup between stock OS and Debian.

> Is it possible it's failing because the drives are
> n't recognized quickly enough to be mounted proper
> ly before Samba starts?

It is likely the case. sysvinit scripts run in multiple threads, so your sequence of commands will have some race condition.

However, with question like this, you should always post the kernel version that you are running. Because my kernel configuration changes when users post some report that cause me to make some minor configuration changes in newer versions.
uname -a

> Is there any way to fix th
> is, like delaying the samba startup, or maybe forc
> ing the mount commands to execute successfully bef
> ore moving to the next step.

You could have wait up to 10 seconds for each mount to succeed before proceeding to start Samba (you would not want to wait forever).

Something simple like this (you'll need to test it, I'm writing on top of my head):
mount /dev/mtdblock3 /opt
mount `findfs UUID="A6A0CA0F20419853"` /pogo1
mount `findfs UUID="21E599BF9F0F2CAB"` /pogo2

for num in 0 1 2 3 4 5 6 7 8 9; do
	if /bin/mountpoint  /pogo1 -q ; then
		break
       fi
       sleep 1
done
for num in 0 1 2 3 4 5 6 7 8 9; do
	if /bin/mountpoint  /pogo2 -q ; then
		break
       fi
       sleep 1
done

opt/etc/init.d/S08samba start

-bodhi
===========================
Wiki
latest Kirkwood kernel builds and rootfs
latest u-boot-kirkwood builds
latest Oxnas kernel builds and rootfs
latest u-boot-oxnas builds
latest MVEBU Armada kernel builds and rootfs
U-Boot & Kernel Booting process
bodhi's u-boot GitHub
bodhi's corner
Re: Persistent USB mount locations on Pogoplug (and other Linux devices)
August 09, 2017 10:34AM
Thanks Bodhi!

Adding those conditionals to the startup script managed to get 2 of the 3 drives (I added another) to mount automatically and be available via SMB. The one that failed to auto-mount was /pogo1 which was first in the list. Maybe it just needs a little more time.

Can you explain how the conditional works? My understanding is that it's saying ... "If there is a drive mounted to /pogoX, then continue on, otherwise wait 1 second and check again (up to 9 tries).

Maybe I can add more time to the /pogo1 conditional, or simply move it to the bottom of the conditionals? My other thought is, maybe I should add a "wait" command before the mount commands?
Re: Persistent USB mount locations on Pogoplug (and other Linux devices)
August 09, 2017 07:21PM
cdlenfert,

> Can you explain how the conditional works? My unde
> rstanding is that it's saying ... "If there is a d
> rive mounted to /pogoX, then continue on, otherwis
> e wait 1 second and check again (up to 9 tries).
>
> Maybe I can add more time to the /pogo1 conditiona
> l, or simply move it to the bottom of the conditio
> nals? My other thought is, maybe I should add a "w
> ait" command before the mount commands?

That was just an example. What you really need to do is to create a script and then do the mount in a for/while statement similar to what I posted. You should not put a lot of commands in the system init scripts that are going to have race conditiion.

The separate script could be like this (again, you need to make sure to do research about how to write scripts that run in the sysvinit scripts).
#!/bin/sh
#

mount /dev/mtdblock3 /opt

mount `findfs UUID="A6A0CA0F20419853"` /pogo1
for num in 0 1 2 3 4 5 6 7 8 9; do
	if /bin/mountpoint  /pogo1 -q ; then
		break
       fi
       sleep 1
done

mount `findfs UUID="21E599BF9F0F2CAB"` /pogo2
for num in 0 1 2 3 4 5 6 7 8 9; do
	if /bin/mountpoint  /pogo2 -q ; then
		break
       fi
       sleep 1
done

opt/etc/init.d/S08samba start

exit 0

=================

Another observation:

Try to find the disk partition label in stock OS for /pogo1 and /pogo2 and use that to mount. It is much better if you can see that it works in stock.

-bodhi
===========================
Wiki
latest Kirkwood kernel builds and rootfs
latest u-boot-kirkwood builds
latest Oxnas kernel builds and rootfs
latest u-boot-oxnas builds
latest MVEBU Armada kernel builds and rootfs
U-Boot & Kernel Booting process
bodhi's u-boot GitHub
bodhi's corner
Re: Persistent USB mount locations on Pogoplug (and other Linux devices)
August 09, 2017 09:03PM
Re: Persistent USB mount locations on Pogoplug (and other Linux devices)
August 10, 2017 11:37AM
I neglected to mention this is a stock Pogoplug E-02 running SMB shares via Optware. Here's the output on the kernel.

[root@Pogoplug ~]# uname -a
Linux Pogoplug 2.6.22.18 #81 Tue Oct 19 16:05:00 PDT 2010 armv5tejl unknown

I put your script above in place and called it in the startup script "etc/init.d/rcS". The end result was the same, but I thought it was cool to see that I didn't botch anything by including it in a separate script.

It's my understanding that the Pogo OS mounts drives in a seemingly random order by default. The mount points in my case are created at:

  1. /tmp/.cemnt/mnt_sda2
  2. /tmp/.cemnt/mnt_sdb2
  3. /tmp/.cemnt/mnt_sdc2

Some others have drives auto mounted at sda1, sdb1, etc. Not sure why mine uses sdX2.

Here is how things are mounting following my script running. The opt, pogo1, pogo2, pogo3 points are ones I created and scripted (with your help:). For some reason /tmp/.cemnt/mnt_sdc2 is not showing up in this list, but the drive that I would expect there is mounted as pogo3. And finally the only reason /dev/sda2 is mounted on pogo1 is because I manually entered the mount command after the reboot was completed.

[root@Pogoplug ~]# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/mtdblock2           32.0M     16.5M     15.5M  51% /
none                    125.0M     52.0k    125.0M   0% /tmp
/dev/mtdblock3           91.0M     51.6M     39.4M  57% /opt
/tmp/.cemnt/sdb2        595.9G    553.0G     42.9G  93% /tmp/.cemnt/mnt_sdb2
/dev/sdb2               595.9G    553.0G     42.9G  93% /pogo2
/dev/sdc2               148.7G      2.5G    146.2G   2% /pogo3
/tmp/.cemnt/sda2        465.4G    333.9G    131.5G  72% /tmp/.cemnt/mnt_sda2
/dev/sda2               465.4G    333.9G    131.5G  72% /pogo1

The ls -l command you supplied didn't work as is, but I changed it to list details about everything under /dev/sd*
Dont' know if that's useful or not, but I'm pasting here just in case.

[root@Pogoplug ~]# ls -l /dev/sd*
brw-r-----    1 root     root       8,   0 Feb 26  2008 /dev/sda
brw-r-----    1 root     root       8,   1 Feb 26  2008 /dev/sda1
brw-r-----    1 root     root       8,  10 Feb 26  2008 /dev/sda10
brw-r-----    1 root     root       8,  11 Feb 26  2008 /dev/sda11
brw-r-----    1 root     root       8,  12 Feb 26  2008 /dev/sda12
brw-r-----    1 root     root       8,  13 Feb 26  2008 /dev/sda13
brw-r-----    1 root     root       8,  14 Feb 26  2008 /dev/sda14
brw-r-----    1 root     root       8,  15 Feb 26  2008 /dev/sda15
brw-r-----    1 root     root       8,   2 Feb 26  2008 /dev/sda2
brw-r-----    1 root     root       8,   3 Feb 26  2008 /dev/sda3
brw-r-----    1 root     root       8,   4 Feb 26  2008 /dev/sda4
brw-r-----    1 root     root       8,   5 Feb 26  2008 /dev/sda5
brw-r-----    1 root     root       8,   6 Feb 26  2008 /dev/sda6
brw-r-----    1 root     root       8,   7 Feb 26  2008 /dev/sda7
brw-r-----    1 root     root       8,   8 Feb 26  2008 /dev/sda8
brw-r-----    1 root     root       8,   9 Feb 26  2008 /dev/sda9
brw-r-----    1 root     root       8,  16 Feb 26  2008 /dev/sdb
brw-r-----    1 root     root       8,  17 Feb 26  2008 /dev/sdb1
brw-r-----    1 root     root       8,  26 Feb 26  2008 /dev/sdb10
brw-r-----    1 root     root       8,  27 Feb 26  2008 /dev/sdb11
brw-r-----    1 root     root       8,  28 Feb 26  2008 /dev/sdb12
brw-r-----    1 root     root       8,  29 Feb 26  2008 /dev/sdb13
brw-r-----    1 root     root       8,  30 Feb 26  2008 /dev/sdb14
brw-r-----    1 root     root       8,  31 Feb 26  2008 /dev/sdb15
brw-r-----    1 root     root       8,  18 Feb 26  2008 /dev/sdb2
brw-r-----    1 root     root       8,  19 Feb 26  2008 /dev/sdb3
brw-r-----    1 root     root       8,  20 Feb 26  2008 /dev/sdb4
brw-r-----    1 root     root       8,  21 Feb 26  2008 /dev/sdb5
brw-r-----    1 root     root       8,  22 Feb 26  2008 /dev/sdb6
brw-r-----    1 root     root       8,  23 Feb 26  2008 /dev/sdb7
brw-r-----    1 root     root       8,  24 Feb 26  2008 /dev/sdb8
brw-r-----    1 root     root       8,  25 Feb 26  2008 /dev/sdb9
brw-r-----    1 root     root       8,  32 Feb 26  2008 /dev/sdc
brw-r-----    1 root     root       8,  33 Feb 26  2008 /dev/sdc1
brw-r-----    1 root     root       8,  42 Feb 26  2008 /dev/sdc10
brw-r-----    1 root     root       8,  43 Feb 26  2008 /dev/sdc11
brw-r-----    1 root     root       8,  44 Feb 26  2008 /dev/sdc12
brw-r-----    1 root     root       8,  45 Feb 26  2008 /dev/sdc13
brw-r-----    1 root     root       8,  46 Feb 26  2008 /dev/sdc14
brw-r-----    1 root     root       8,  47 Feb 26  2008 /dev/sdc15
brw-r-----    1 root     root       8,  34 Feb 26  2008 /dev/sdc2
brw-r-----    1 root     root       8,  35 Feb 26  2008 /dev/sdc3
brw-r-----    1 root     root       8,  36 Feb 26  2008 /dev/sdc4
brw-r-----    1 root     root       8,  37 Feb 26  2008 /dev/sdc5
brw-r-----    1 root     root       8,  38 Feb 26  2008 /dev/sdc6
brw-r-----    1 root     root       8,  39 Feb 26  2008 /dev/sdc7
brw-r-----    1 root     root       8,  40 Feb 26  2008 /dev/sdc8
brw-r-----    1 root     root       8,  41 Feb 26  2008 /dev/sdc9
brw-r-----    1 root     root       8,  48 Feb 26  2008 /dev/sdd
brw-r-----    1 root     root       8,  49 Feb 26  2008 /dev/sdd1
brw-r-----    1 root     root       8,  58 Feb 26  2008 /dev/sdd10
brw-r-----    1 root     root       8,  59 Feb 26  2008 /dev/sdd11
brw-r-----    1 root     root       8,  60 Feb 26  2008 /dev/sdd12
brw-r-----    1 root     root       8,  61 Feb 26  2008 /dev/sdd13
brw-r-----    1 root     root       8,  62 Feb 26  2008 /dev/sdd14
brw-r-----    1 root     root       8,  63 Feb 26  2008 /dev/sdd15
brw-r-----    1 root     root       8,  50 Feb 26  2008 /dev/sdd2
brw-r-----    1 root     root       8,  51 Feb 26  2008 /dev/sdd3
brw-r-----    1 root     root       8,  52 Feb 26  2008 /dev/sdd4
brw-r-----    1 root     root       8,  53 Feb 26  2008 /dev/sdd5
brw-r-----    1 root     root       8,  54 Feb 26  2008 /dev/sdd6
brw-r-----    1 root     root       8,  55 Feb 26  2008 /dev/sdd7
brw-r-----    1 root     root       8,  56 Feb 26  2008 /dev/sdd8
brw-r-----    1 root     root       8,  57 Feb 26  2008 /dev/sdd9
Re: Persistent USB mount locations on Pogoplug (and other Linux devices)
August 10, 2017 06:51PM
cdlenfert,

> I put your script above in place and called it in
> the startup script "etc/init.d/rcS". The end resul
> t was the same, but I thought it was cool to see t
> hat I didn't botch anything by including it in a s
> eparate script.
>
> It's my understanding that the Pogo OS mounts driv
> es in a seemingly random order by default. The mou
> nt points in my case are created at:

Yes, not only Pogo OS. The order of enumeration for multiple USB drives are not supposed to be defined in any Linux version. It depends on what drive is plugged into the port that cause the "spin up" time to be slow or fast. If the system has SATA and USB disks, then SATA is assigned sda, and USB is assigned sdb.

So we need away to identify the drive partition to mount it correctly. This is your mount-by-UUID script is doing.

> Some others have drives auto mounted at sda1, sdb1
> , etc. Not sure why mine uses sdX2.

If there are more than 1 partition in the sdx drive then 2nd partition is sdx2.

> The ls -l command you supplied didn't work as is,

That was my intent. To see if this stock OS version has the partitions label that can be used. So try

ls -lR /dev/disk/*

The "findfs UUID" command is OK. But it it not as elegant and robust as partition label. With the label, there is no need to search.

For example,

ls -l /dev/disk/by-label/
lrwxrwxrwx 1 root root  10 Jul 26 01:07 HOME -> ../../sdb1
lrwxrwxrwx 1 root root  10 Jul 26 01:07 rootfs -> ../../sda1

And using UUID has a big drawback. You can't replace the drive without changing the script to make it work. Using label is the best method, because you can replace the drive and it will work, as long as the label is the same.

UPDATE:

I've just realized that this stock OS version likely does not enumerate partition labels!

-bodhi
===========================
Wiki
latest Kirkwood kernel builds and rootfs
latest u-boot-kirkwood builds
latest Oxnas kernel builds and rootfs
latest u-boot-oxnas builds
latest MVEBU Armada kernel builds and rootfs
U-Boot & Kernel Booting process
bodhi's u-boot GitHub
bodhi's corner



Edited 3 time(s). Last edit at 08/10/2017 07:00PM by bodhi.
Re: Persistent USB mount locations on Pogoplug (and other Linux devices)
August 10, 2017 07:02PM
Re: Persistent USB mount locations on Pogoplug (and other Linux devices)
August 11, 2017 08:35AM
They all say the same.

[root@Pogoplug ~]# e2label /dev/sdb2
e2label: Bad magic number in super-block while trying to open /dev/sdb2
Couldn't find valid filesystem superblock.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: