From LQWiki
Jump to navigation Jump to search

To hotplug, or hotplugging, means plugging a hardware device of some kind into a running computer and having it work without requiring a reboot of the computer.

The most common devices that support this are USB devices.Other device that can be hotplugged are PCMCIA/CardBus, Firewire, CompactPCI, 'normal' PCI (through use of a special hotplug controllers), IDE (some RAID controlles support this), SCSI, CPUs, memory and laptop power docking stations.

Hotplug in kernel 2.6

Hotplug is a standard part of the 2.6 kernel. It works with udev and hal to add hotplugged devices into /dev/mapper automatically.

Hotplug vs Hotswap

Sometimes the term hotswap is used to mean hotplug but the two concepts are distinct. Normally a hotplug device needs to be shutdown before removal. By contrast, a hotswap device can simply be unplugged without risk of harm.

When does the difference matter?
The difference is important when dealing with equipment like PCI cards or harddisks. These can't be removed without risk of serious harm unless they are hotswap-capable or first powered down. Not all USB devices are hot-swappable. It is generally best to use the software "eject" button before physically unplugging a writable USB device.

[additions and corrections]

Linux hotplugging

Hotplugging support in Linux is made out of two parts, a kernel part that deals with generating events when there is a change in the devices (e.g. a device is disconnected). This event is then passed to a command in userspace. This part is usually handled by the hotplug command, but could easily be replaced with some other implementation.

Note: hotplug also supports coldplugging, that means it can be called at boot to configure all the currently connected devices. And because it supports most types of devices it works like a full Automatic Hardware Configuration tool.

Kernel part

In kernel version 2.4 Linux got a hotplug mechanism (though it's also been backported to 2.2). If a kernel supports hotplug it will have a file called /proc/sys/kernel/hotplug. This file contains the path to the command which the kernel will call to handle the 'event' (e.g. a device being connected or removed). This normally is /sbin/hotplug or can be set to /bin/true to disable hotplugging. It also requires kernel modules support in the kernel (which is default in almost every kernel).

Userpace part

The userspace part is the hotplug package, which comes from the Linux hotplugging project and is available in many distributions (called 'hotplug' in most cases). Hotplug handles loading of the proper kernel modules when a device is hotplugged, but also does coldplugging (through 'synthesizing' the hotplug events during boot). When it is installed by a version made for your distribution it shouldn't need any manual configuration.

Note, you may still hotplug, say, USB devices without the "hotplug package" installed -- you'll just have to manually take care of loading kernel modules yourself if necessary (by modifying config files and using modutils, or else using something like modconf).

See also

  • udev - can manage the /dev/ devices directory, creates devices based on hotplug events.
  • initrd - initial ramdisk support. Hotplug + initrd allows for a fully modular and automatically configured kernel.