I f you're in the market for a new printer, you may want to consider one with a USB (Universal Serial Bus) interface. While serial line interfaces were a great improvement over parallel interfaces, USB is even better. USB-connected printers are easy to configure and print faster (due both to faster communication with the host and more modern printer hardware).
I f you’re in the market for a new printer, you may want to consider one with a USB (Universal Serial Bus) interface. While serial line interfaces were a great improvement over parallel interfaces, USB is even better. USB-connected printers are easy to configure and print faster (due both to faster communication with the host and more modern printer hardware).
Linux supports a very wide variety of USB devices. This month, we’ll delve into USB and see how easy it is to add USB peripherals to your Linux system.
All About USB
USB is a communication standard created in 1994 by a consortium of hardware and software vendors, including Compaq, Intel, Microsoft, and NEC. The companies’ goal was to devise a single standard bus capable of connecting a full range of peripheral devices to the computer. At the same time, they also wanted to overcome some of the problems and limitations of traditional serial and parallel connections. The companies achieved their goal: USB has almost completely obsoleted RS-232, ADB, PS/2, busmouse, serial, and parallel connections.
The USB bus can support many different kinds of peripheral devices: printers, modems, external hard disks, scanners, cameras and other multimedia devices, and so on. USB also provides an interface to the computer keyboard and mouse, and it’s also “plug-and-play”, meaning that (most) devices can be added and removed while the system is running.
The theoretical bandwidth of a USB bus is 12 Mbits/s; however, actual throughput is more like 8-8.5 Mbits/s, and devices seldom achieve more than about 2 Mbits/s due to limitations in packet size and other factors. The next version of USB, USB 2, has a theoretical maximum of 480 Mbits, so it might yield actual speeds in the range of 60-80 Mbits/s. However, USB 2 devices are uncommon, and Linux support for USB 2 is not yet available.
In hardware, USB is implemented as an internal controller on the host computer. USB hubs provide the actual device ports, and the controller contains a virtual hub (known as the “virtual root hub”) with two ports. External USB hubs can be connected to the controller and to one another to support up to 127 devices. Hubs can be nested five levels deep below the root.
External hubs have four or more ports. Vendors usually provide external power supplies with their USB hubs, but hubs typically have the option to draw power directly through the bus. (The Linux USB project developers recommend to not draw power from the bus. If you’re using a desktop system, use the external power supply. On a laptop, however, you can use a small hub without external power, but only when the laptop has A/C power and the attached USB devices don’t require power supplies themselves.)
|Figure One: USB connector pinouts|
USB connectors have been standardized across all device types (another advantage it has over traditional serial ports). Unlike traditional serial cables, USB cables contain only four wires: power, ground, send, and receive. Device communication is handled hierarchically: all communication is controlled by the master device on the USB controller, and all attached devices function as slaves. This scheme eliminates issues like bus collisions. The pinouts for USB cable connectors are illustrated in Figure One.
Enabling USB Support
|Figure Two: USB-related kernel parameters |
The best USB support is found in the 2.4 Linux kernel, and USB support must be enabled in the kernel before you can use it. Figure Two illustrates make xconfig‘s USB menu.
Note that the figure shows only part of a very long parameter list (the gap indicates omitted selections). As usual, the various options are grouped by type, beginning with general USB support and support for hubs and classes of devices, followed later by choices corresponding to specific USB devices.
The second section in the figure shows the options for USB controller interfaces. USB devices use several different types: the open host controller interface (OHCI), the universal host controller interface (UHCI), and the enhanced host controller interface (EHCI). Settings for the first two appear in the dialog (the latter is seldom used). Different vendors use one or the other of these two types for all of their devices.
The USB Human Device Interface (HDI) section contains settings needed for USB keyboards and mice (that’s what HDI refers to). We have enabled them here as well.
The figure highlights the settings required for the three devices we’ll be considering in this column: a mouse, a Zip drive, and a printer. You should select module-based support whenever possible.
After enabling USB in the kernel, you’ll also want to install the usbutils package if it is not already present on the system. You may also find the usbview utility useful if you prefer a graphical USB device display.
You can view the currently attached USB devices with lsusb (included in the usbutils package):
# lsusb | grep Bus
Bus 001 Device 001: ID 0000:0000
Bus 001 Device 002: ID 0458:0003 KYE Systems Corp.(Mouse Systems)
Bus 001 Device 003: ID 0451:2046 Texas Instruments TUSB2046 Hub
Bus 001 Device 004: ID 059b:0030 Iomega Corp. Zip 250
Bus 001 Device 006: ID 04b8:0005 Seiko
Epson Corp. Stylus Color 760
On this system, there are three USB devices: a mouse, an Zip drive, and a printer. The display lists the bus number (always 001 here) and the device number for each USB device. Note that device 003 is an external USB hub.
USB device attributes are also available within the /proc file system, in files named like /proc/bus/usb/busB/devN, where B is the bus number and N is the device number.
The usbmodules command can be used to list the device-specific modules used by a USB device, as in these examples:
# usbmodules –device/proc/bus/usb/001/002
# usbmodules –device/proc/bus/usb/001/006
USB modules are loaded automatically when a device is detected by the USB subsystem.
Setting up USB Devices: Three Examples
USB devices are accessed via special files under /dev. We’ll be using the following special files for our three USB devices:
/dev/input/mouse0 or /dev/input/mice
Let’s begin with the USB mouse. In general, using a USB mouse in the system console does not require configuration. However, using it under X does. We’ll look at the configuration for X version 4 here, which involves editing the XFree86Config file (usually found in the /etc/X11 directory).
First, we must add an InputDevice section to the file. Here is an example:
Identifier “USB Mouse”
Option “Protocol” “IMPS/2″
Option “Device” “/dev/input/mice”
The special file mentioned in this example, /dev/input/mice, refers to any and all USB mice present on the system. If you wanted to specify just the first USB mouse, you would use /dev/input/mouse0 instead.
Secondly, we must tell the X server about the mouse device via an InputDevice directive in the ServerLayout section. For example, these entries specify both a normal mouse and a USB mouse:
InputDevice “Mouse” “CorePointer”
InputDevice “USB Mouse” “SendCoreEvents”
The first field in the InputDevice directive is the Identifier from the corresponding InputDevice section defined previously. The second field is a keyword that specifies how to treat that mouse device. If you want to use only a USB mouse, remove the entry for the usual mouse, and set the second parameter of the USB mouse’s entry to CorePointer.
That’s all there is to it. The next time you start X, the mouse should be working.
Next, we’ll move on to the USB printer. In general, configuring a USB printer is no different than setting up any other printer under Linux: attach the device, set up /etc/printcap entries, and so on. Once the USB device is recognized, no other special handling is necessary.
Using the provided administrative tools is often a quick and convenient method of adding a new printer. Alternatively, you can set up a printer manually, using the same device file, /dev/usblp0. Once the corresponding printer queue is configured, printing to the new device is ready to go.
As our final example, we’ll add an external USB Zip 250 drive to the system. Zip drive support is provided by the USB mass storage driver. Via a sleight of hand, this driver tricks the standard SCSI driver into servicing the USB disk. Accordingly, the kernel must also provide SCSI support to use such USB devices, specifically: SCSI support, SCSI generic support and SCSI disk support. For the same reasons, SCSI disk special files are used to refer to Zip drives.
Once the device is recognized by the USB subsystem, you can mount it in the normal way. For example, the following command could be used to mount a Zip disk at /zip250:
# mount -t vfat /dev/sda4 /zip250
Note that the Zip disk’s DOS partition is interpreted as partition 4 on the disk. You can also build other file system types on Zip disks if you like. One final, important point: be sure to unmount the /zip file system before ejecting the disk or you may lose data in unflushed disk buffers.
Many people have been slow to use USB devices on Linux systems. Hopefully, this column has shown you just how easy it really is.
If you would like more information about USB on Linux systems, consult the Linux USB project’s web site at http://www.linux-usb.org.
Æleen Frisch is the author of
Essential System Administration. She can be reached at email@example.com.