Penguin
Note: You are viewing an old revision of this page. View the current version.

HotPlugging refers to insertion and removal of hardware and peripherals while a computer is running ("hot").

BigIron machines which typically must be running 24 hours a day for mission critical applications allow insertion and removal of almost all the internal hardware, including RAM and CPUs, although obviously they must first be disabled by the software.


Hotplug Package

"hotplug" is also the name of a linux package for managing the drivers/software side of things when hardware changes take place. For example, when USB devices are added or removed. There are other types of devices supported, but USB is the predominantly used type.

The way it works is that based on a device's identifying features, you can load different modules and run different scripts.

In the /etc/hotplug directory, there is a file named usb.usermap. This gives the name of scripts to run for particular USB devices.

The file format is
name_of_script fields_to_match field1 field2 field3 ... field11

The "fields_to_match" field is a bitfield - add 1 if you want to match against field1, add 2 if you also want to match against field2, add 4 to match against field3, etc. Only field1 and field2 are really necessary - they correspond to vendor_id and vendor_product_id respectively.

Here is my usb.usermap
  1. kodak dx3900 digital camera

usbcam 0x0003 0x040a 0x0170 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0

  1. sony dsc p10 digital camera

usbcam 0x0003 0x054c 0x004e 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0

  1. laser printer

brother_hl1440 0x0003 0x04f9 0x000d 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0

So, when a USB device with vendor ID of 40a and product ID of 170 is inserted, hotplug will run the script named "usbcam" in the /etc/hotplug/usb directory. The 0x0003 tells hotplug to match this rule against only the vendor ID (1) + the product ID (2), ignoring all the other fields. You can determine these values by looking at your system logs (eg run dmesg(8)) after insertin the USB device.

See below for notes about the scripts.

Notes about editting the usb.usermap file

In the version of hotplug in Debian Woody, you should add your changes to /etc/hotplug/usb.usermap-local and then run

  1. update-usb.usermap

In more recent versions of hotplug, (such as Debian Testing/Unstable), it appears you can create files named /etc/hotplug/usb/{foo}.usermap, for different versions of foo.

USB scripts

Make sure these scripts are executable! Hotplug will set the following environment variables for use by the scripts
ACTION {add, remove} DEVICE {name of the usbdevfs device... for example /proc/bus/usb/001/003} DEVFS PRODUCT INTERFACE TYPE

See the /etc/hotplug/usb.agent script for more details.

Example scripts

This is the script run when hotplug detects one of the digital cameras. the gphoto2 package for DigitalCameras comes with its own usbcam script for this purpose, but it sets the USB device to be owned by the user that owns /dev/console, which doesn't work under debian. This works fine assuming you are the only person on your computer, or you trust the other users not to delete your photos from your camera :p.

usb/usbcam
  1. /bin/sh

  2. John - we need to make the usb device readable/writeable by normal
  3. users. Should be the same person as on console, but debian doesn't
  4. change /dev/console to the current user, so make it world +rw.

chmod a+rw "$DEVICE"

I'm not entirely sure that this really needs to be done every time, but I have noticed that sometimes CUPS can't talk to the printer if it is powered on after boot. Also see CUPSNotes to see where this command line came from.

usb/brother_hl1440
  1. /bin/sh

foomatic-configure -s cups -n Brother -c file:/dev/usb/lp0 -p Brother-HL-1440 \

  • d hl1250 -o !PageSize?=A4