Linux supports a wide variety of USB (universal serial bus) devices. A USB system on a PC consists of a host controller inside your computer, hubs that act as splitters to give you more ports, and the actual USB devices. The Linux kernel supports USB devices through three types of drivers:
Host interface drivers
USB device drivers
Other drivers not necessarily related to USB, but required by a USB device driver (for example, the USB mass storage driver requires the SCSI disk support driver)
When the host interface driver recognizes a controller, the kernel logs messages such as these:
ohci_hcd: 2003 Oct 13 USB 1.1 'Open' Host Controller (OHCI) Driver (PCI) ohci_hcd 0000:00:02.0: irq 9, pci mem d4806000 ohci_hcd 0000:00:02.0: new USB bus registered, assigned bus number 1 hub 1-0:1.0: USB hub found hub 1-0:1.0: 2 ports detected
Notice that the controller has an integrated hub with two ports. Plugging in external hubs yields kernel messages like the following:
hub 1-0:1.0: new USB device on port 2, assigned address 3 hub 1-2:1.0: USB hub found hub 1-2:1.0: 4 ports detected
Don't be surprised if you see hub-related log messages when plugging in a USB device, even if the device is not a hub. Some of these devices contain hubs.
When you plug in a USB device, the kernel asks the various device drivers if they know how to talk to the device. If a driver recognizes the device, it can claim the device and take over its management.
With the usbdevfs filesystem mounted at /proc/bus/usb on your system, you can take a look around this directory to see the details of the devices that are connected to your system. However, you can also get a short summary with the lsusb command from the usbutils package:
Bus 001 Device 005: ID 054c:002d Sony Corp. MSAC-US1 MemoryStick Reader Bus 001 Device 003: ID 0451:2046 Texas Instruments TUSB2046 Hub Bus 001 Device 002: ID 046d:c00c Logitech Inc. Optical Wheel Mouse Bus 001 Device 001: ID 0000:0000 Virtual Hub
If you want to see the gory details of all of your devices, run lsusb -v. Be warned, though, that this prints an extremely verbose listing.
Basic USB keyboard and mouse support is not complicated. To use these devices on your system, you need the USB human input device (HID) driver in your kernel. The relevant kernel log message looks like this:
drivers/usb/input/hid-core.c: v2.0:USB HID core driver
With this in place, any USB keyboard that you plug into your computer should work with no further configuration. Here is the message that the kernel logs when you plug in an old Apple keyboard:
input: USB HID v1.00 Keyboard [Alps Electric Apple USB Keyboard] on usb-0000:00:02.0-2.1
USB mice aren't much more difficult to configure; the only thing you need to do is to tell the X server or gpm where to find a USB mouse (look at your /etc/X11/XF86Config file and grep for gpm in your init.d directory). The kernel maps all mice to /dev/input/mice, using the PS/2 mouse driver. The kernel message that results from the hookup of a new mouse looks like this:
input: USB HID v1.10 Mouse [Logitech USB Optical Mouse] on usb-0000:00:02.0-1
Linux accesses external USB storage devices, including flash memory, in blocks, presenting the storage as a SCSI disk. Therefore, you need the following drivers in your kernel if you would like to use such a device:
SCSI disk support, compiled directly into your kernel or as the sd_mod kernel module
A USB interface driver (see Section 11.3)
USB mass storage support, compiled directly into your kernel or as the usb-storage module
Assuming that you have all of the drivers in place, you should see a kernel log message proclaiming that there is a new SCSI bus when you plug in a flash media card device or other external mass storage device:
scsi1 : SCSI emulation for USB Mass Storage devices Vendor: Sony Model: MSAC-US1 Rev: 1.00 Type: Direct-Access ANSI SCSI revision: 02 SCSI device sda: 15840 512-byte hdwr sectors (8 MB) sda: Write Protect is off sda: Mode Sense: 00 06 00 00 sda: assuming drive cache: write through sda: sda1 Attached scsi removable disk sda at scsi1, channel 0, id 0, lun 0 Attached scsi generic sg2 at scsi1, channel 0, id 0, lun 0, type 0
Upon disconnecting the device, you will see a message like this:
usb 1-2.1: USB disconnect, address 4
Seeing the new SCSI bus in the kernel log does not necessarily mean that you have access to the attached USB device. If your system does not have hotplug support, you may need to run a script called rescan-scsi-bus.sh to get the kernel to recognize the new device. You can verify the geometry, partitions, and filesystems on the storage device with an fdisk command such as this:
fdisk -l /dev/sda
The flash memory in most digital cameras contains an MS-DOS filesystem that you can easily mount when you see the device in the kernel logs.
You may wish to mount the filesystem in read-only mode, because it is too easy to remove flash media cards and devices before unmounting the filesystem. If you alter the filesystem, then remove the card before flushing the changes to the physical media with an unmount operation, you risk data corruption.