How does Ubuntu detect hardware?

Solution 1:

As Marius says: hardware is detected by the kernel at boot time, or later if it's "pluggable" (USB, etc.). When the hardware is recognized, the related kernel module (driver) will be loaded and in most cases userspace will be notified via dbus/udev to determine what to do with that hardware; udev has a set of "rules" that specify what to do with certain types of hardware. E.g. "if the detected hardware is an USB printer, add it to the print server (CUPS)" is an example of such rule, and it would look something like this:

# Low-level USB device add trigger
ACTION=="add", SUBSYSTEM=="usb", ATTR{bInterfaceClass}=="07", ATTR{bInterfaceSubClass}=="01", RUN+="udev-configure-printer add %p"
# usblp device add trigger (needed when usblp is already loaded)
ACTION=="add", KERNEL=="lp*", RUN+="udev-configure-printer add %p"

The above is part of /lib/udev/rules.d/70-printers.rules (at least, on 10.10), which also includes a rule for removing the printer from CUPS if you unplug it.

BTW: USB class 7 are USB printers.

In some cases you might have to change some configuration files, but that would be considered a bug or a necessary workaround (some hardware is impossible or difficult to detect).