Originally Published: Thursday, 22 February 2001 Author: Brian Richardson
Published to: enhance_articles_hardware/Hardware Articles Page: 1/1 - [Printable]

2.4 Kernel & USB Mass Storage

Hot on his frenzy of USB euphoria, Brian Richardson chronicles his journey into the land of USB storage devices.

   Page 1 of 1  

USB Support under the recently released 2.4 Linux kernel adds more than support for keyboards and mice. While USB-based storage devices aren't well suited as primary system storage devices, they are a handy way to add storage to an existing system without cracking the case.

How it all started

My recent fascination with USB and Linux can be attributed to my boss. Last week he received a new toy ... an Agate USB Q. The Q is a keychain with a USB connector; a keychain that holds 16MB of data. My boss downloaded the Windows 98 drivers, installed the device, and started copying data over to his new toy.

Agate USB Q

I thought it was pretty cool. I thought it would be cooler if it worked under Linux.

Serial Storage

The 2.4 kernel specifically supports USB devices that comply to the USB Mass Storage Device specification. This specification allows USB storage devices to be emulated as SCSI devices. This standard allows a variety of devices to work across multiple operating systems.

Warning: not all USB storage devices comply to the USB Mass Storage Device specification. We will discuss this in more detail before the article ends.

I decided to use the Red Hat 6.2 box in my lab for this test. Since it was running the original kernel, I downloaded the 2.4.1 source code and used 'make xconfig' to configure the kernel before compiling. Aside from the kernel configuration required to make my system go, a few extra items are required for USB Mass Storage Device support.

SCSI Support USB Mass Storage Devices are emulated as SCSI devices, so 'SCSI support' needs to be enabled. Also enable the types of devices you want to attach: it works best to enable 'SCSI disk support', 'SCSI CD-ROM support' and 'SCSI generic support'.
Generic USB support Under the 'USB Support' category, select 'Support for USB'. I suggest you compile this in using the 'y' option, not as a module. This enables USB support when the kernel first boots, so USB Mass Storage Devices can be bootable. It's also a good idea to enable 'Verbose USB Debug Messages' and ' Preliminary USB Device Filesystem' for troubleshooting. The 'Verbose USB Debug Messages' option directs any USB-related error to the system logs, and the 'Preliminary USB Device Filesystem' reports the USB device configuration as part of the /proc filesystem.
Proper USB host controller support This is critical to making any USB device work. If your USB controller is part of an Intel or VIA motherboard chipset, choose one of the UHCI drivers (pick one or the other). Any other USB controller falls under the OHCI driver including iMac, SiS, Compaq and add-in PCI card controllers. Again, compile this in using the 'y' option, not as a module.
USB Mass Storage Of course, no USB Mass Storage configuration would be complete without enabling 'USB Mass Storage support'.

The kernel code is now configured for USB Mass Storage, time to compile, install the new kernel and take the new toy for a test drive. Too bad things aren't always that easy!

Minor Setbacks

Before I rebooted the computer, I attached the Agate USB Q to my computer's USB port. I wanted to see what messages the kernel displayed when configuring USB devices, especially with the verbose debugging options turned on. It's a good thing I had those verbose messages turned on, or I would have spent hours beating my head against a cubicle wall.

Note: the verbose debug messages I turned on in the kernel configuration are passed on to the system logs. To make life easier, I redirect all of the log messages to an unused tty terminal. This is accomplished by adding the following line to the end of the /etc/sys.d.conf file:

*.*        /dev/tty11
This passes every message going to log files straight to TTY11. If I watch TTY11 when I insert a USB device, I observe errors generated by the device insertion.

According to the log messages, my USB storage device was not installed. The Linux kernel tried to initialize the Agate Q, but displayed nasty errors on every attempt. I was crestfallen. What did I do wrong? Was it an incorrect kernel option? Did I leave out some obscure SCSI option? A quick consultation with my boss cleared things up.

Did I mention my boss writes USB firmware for a living?

A quick review of the logs led my boss to believe that the Agate USB Q was not a true USB Mass Storage Device. To verify this, he asked me to try the experiment using a USB Floppy drive. This drive was definitely compliant with the USB Mass Storage Device specification.

Abort, Retry, Fail?

Right... try again. Remove the Q, plug in the floppy drive, and check to see if the system recognizes it. This looks like a job for the Preliminary USB Device Filesystem (sorry, Superman had the day off ), which displays USB configuration information. This needs to be properly mounted in the /proc filesystem.

mount -t usbdevfs none /proc/bus/usb
This creates the directory /proc/bus/usb, which describes the USB configuration. The file /proc/bus/usb/devices lists all detected USB devices. Although the file format is a bit difficult to read, my USB floppy did appear. The file /proc/bus/usb/drivers lists all installed USB device drivers, including our good friend 'usb-storage' (the loadable module file is named 'usb-module.o').

Since the USB Floppy should be emulated as a SCSI device, I also had to make sure the device was present in the SCSI configuration. A quick check in /proc/scsi/scsi confirmed my USB Floppy drive existed as /dev/sda (the only SCSI device on my system). I was, as they say on MTV, ready to rock.

Time To Get My Mount On

Like any drive, the USB Floppy had to be mounted. I created a directory named /mnt/usbfd, then made a new entry to /etc/fstab:

/dev/sda    /mnt/usbfd    auto    noauto,user 0 0
Now the drive is ready for mounting:
mount /mnt/usbfdd
The USB floppy was operational! This confirmed the fact that the Agate USB Q is not USB Mass Storage Compliant. The Agate website has Windows 95/98 drivers, and promises drivers for Linux & Windows 2000 at a future time. This is disappointing, but I'm sure some ingenious company will produce a similar product that is fully compliant. There are many other USB storage devices that are compliant, so there are many uses for USB Mass Storage with Linux.
Brian Richardson continues to plug all sorts of USB devices into his Linux test machine.




   Page 1 of 1