Hotplugging with Udev, HAL, and D-Bus HOTHOT WIREDWIRED
Total Page:16
File Type:pdf, Size:1020Kb
LINUXKNOW-HOW USER SchlagwortHotplugging sollte hier stehen Hotplugging with Udev, HAL, and D-Bus HOTHOT WIREDWIRED Hardware which just works is what every user wants. Current Linux distributions go a long way to fulfilling that dream. In this article, we will be investigating how the hotplug system works. BY OLIVER FROMMEL, MARCEL HILZINGER AND RENÉ REBE s it really that difficult? You only wanted Linux to launch the right manages the actions associated with a Iprogram when you attached your hotplug event. In this case, the agent new digital camera, but the operating manages the task of adding and register- which in turn start other agents. It is system has decided to sit this one out. ing the new device. common for multiple hotplug agents to This scenario is all too common, The steps the agent performs may work together. For example, when you although the situation has started to vary depending on your distribution and connect an external hard disk, first the improve. Linux should handle any kind the type of hardware you are installing. USB agent loads, then the SCSI agent of hardware correctly, but the ability to Since most hotplug-capable hardware loads to mount the individual partitions manage USB and Firewire devices attaches to a USB port, the USB agent is as SCSI devices with the help of the usb- plugged in or unplugged while the com- perhaps a good example. The USB agent storage module. If you attach a Bluetooth puter is running (known as hotplugging first checks if a driver is available for the dongle, the USB agent runs first, fol- [1]) has become increasingly important. new device (for example, isdn) and then lowed by a Bluetooth agent called blue- This article explains what a modern calls modprobe to load the module. If the tooth.agent. Linux system does with the devices you agent finds a script with the same name attach to it, and why not everything as the driver in the /etc/hotplug/usb/ Blacklisting Drivers works as planned. directory, the agent runs that script. The /etc/hotplug/blacklist file has a list The act of loading modules typically of modules that no agent is allowed to Agents at Work triggers a few more hotplug events, load. The list includes the modules that When you plug in a device that supports hotplugging, the kernel sends an event signal to the hot- plug system. The hotplug system uses Udev to create a device file for the device and then calls the Figure 1: After you modify the appropriate agent. An agent is a Udev configuration file, the script, typically stored below Gnome desktop icon has a Figure 2: The hal-device-manager with detailed information for the the /etc/hotplug/ directory, that more intuitive label. Prism2 WLAN adapter. 48 ISSUE 53 APRIL 2005 WWW.LINUX- MAGAZINE.COM Hotplugging KNOW-HOW the system loads via other services, as the global rules, you will need to assign This stops the Gnome desktop from dis- well as modules that prevent power a filename to ensure that this happens, playing the generic sda1 label; instead management. for example 10-local.rules. The following the label is a more intuitive mp3disk Linux typically requires a device file in entry is good for a no-name MP3 stick: (Figure 1). The lsusb tool, which lists the order to interact with a device. In a hot- attached USB devices, will help you find plug situation, that device file must be BUS="usb", SYSFS{idProduct}=U the USB IDs. If a device file exists, created on the fly when the new device "1000", SYSFS{idVendor}="10d6",U udevinfo -q path -n /dev/devicefile dis- is detected. As you learned in the pre- NAME="mp3disk" plays the path in the SysFS (see “Box2: ceding section, hotplug uses Udev to cre- Device files with Udev”), but it does not ate the device file prior to summoning give you the mount point /sys. You need the agent. the path as a parameter (-p), with this command to get SysFS information: Device Files as Needed Udev [1] is the designated successor to udevinfo -a -p /block/hda/hda1 static device files, and most current dis- ... tributions now use it. The purpose of SYSFS{idVendor}="10d6" Udev is to create device files based on ... rules specified in a Udev configuration file. For example, if you want to assign a This command helps you discover the device file other than sda1 to your MP3 device-specific values you need for spe- stick, you could specify this requirement cial configurations. There is a detailed in your own Udev rule. how-to for creating Udev files at [2]. The Udev rules are stored in /etc/udev/ Fedora site has a short overview of the rules.d. If you look in that directory, you Udev system [3]. will find a file that describes typical devices: in Ubuntu this is udev.rules, Your Own Usermaps whereas Fedora uses 50-udev.rules. Udev Figure 3: In Gnome 2.8, gnome-volume- A usermap file contains one or multiple reads the files in alphabetic order. If you properties specifies which application is run IDs that uniquely identify a hardware want to load your own Udev rule before for which hotplug event. component. When a device that matches Box 1: Hotplug on Suse Linux The Suse Linux approach to hotplugging also has them for hard disks, CD/DVD tion when you attach a memory stick, is different in parts, and the current ver- drives, and a variety of USB devices. but if you have disabled this feature, or if sion does not use the HAL architecture. After hwup has finished, the hotplug you simply close the window, it’s back to It distinguishes between (currently) agent launches. In the case of a USB My Computer. unknown and configured devices and event, the agent will be the USB agent; Suse Linux uses its own icons for the dri- uses the hwup, hwdown, hwstatus, and for network events, the agent will be the ves:/ URL. They are located below /usr/ hwscanqueue programs to support hot- network agent; and so on. If the hotplug share/hotplug/DesktopTemplates/. KDE plugging. Suse stores a configuration system fails to find a suitable agent, it adds the name to the ~/.kde/share/con- file in /etc/sysconfig/hardware for config- launches a generic agent to create the fig/kio_drivesrc file. You can edit the file ured devices. When the kernel registers required device files. In Suse Linux 9.2, to assign intuitive and unique names to a hotplug event, /sbin/hotplug loads the the agent also looks in /etc/sysconfig for your devices. For example, if you have appropriate kernel module. a configuration file for the service and two memory sticks, you can simply edit No HAL launches the appropriate service. the entries below [Used Names] to dis- After loading the kernel module, hwup Suse Linux has a simple approach to tinguish between them. checks if there is a configuration file for bug hunting that makes hotplug slightly To enable the device icons for the KDE the device below /etc/sysconfig/hard- more verbose. To enable this, set the desktop in Suse, you first need to install ware and, if so, loads the modules speci- variable HOTPLUG_DEBUG in the kdebase3-extra and kdemultimedia3- fied by the file. If hwup fails to locate a /etc/syconfig/hotplug to yes or even to extra packages. Take care if you have configuration file, it attempts to locate max. The latter setting tells the system Suse 9.2: the packages are only on the the required modules by reading the to log every single step. DVD version! After completing the *.usermap files in /etc/hotplug/, just as Desktop Icons on Suse Linux install, right click on the KDE desktop other distributions do. Suse Linux Version 9.1 or later does not and select Configure desktop… in the drop-down menu. In the Behavior win- In the future, Suse is looking to create a create desktop icons for drives. Instead, dow, select Device icons and then check file below /etc/sysconfig/hardware for users are expected to use the My Com- Enable icons on desktop. You can then every hardware component and to com- puter icon (just like in Windows) or to use the list to specify which device icons pletely do without usermap files. Com- access drives directly via the drives:/ you want to display on the desktop. paring the last two Suse versions shows URL. This solution can be a less than After installing kdebase3-extra and kde- that Suse is already heading in this perfect for USB memory sticks. By multimedia3-extra, the devices:/ URL will direction. Whereas 9.1 only creates con- default, Suse opens a Konqueror win- also work in Konqueror. figuration files for network devices, 9.2 dow with the content of the stick parti- WWW.LINUX- MAGAZINE.COM ISSUE 53 APRIL 2005 49 KNOW-HOW Hotplugging one of these entries is plugged into the prism2 0x0003 0x0846 0x4110 The script we want to run, prism2, system, the subsystem automatically 0x0000 0x0000 0x00 0x00 0x00 needs to be in the same directory, and runs the specified program, which can 0x00 0x00 0x00 0x0 we need to run chmod +x to make it be a script. executable. In our example, it runs the This allows you to enable a WLAN USB Most maps look like this and only use rc.wlan start script from the Prism2 adapter that your distribution does not the first four values. The first value spec- package, configures the wlan0 network properly configure.