lechtermann.net: OpenBSD journal
Home : : Add Story : : Archives : : CVSweb : : About : : Create Account : : Login :
advanced hotplugd usage
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
[topicopenbsd]

<< happy new year! | Reply | Flattened | Expanded | ports@: NEW games/armagetronad-dedicated >>

Threshold: Help

Related Links
more by belenus


  Re: advanced hotplugd usage (mod -9/101)
by Charles (69.134.35.207) (motm95@gmail.com) on Sat Feb 2 18:20:42 2008 (GMT)
  Hi, thanks for this article. I am trying to use these on OpenBSD 4.2 and I get an error with the attach script:

/etc/hotplug/attach[78]: syntax error: `)' unexpected

Any ideas on how to fix this? TIA.
  [ Show thread ] [ Reply to this comment ] [ Mod Up ] [ Mod Down ]

[ Home | Add Story | Archives | Polls | About ]

Copyright © 2006-2009 Michael Lechtermann. All rights reserved. Articles and comments are copyright their respective authors, submission implies license to publish on this web site. Some icons from slashdot.org used with permission from Kathleen. This journal runs as CGI using chrooted Apache as supplied with OpenBSD, the original source code is BSD licensed. Search engine is a patched version of ht://Dig.