Archives
Using a USB thumb drive as a switch with hotplugd
2013/10/07 16:13:00 CEST

This feature is often overlooked. When someone insert their USB thumb drive in a computer port, this triggers an event. On OpenBSD, such event can be monitored by hotplugd(8), which in turn allows to execute a script on device attachement or detachment. This is usually used to automatically mount a USB drive or activate the USB device in some way.

However, one could also consider such event as a meaningful signal. Instead of mounting the partition(s) of the USB drive one could identify it, e.g. via its UUID with the help of disklabel(8), and take a specific action. The rest is a matter of scripting (see hotplugd(8) for an example).

I currently use this trick with a headless system that acts as a file, scanning and printing server. When I need to use it I switch it on, and when I am done I plug in a dedicated USB thumb drive to have it shut down. I have another one to mirror the hard drive, perform some SMART self-tests, mail the result , then shutdown).

Of course, such setup grants anyone the ability to execute these actions on the system without requiring to log in, but this can be an acceptable "risk", pretty much like a television sitting in the living-room. This helps to save space and can really speed-up operating the headless device, compared with remotely login in. It can be affordable if one has old thumb drives lying around.

A USB hub equiped with on-off switches, like this one, would allow for a clean setup. No dandling cable, no thumb drive lying around.

Tags hotplugd