I thoroughly detest udev: large, ugly, inflexible, disgusting, recently started to insist on DEVTMPFS and /usr being on / (or having an initramdisk, neither of which I accept) and so on.
For the few situations where there are dynamic changes on my boxes (e.g. usb sticks, radio killswitch and so on) I've made do with hotplug until now, but that set of shell scripts has simply grown too annoying to maintain. But recently I found out about mdev, a small component of busybox, and I took to it instantly.
Mdev was designed to be a micro-udev for all kinds of embedded systems where busybox is playing the vital role of providing most (if not all) classic unix tools. To me mdev is the embodiment of the unix mindset: do one thing, and do it well.
And that's what it does: if given the -s
switch, it trawls
/sys
for things that look like devices and creates them in
/dev
. When run without args as hotplug helper, it creates the
device the kernel tells it about, or loads firmware if that's asked for,
or removes a device if the kernel says it is going away.
These operations are adjustable via a straightforward, simple configuration
file which also lets you tell it to run commands of your choice (and load
modules), and that's all there is to it. mdev consists of about 650
lines of C, and it works very well.
What it is/was lacking, is support for kernel uevents with action=change, which some subsystems use (e.g. the rfkill subsystem signals changes to any radio kill switches that way). So I wrote this tiny patch to add that capability (I hope upstream includes it in the next version of busybox), and mdev now runs *-tagged commands on add, remove and change.
The other lacking thing is documentation - in the debian packages, that is.
mdev is decently explained in docs/mdev.txt
and examples/mdev*.conf
in the source tarball, but the
debian maintainer chose not to ship any of that. I'd recommend getting and
reading those documents first if you ponder playing with mdev.
So, to help others along a bit, here is my own setup as an example:
- my commented mdev config file,
- my auto mounter for removable devices,
- and a small renaming helper that puts usb
devices into a hierarchy in
/dev/bus/usb/NNN/MMM
.
I do have a few extra bits and pieces (e.g. startup scripts, small rfkill and bluetooth agents), but they're somewhat idiosyncratic and likely not very useful to others (but just ask if you do want them).