Automount USB disks on your NAS

Frank Wille <[email protected]> Fri, 28 Dec 2012 17:39:13 +0100
Newsgroups gmane.os.netbsd.ports.sandpoint
Organization Privates Internet Ostwestfalen/Lippe e.V.
Message-ID <[email protected]>
This is a multi-part message in MIME format.

--Multipart=_Fri__28_Dec_2012_17_39_13_+0100_Nzm8mT5dZ.YkXB4n
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

Hi,

while setting up a sandpoint NAS for a friend (with Samba, NFS,
web-server, etc.) I had to find a way to mount USB disks automatically,
because I cannot expect him to login with SSH and type some mount
commands.

On the netbsd-users mailing list I found this nice solution by
Stephen Borrill, using amd(8), which worked fine for me:

http://mail-index.netbsd.org/netbsd-users/2008/10/07/msg002136.html

I changed the script to mount /dev/sd0e instead of /dev/sd0d and
added some code to use the USB LED of the NAS to indicate that the
USB device is currently mounted.

For most sandpoint NAS the LEDs can be controlled by writing one or
more characters to /dev/satmgr. Examples:

                USB LED on  USB LED off
---------------------------------------
QNAP            `           b
Synology        @           B
DLink           MMF\n       MMC\n       (yellow, green is MMK)
Kurobox         WW          VV          (using the Disk-Full LED)

For NH230/231 you can use gpioctl(8) to turn on USB LED 1 (pin 6) or
2 (pin 7). The pins are active-low:
# /usr/sbin/gpioctl gpio0 6 0
# /usr/sbin/gpioctl gpio0 7 0


Besides amd.conf, amd.local and devmount, which you have to put into
/etc, you have to create the directory /amd as root and enable rpcbind
and amd in /etc/rc.conf:
rpcbind=YES
amd=YES

# ls -l /mnt/usb/
...will mount and list your USB device with FAT. It is unmounted after 5
seconds, indicated by the USB LED. When you have a lock on the USB
filesystem, e.g. by entering the directory with cd(1), the filesystem
stays mounted.

Attached /etc/devmount is for QNAP. Change it to match your needs.

Have fun!

-- 
Frank Wille

--Multipart=_Fri__28_Dec_2012_17_39_13_+0100_Nzm8mT5dZ.YkXB4n
Content-Type: application/octet-stream;
 name="amd.conf"
Content-Disposition: attachment;
 filename="amd.conf"
Content-Transfer-Encoding: base64

WyBnbG9iYWwgXQpwcmludF9waWQgPSBubwpyZXN0YXJ0X21vdW50cyA9IHllcwpzZWFyY2hfcGF0
aCA9IC9ldGMKbG9nX2ZpbGUgPSAvdmFyL2xvZy9hbWQKbG9nX29wdGlvbnMgPSBhbGwKYnJvd3Nh
YmxlX2RpcnMgPSB5ZXMKdW5tb3VudF9vbl9leGl0ID0gbm8KZGlzbW91bnRfaW50ZXJ2YWwgPSA1
CmNhY2hlX2R1cmF0aW9uID0gNQpzZWFyY2hfcGF0aCA9IC9ldGMKClsgL21udCBdCm1hcF9uYW1l
ID0gYW1kLmxvY2FsCgo=

--Multipart=_Fri__28_Dec_2012_17_39_13_+0100_Nzm8mT5dZ.YkXB4n
Content-Type: application/octet-stream;
 name="amd.local"
Content-Disposition: attachment;
 filename="amd.local"
Content-Transfer-Encoding: base64

dXNiIHR5cGU6PXByb2dyYW07b3B0czo9dXRpbWVvdXQ9MjA7bW91bnQ6PSIvZXRjL2Rldm1vdW50
IGRldm1vdW50IG1vdW50IHNkMCAke2F1dG9kaXJ9LyR7cmhvc3R9LyR7cGF0aH0iO3VubW91bnQ6
PSIvZXRjL2Rldm1vdW50IGRldm1vdW50IHVtb3VudCBzZDAgJHthdXRvZGlyfS8ke3Job3N0fS8k
e3BhdGh9IgoK

--Multipart=_Fri__28_Dec_2012_17_39_13_+0100_Nzm8mT5dZ.YkXB4n
Content-Type: application/octet-stream;
 name="devmount"
Content-Disposition: attachment;
 filename="devmount"
Content-Transfer-Encoding: base64

IyEvYmluL3NoCiMgJFJldmlzaW9uOiAxLjIgJAoKZGV2PSQyCmRpcj0kMwoKZG9fZGlza2xhYmVs
KCkKewogICAgICAgIGxvY2FsIHJldAogICAgICAgIGRpc2tsYWJlbCAvZGV2L3IkezF9ZCAyPi9k
ZXYvbnVsbAogICAgICAgIHJldD0kPwogICAgICAgIFsgJHJldCAtbHQgMTAwIC1hICRyZXQgLWd0
IDAgXSAmJiBlY2hvICJleGl0ICQ/Igp9CgpjYXNlICIkZGV2IiBpbgpzZCopCiAgICAgICAgcGFy
dD1gZG9fZGlza2xhYmVsICRkZXYgfCBhd2sgJ0JFR0lOewogICAgICAgICAgICAgICAgcGFydD0i
ZSIKICAgICAgICB9ewogICAgICAgICAgICAgICAgaWYoJDE9PSJleGl0IikgZXhpdCgkMikKICAg
ICAgICAgICAgICAgIGlmKCQxPT0idG90YWwiICYmICQyPT0ic2VjdG9yczoiICYmICQzPT0iMjg4
MCIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcGFydD0iZSIKICAgICAgICAgICAgICAgICAg
ICAgICAgZXhpdAogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYoJDQ9PSJNU0RP
UyIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgc3ViKCI6IiwiIiwkMSkKICAgICAgICAgICAg
ICAgICAgICAgICAgcGFydD0kMQogICAgICAgICAgICAgICAgICAgICAgICBleGl0CiAgICAgICAg
ICAgICAgICB9CiAgICAgICAgfQogICAgICAgIEVORHsKICAgICAgICAgICAgICAgIHByaW50IHBh
cnQKICAgICAgICB9J2AKICAgICAgICBbICIkPyIgIT0gMCAtbyAteiAiJHBhcnQiIF0gJiYgZXhp
dCAxCiAgICAgICAgOzsKZmQqKQogICAgICAgIHBhcnQ9YQogICAgICAgIDs7CiopCiAgICAgICAg
ZXhpdAogICAgICAgIDs7CmVzYWMKCgpjYXNlICIkMSIgaW4gbW91bnQpCiAgICAgICAgbW91bnRf
bXNkb3MgLWwgLU0gMDc3NyAtbSAwNjY2IC11IG5vYm9keSAtZyBub2JvZHkgLW8gbm9jb3JlZHVt
cCxub2Rldixub2V4ZWMsbm9zdWlkIC9kZXYvJHtkZXZ9JHtwYXJ0fSAkZGlyCglpZiBbICQ/IC1l
cSAwIF0gOyB0aGVuCgkJZWNobyAtbiAiXGAiID4gL2Rldi9zYXRtZ3IKCWVsc2UKCQlleGl0IDEK
CWZpCiAgICAgICAgOzsKdW1vdW50KQoJdW1vdW50ICRkaXIKCWlmIFsgJD8gLWVxIDAgXSA7IHRo
ZW4KCQllY2hvIC1uICJiIiA+IC9kZXYvc2F0bWdyCgllbHNlCgkJZXhpdCAxCglmaQogICAgICAg
IDs7CnByaW50KQogICAgICAgIGVjaG8gL2Rldi8ke2Rldn0ke3BhcnR9CiAgICAgICAgOzsKKikK
ICAgICAgICBleGl0IDEKICAgICAgICA7Owplc2FjCmV4aXQgMAo=

--Multipart=_Fri__28_Dec_2012_17_39_13_+0100_Nzm8mT5dZ.YkXB4n--