For the home server we got an external USB powered hard disk for the public file share. Because this disk may not be present when the computer is started up, and may change device name since it is USB attached, I desired a way to mount that specific hard disk when it was plugged in.
The answer was a fairly long but simple udev rule, and a script to do the mounting.
/etc/udev/rules.d/storage.rules
ATTRS{idVendor}=="0bc2", ATTRS{idProduct}=="5031", ATTRS{serial}=="NA0B3DKV", ENV{DEVTYPE}=="partition", ACTION=="add", RUN+="/usr/local/sbin/mount-storage"
/usr/local/sbin/mount-storage
#!/bin/sh
mount -t vfat -o uid=nobody,gid=nogroup,dmask=000,fmask=111 \
"$DEVNAME" /mnt/store
I found how to write the rule after referring to
Writing udev rules and
an example of a rule that matches the type of device.
It is still required to unmount the disk before unplugging it, as is the case with any operating system at the moment.