Hot Plug
The /sbin/hotplug script can be a very simple script if you only want it to control a small number of devices. For example, if you have a USB mouse and wish to load and unload the kernel driver whenever the mouse is inserted or removed, the following script, located at /sbin/hotplug, would be sufficient:
#!/bin/sh
if [ "$1" = "usb" ]; then
if [ "$INTERFACE" = "3/1/2" ]; then
if [ "$ACTION" = "add" ]; then
modprobe usbmouse
else
rmmod usbmouse
fi
fi
fi
Or if you want to run ColdSync (www.ooblick.com/software/coldsync) automatically when you connect your USB HandSpring Visor to the computer, the following script located at /sbin/hotplug would work well:
#!/bin/sh
USER=gregkh
if [ "$1" = "usb" ]; then
if [ "$PRODUCT" = "82d/100/0" ]; then
if [ "$ACTION" = "add" ]; then
modprobe visor
su $USER - -c "/usr/bin/coldsync"
else
rmmod visor
fi
fi
fi
If you want to make sure that your network devices always come up
connected to the proper Ethernet card, the following /sbin/hotplug
script, contributed by Sukadev Bhattiprolu, can do this:
#!/bin/sh
if [ "$1" = "network" ]; then
if [ "$ACTION" = "register" ]; then
nameif -r $INTERFACE -c /etc/mactab
fi
fi
Listing 1 shows a more complex example that can handle
automatically loading and unloading modules for three different USB
devices.
Listing 1. Script to Load and Unload Modules Automatically for Three Different USB Devices
The previous small example shows the limitations of being forced to enter in all of the different device IDs manually, product IDs and such in order to keep a /sbin/hotplug script up to date with all of the different devices that the kernel knows about. Instead, it would be better for the kernel itself to specify the different types of devices that it supports in such a way that any user-space tools could read them. Thus was born a macro called MODULE_DEVICE_TABLE() that is used by all USB and PCI drivers. This macro describes which devices each specific driver can support. At compilation time, the build process extracts this information out of the driver and builds a table. The table is called modules.pcimap and modules.usbmap for all PCI and USB devices, respectively, and exists in the directory /lib/modules/kernel_version/.
For example, the following code snippet from drivers/net/eepro100.c:
static struct pci_device_id eepro100_pci_tbl[]
__devinitdata = {
{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82557,
PCI_ANY_ID, PCI_ANY_ID, },
{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82562ET,
PCI_ANY_ID, PCI_ANY_ID, },
{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL
_82559ER, PCI_ANY_ID, PCI_ANY_ID,
},
{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL
_ID1029, PCI_ANY_ID, PCI_ANY_ID,
},
{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL
_ID1030, PCI_ANY_ID, PCI_ANY_ID,
},
{ PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL
_82801BA_7, PCI_ANY_ID, PCI_ANY_ID,
},
{ 0,}
};
MODULE_DEVICE_TABLE(pci, eepro100_pci_tbl);
causes these lines to be added to the modules.pcimap file:
eepro100 0x00008086 0x00001229 0xffffffff 0xffffffff 0x00000000 0x00000000 0x00000000 eepro100 0x00008086 0x00001031 0xffffffff 0xffffffff 0x00000000 0x00000000 0x00000000 eepro100 0x00008086 0x00001209 0xffffffff 0xffffffff 0x00000000 0x00000000 0x00000000 eepro100 0x00008086 0x00001029 0xffffffff 0xffffffff 0x00000000 0x00000000 0x00000000 eepro100 0x00008086 0x00001030 0xffffffff 0xffffffff 0x00000000 0x00000000 0x00000000 eepro100 0x00008086 0x00002449 0xffffffff 0xffffffff 0x00000000 0x00000000 0x00000000As the example shows, a PCI device can be specified by any of the same parameters that are passed to the /sbin/hotplug program.
A USB device can specify that it can accept only specific devices such as this example from drivers/usb/mdc800.c:
static struct usb_device_id
mdc800_table [] = {
{ USB_DEVICE(MDC800_VENDOR_ID, MDC800_PRODUCT_ID) },
{ } /* Terminating entry */
};
MODULE_DEVICE_TABLE(usb, mdc800_table);
which causes the following line to be added to the modules.usbmap file:
mdc800 0x0003 0x055f 0xa800 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000Or it can specify that it accepts any device that matches a specific USB class code, as in this example from drivers/usb/printer.c:
static struct usb_device_id usblp_ids [] = {
{ USB_INTERFACE_INFO(USB_CLASS_PRINTER, 1, 1) },
{ USB_INTERFACE_INFO(USB_CLASS_PRINTER, 1, 2) },
{ USB_INTERFACE_INFO(USB_CLASS_PRINTER, 1, 3) },
{ } /* Terminating entry */
};
MODULE_DEVICE_TABLE(usb, usblp_ids);
which causes the following lines to be added to the modules.usbmap
file:
printer 0x0380 0x0000 0x0000 0x0000 0x0000 0x00 0x00 0x00 0x07 0x01 0x01 0x00000000 printer 0x0380 0x0000 0x0000 0x0000 0x0000 0x00 0x00 0x00 0x07 0x01 0x02 0x00000000 printer 0x0380 0x0000 0x0000 0x0000 0x0000 0x00 0x00 0x00 0x07 0x01 0x03 0x00000000Again these USB examples show that the information in the modules.usbmap file matches the information provided to /sbin/hotplug by the kernel, enabling /sbin/hotplug to determine which driver to load without relying on a hand-generated table, as PCMCIA does.
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- Validate an E-Mail Address with PHP, the Right Way
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Home, My Backup Data Center
- New Products
- Tech Tip: Really Simple HTTP Server with Python
- RSS Feeds
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Prototyping Pi Plate Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.




52 min 56 sec ago
2 hours 21 min ago
3 hours 30 min ago
4 hours 16 min ago
4 hours 38 min ago
10 hours 52 min ago
16 hours 31 min ago
22 hours 30 min ago
22 hours 53 min ago
23 hours 3 min ago