Contributed by belenus on Mon Feb 2 17:24:15 2009 (GMT)
from the scripting dept.
Let me start this article with a slightly modified first part from the official OpenBSD hotplugd manpage:
The hotplugd(8) daemon monitors the hotplug(4) pseudo-device, acting on signaled events by executing the scripts attach and detach in the /etc/hotplug directory.
Since the example from the manpage is already pretty good I won't go into the basics here but describe a little script modification that really helps when you need more complex detach actions.
The common way of using the attach script with umass(4) devices is to read the disklabel(8) and execute the proper commands (ie. mount(8)) by the type, name and label of the device. While this works pretty good when attaching a device this can't be done when detaching since the device is already gone and the disklabel can't be read anymore.
To solve this problem I let the attach script write some information (device class, device name, mountpoint, device label) to the file /etc/hotplug/hottab.
When a device is detached the proper device class is selected and, right now only in case of a disk device, the hottab is read and checked (see attach/detach scirpts blow).
Actually I am using a similar setup at the moment on some boxes and it seems to work without issues.
The attach and detach scripts are BSD licensed and should always work for -current since I use them myself.
attach/detach examples:
http://cvs.lechtermann.net/cvsweb/OpenBSD/etc/hotplug/
example hottab:
2 sd0 /media/USB_DISK_28X____ USB DISK 28X
|
|
|