Date: Mon, 25 Mar 2002 10:45:25 -0800 From: darrylo <darrylo@sonic.net> To: stable@freebsd.org Subject: How to get USB hard disks working on FreeBSD-stable Message-ID: <20020325104525.A23412@sonic.net>
next in thread | raw e-mail | index | archive | help
[ I'm really, REALLY sorry about the last post. I'm having to send this via an alternate account, because the freebsd.org mail server appears to be rejecting messages from agilent.com, and I wasn't familiar with the particular mail client that I'm using on the alternate account. ] FYI, Here's a draft document that describes how to get USB hard disks working under FreeBSD-STABLE. It assumes basic sysadmin skills, as well as basic C programming proficiency. Note that this document is only needed until FreeBSD-STABLE gets fixed, and no longer needs the DA_Q_NO_6_BYTE hackery (for USB devices). -- Darryl Okahata darrylo@soco.agilent.com DISCLAIMER: this message is the author's personal opinion and does not constitute the support, opinion, or policy of Agilent Technologies, or of the little green men that have been following him all day. =============================================================================== USB Hard Disks and FreeBSD-STABLE Version 0.5, Mon Mar 25, 2002 (C) Copyright 2002, by Darryl Okahata (darrylo@sonic.net) IMPORTANT: THIS DOCUMENTATION IS PROVIDED BY DARRYL OKAHATA "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DARRYL OKAHATA BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***** Summary: This article describes my experiences on getting an USB hard disk working with FreeBSD-STABLE. Anyone also wanting to do this should have some minimal C programming experience, as some simple modifications to the kernel source code will probably be needed. ***** Introduction: For transporting files between home and work, I was looking for a portable hard disk solution -- one supported by both FreeBSD and Windows. I could have used a laptop, but a laptop tends to be big and bulky, and I wanted something smaller. Tape drives tend to be slow and have limited capacity, and I was apprehensive about the reliability of proprietary drive solutions like Iomega's Jaz drive and Castlewood System's Orb. I ended up getting an USB 2.0 hard disk enclosure for 2.5" drives. Why USB? Well, I considered IEEE 1394 drives, but there seems to be possible royalty issues with IEEE 1394 and open-source operating systems (i.e., it's unclear if it's possible to have a no-cost/free driver). Also, USB 1.1 ports are pretty ubiquitous; I wouldn't have to buy any adapter cards. Yes, USB 1.1 is slow, but it's not that slow, and, hopefully, FreeBSD will someday get USB 2.0 support. By getting an USB 2.0 hard disk enclosure, I can use it with USB 1.1 ports today (although a bit slowly), and I can hopefully continue to use it when FreeBSD gets USB 2.0 support. Also, by getting a standard 2.5" enclosure, I can use 2.5" (laptop) drives, which tend to be more rugged than 3.5" drives (and, possibly, more rugged than the proprietary drives, too). The price isn't bad, either; for around US$200, I can put together a 20GB USB 2.0 hard disk (~US$70 for the enclosure, ~$100-$110 for a 20GB drive, plus tax and shipping). It could be even much less, if I recycled an old, unused 2.5" laptop drive. ***** The Hardware: The most important piece of the puzzle is getting a good USB hard disk enclosure. Some older enclosures did not meet the USB mass storage specifications exactly, and required special drivers to be installed. Newer enclosures have better USB interface hardware, and often do not need any special drivers. Windows ME, 2000, and XP (but not 98SE and earlier) should have the standard USB mass storage drivers built into them, and do not need any special drivers to be installed. My idea was that, if the hardware was standard enough to not need any special Windows drivers, then the hardware "should" also work with FreeBSD. Fortunately, the hardware I bought did eventually work with FreeBSD, although I had to apply some kernel fixes. Unfortunately, for those of you who would also like to do what I did, I have no idea who makes the USB 2.0 enclosure; while the packaging box is of decent quality, with color pictures and printing, it does not list any manufacturer's name. I assume that this is some generic brand made in either Taiwan or China. The main labeling is ``Portable 2.5" HDD Enclosure'', and "ME-910 Series", and the particular model I have is, "ME-910U2", for "IDE to USB 2.0". The same manufacturer also apparently makes a model "ME-910U" (for "IDE to USB 1.1"), and a model "ME-910F" (for "IDE to IEEE 1394"). The second most important piece of hardware is a functional USB port. Fortunately, you probably already have one built into your PC's motherboard. Unfortunately, you may have buggy USB ports; I've heard that some older VIA-chipset-based motherboards have buggy USB ports. If you have one of these, you may be out-of-luck. You also need one supported by FreeBSD, although most are, if not all. ***** Getting It All Working: * First, decide if you're going to dedicate the entire USB disk to FreeBSD, or if you're going to use/share it with Windows. You've got three choices: 1. Use the entire disk for FreeBSD. Even though you're going to use the entire disk for FreeBSD, you should use Windows 2000/ME/XP to format the disk and put a small Windows volume on the disk; this will be used later as a test to see if you need to apply some kernel tweaks. If you don't have access to a Windows system, don't worry; you can just assume that you need to apply the tweaks. 2. Use the entire disk for Windows. If so, use Windows to format the disk, and let it use up all the disk space. If you're using WinNT or above, you'll probably want to format the disk as FAT32, as NTFS is not well supported by FreeBSD. 3. Partition the disk into two parts: one for FreeBSD, and one for Windows. If so, use Windows to format the disk (just like the previous step), but do not allocate the entire disk to Windows. Again, if you're using WinNT or above, you'll want to format the drive as FAT32 and not NTFS. * Disconnect the USB disk from your system, if it's currently connected. You want to leave the disk disconnected for now. * Next, you need to get and boot a recent version of FreeBSD-STABLE. If you don't know how, follow the directions in the handbook to do so. You also need to make sure that you have the kernel sources, as you'll probably have to edit the kernel sources and rebuild it. It has to be a recent FreeBSD-STABLE. Unfortunately, FreeBSD 4.5-RELEASE will probably not work. I was using FreeBSD-STABLE as of mid-February 2002 (released after 4.5-RELEASE), and the USB drivers in that version would not work; I would get errors like: umass0: BBB reset failed, TIMEOUT However, after noticing that a number of USB-related changes have been made, I upgraded to FreeBSD-STABLE (March 19, 2002 as of ~3AM PST, CVS tag: RELENG_4). After a bit of tweaking, I was eventually able to get the USB disk working. * Configure the kernel for USB devices. If you're using the standard, GENERIC, kernel, this has already been done for you, and you can skip this step. However, note that, in subsequent steps, you will still have to edit the kernel sources, rebuild the kernel, and reboot. At this point, we're only interested in getting enough functionality working to query the USB bus and USB hard disk, in order to get the necessary information that we'll later use to edit to the kernel sources. [ Note: the following is for people who have customized their kernels, and are not using the standard, GENERIC, kernel. It's assumed that they know how to configure and build a kernel. ] If you're using a nonstandard kernel, you need to have built a kernel with the following devices: # SCSI peripherals device scbus # SCSI bus (required) device da # Direct Access (disks) You also need to add the basic PCI-USB driver, depending on the hardware that you have; also add one of the following: device uhci # UHCI PCI->USB interface device ohci # OHCI PCI->USB interface It's generally easiest to just add both, though. You need additional USB device drivers, although these can be either built into the kernel, or loaded as kernel modules: device usb # USB Bus (required) device umass # Disks/Mass storage - Requires scbus and da * Enable the USB daemon (the next time you reboot) by adding the following line to /etc/rc.conf: usbd_enable="YES" * Reboot FreeBSD to make sure that USB support is enabled. If you're using the standard GENERIC kernel, you can skip this step. * Connect the USB disk to your system. In the syslog (and, usually, the console), messages similar to the following will appear, but they'll be somewhat different: umass0: DMI USB 2.0 Storage Adaptor, rev 2.00/10.07, addr 3 da0 at umass-sim0 bus 0 target 0 lun 0 da0: <TOSHIBA MK2016GAP U0.3> Fixed Direct Access SCSI-0 device da0: 650KB/s transfers da0: 19077MB (39070080 512 byte sectors: 64H 32S/T 19077C) Note the disk drive identification; in the above, it's: TOSHIBA MK2016GAP U0.3 Yours will probably be different. Make a note of the EXACT string. If you don't see messages like the above when you connect the disk, you're probably using a buggy version of FreeBSD. You probably need to upgrade. This is especially true if you see errors like: umass0: BBB reset failed, TIMEOUT * Hopefully, you have a windows partition on the disk (if you don't, assume that you need to apply the kernel tweaks, and skip to the next step). As a test (which will probably fail), try mounting it: mount_msdos /dev/da0s1 /mnt You may have to edit the above command before running it: + If you only added one Windows volume to the disk, the device name will be /dev/da0s1. If you have more than one Windows volume, the device name will be different, and you'll have to replace "/dev/da0s1" with the correct name. + You can use "/mnt" only if there isn't already something mounted there. If there is, use something else. Chances are, the above command will fail (assuming that you used the correct parameters), with messages like the following appearing in the syslog/console: (da0:umass-sim0:0:0:0): READ(06). CDB: 8 0 0 0 4 0 (da0:umass-sim0:0:0:0): ILLEGAL REQUEST asc:21,0 (da0:umass-sim0:0:0:0): Logical block address out of range If you see this, don't worry; it just means that you have to tweak the kernel sources. In the above, note that the failing command is, "READ(06)"; if you see anything else, stop now, as something else is going wrong, and the rest of these instructions will probably not help you. If, by some miracle, the above command actually succeeds, rejoice. It means that you do not have to tweak the kernel sources, and that the USB disk should already be fully functional under FreeBSD. You can skip the rest of these steps, and start using the disk normally (but see the cautions below on disconnecting the disk from the USB bus!). * If the above mount failed, it means that you probably need to apply some kernel tweaks. What's happening is that FreeBSD treats an IDE USB disk as a SCSI disk, and tries to send it 6-byte SCSI commands, but the USB disk probably understands only 10-byte SCSI commands, and gives errors when 6-byte commands are used. [ Yes, it may seem strange, treating an IDE USB disk as a SCSI one, but it's actually a pretty good idea. This simplifies driver writing, because the USB driver only has to worry about low-level details, and the higher-level SCSI driver can handle a lot of the upper-level details. ] Fortunately, FreeBSD allows you to mark certain SCSI devices as being incapable of understanding 6-byte SCSI commands, which is a passable workaround for this problem. Ideally, the driver should fall back to using 10-byte commands if 6-byte one fails, but this does not (yet?) exist in FreeBSD-STABLE (I believe it does exist in FreeBSD-CURRENT, though). This is where the drive identification string comes in (you did make a note of it, above, right?). Here's a tricky part: you have to break up this drive identification string into a manufacturer name, a model name, and a revision. Hopefully, you're familiar with disk drive manufacturers; if you're not, ask around. In the above example, the drive identification string is (and this will almost certainly be different for you): TOSHIBA MK2016GAP U0.3 Here, the manufacturer name is "TOSHIBA", and the model name is "MK2016GAP", and the revision is "U0.3". Note that this one's easy; other drive identification strings may have additional spaces. The two key parts you'll need are the manufacturer and model names. Make a note of them. * As root, go to /usr/src/sys/cam/scsi, and edit the file, "scsi_da.c". Search for the variable, "da_quirk_table"; you want to locate where it is defined. The variable, "da_quirk_table", contains a list of all SCSI devices that need to be specially handled, and it is here where we need to add an entry for our USB disk. Basically, to this variable, you want to add an entry like: { {T_DIRECT, SIP_MEDIA_FIXED, "TOSHIBA", "MK2016GAP", "*"}, /*quirks*/ DA_Q_NO_6_BYTE }, Replace "TOSHIBA" with the manufacturer name of your disk, and replace "MK2016GAP" with the model name. This will tell FreeBSD to specially handle your USB disk -- to not use 6-byte SCSI commands. Rebuild your kernel (don't forget to do a "make depend"), and reboot. The USB disk should be functional. >From here, you should be able to use the disk normally. However, before physically disconnecting the USB disk from the USB bus, do not forget to unmount any mounted filesystems that come off the USB disk. Bad Things Will Happen if you disconnect the disk before unmounting any such filesystems (you may lose data, or FreeBSD might crash). If part or all of the disk is going to be used for FreeBSD, just follow the instructions in the handbook. ***** Notes: * When using an USB disk, do not forget to unmount any filesystems that come off the USB disk. Bad Things Will Happen if you disconnect the disk before unmounting any such filesystems. You may lose data, or FreeBSD might crash. * For instructions on adding a disk to FreeBSD, see the chapter called, "Storage". --}-<<report>> ----- End forwarded message ----- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020325104525.A23412>