AW: Persistent mountpoint for USB storage

Franz Leu franz.leu at norfolk.ch
Thu Nov 5 09:03:37 UTC 2015


> -----Ursprüngliche Nachricht-----
> Von: Isaac Dunham [mailto:ibid.ag at gmail.com]
> Gesendet: Samstag, 31. Oktober 2015 04:50
> An: Franz Leu
> Cc: busybox at busybox.net
> Betreff: Re: Persistent mountpoint for USB storage
> 
> On Fri, Oct 30, 2015 at 02:28:11PM +0100, Franz Leu wrote:
> > Hi
> >
> >
> >
> > I'd like to mount USB storage on persistent mount point depending in
> > the USB port it's plugged in.
> >
> > Plugged in port 0 always mounts to /mnt/usb0
> >
> > Plugged in port 1 always mounts to /mnt/usb1
> >
> > ...
> >
> >
> >
> > How can I achieve this automatically, manually or by a script.
> 
> If you can figure out from sysfs whether a given disk is attached to
> port 0/1/2/..., you can do the following:
> 
> - have /dev/usbdisk<port> in your fstab
> - have a script that looks in the proper sysfs dir
> (/sys/class/block/<disk>)  and follows a bunch of symlinks to figure
> out if it's usb and which port,  then use a symlink.
> 
> 
> However, I'm not sure how you'd do the script.
> Right here, it *seems* that I have three ports (1-1, 1-2, and 1-3), and
> I can tell the difference by this:
> DISKPATH=$(readlink -f /sys/class/block/<disk>)
> USBPATH=${DISKSPOT#*/usb} USBPORT=$(echo $USBPATH | cut -d/ -f2)
> 
> But I'm not sure about all that; it's my best guess of what's going on.
> 
> HTH,
> Isaac Dunham


Thanks for the input.
I found a solution with find and grep. 
If I know I have to find where, for instance, sda is connected on my 4 ports:

find /sys/bus/usb/devices/usb*/ -name dev -path "*usb1*sd*" | grep -E sda
find /sys/bus/usb/devices/usb*/ -name dev -path "*usb2-1.1*sd*" | grep -E sda
find /sys/bus/usb/devices/usb*/ -name dev -path "*usb2-1.2*sd*" | grep -E sda
find /sys/bus/usb/devices/usb*/ -name dev -path "*usb2-1.4*sd*" | grep -E sda

The return value is 1 if there is no entry matching and 0 if there is.
I wrapped this in a function with sd_ as variable and it works as supposed.

Cheers,
Franz


More information about the busybox mailing list