Usb-storage

From LQWiki
Jump to: navigation, search

usb-storage is a Linux device driver for USB hard drives, memory sticks and similar.

Here is a quick overview of how usb-storage fits into the Linux picture. Suppose that you plug a USB memory stick into your computer. What happens?

The first thing is that the memory stick is a USB device, and all USB devices use a common set of protocols for communicating, these being low-speed, full speed and hi-speed. There is correspondingly a single Linux device driver that handles communication for all USB devices.

The interface this driver offers the rest of the system to the USB pen is via the filesystem: The pen will appear as a node at /proc/bus/usb/001/001 - the numbers will vary. You can have fun verifying this by having a look in that directory. Plug in a usb-pen and a new file will appear. Unplug it and it will disappear. A description of all attached USB devices is given in the file /proc/bus/usb/devices. Again this is dynamically updated so you can have fun seeing how it changes as you plug in or remove devices. The list of USB devices can also be obtained by running "lsusb" at the command line.

Next, different USB devices do different things... wow, a USB keyboard and a USB memory stick need different software at some stage! To keep things simple, USB devices fall into categories and this has the advantage that only one device driver is needed to handle all devices in some category. This is a slight fib. Some devices fall under several categories. Cameras, for instance, can commonly be read either as a mass storage device, just as if they were USB sticks, or as Pict-bridges which is a mode specific to editing still images. However that just leaves us spoilt for choice of how to communicate with the device. Let's suppose that we classify the pen drive as a USB mass storage device.

This is where the driver usb-storage comes in. The joy of classes is that we need only one driver to handle all USB storage devices. You don't need a different driver for a memory stick, a hard drive and a camera. The "USB mass storage" class defines standard ways of reading and writing to a USB device and the USB widget manufacturers need to implement these standards in their devices. At the computer end, the USB storage driver understands the standard language. The driver takes the USB device represented by /proc/bus/usb/001/002 or whatever and makes it appear as a hard drive, usually at /dev/sda, and it's partitions are at /dev/sda0, /dev/sda1 and so on.

Then filesystems can be put on the partitions and the filesystems mounted, just as for any other hard drive.

See also