Fix for problem with mixing USB shares on QNAP

Most QNAPs randomly mounts USB disk shares. I.e. you can have disk attached to left USB port as USBDisk1, second as USBDisk2 and after reset — changed together. This causes many problems, where being unable to write some script accessing particular disks could be named at first. There isn’t an easy way to work around it. The only solution I found out was to write an script that resides in flash memory (therefore is called upon each restart of QNAP) and that mounts disks under shares similar to their disk labels.

Here is an example of such script:

[code language=”shell”]
# Create folders
mkdir /share/wd
mkdir /share/samsung
# Check disk bindings
WD=`/usr/local/sbin/blkid |grep WD|awk {‘print $1’}|cut -f1 -d":"`
SAMS=`/usr/local/sbin/blkid |grep Samsung|awk {‘print $1’}|cut -f1 -d":"`
# Mount disks
/bin/mount -t ufsd $WD /share/wd/ -o force
/bin/mount -t ufsd $SAMS /share/samsung/ -o force

When this script is executed, it mounts proper disk (referenced by disk label — WD and Samsung in my case) always in the same local folder, /share/wd/ and /share/samsung/ respectively. From this moment I can point all my other scripts to any of these two folders (instead of default USBDisk1 and USBDisk2) and be sure, that I’m always referencing correct disk.

Tested under TS-210, works like a charm.

You must run this script manually each time you want to make sure, that devices to which /share/wd/ and /share/samsung points to could change (i.e. after every QNAP restart). If this is unhandy or impossible then you may want to automate this, by putting above script into flash memory, where it will be automatically executed with each QNAP restart.

This is discussed in “Run bash script with every startup of your machine” article.

Thanks to Dylon for all the help here.

Leave a Reply