Библиотека сайта или "Мой Linux Documentation Project"
Linux System Administrator's Survival Guide lsg07.htm
SCSI (Small Computer Systems Interface) is the most widely used method for connecting devices in UNIX systems. It is also used in higher-end PC machines because it has more intelligent device handling and faster transfer speeds than the less expensive IDE. SCSI devices and adapter cards are usually more expensive than IDE drives and cards, which has discouraged many PC buyers from using SCSI.
Adding SCSI devices to a Linux system is relatively easy compared to the same process with IDE and other interfaces. The next few chapters look at adding CD-ROM drives, tape drives, and other devices using other interfaces, but this chapter deals specifically with SCSI. In this chapter, you learn how to attach SCSI devices to Linux, how to configure them, and how to solve common SCSI problems.
SCSI Chains and Devices
SCSI uses a dedicated controller card (often called a SCSI adapter card) to which you can connect a chain of devices. SCSI devices are connected to each other by a flat-ribbon cable (internally) or a shielded cable (externally). The SCSI cables run from one device to the next, forming a long connecting chain. A SCSI chain will have the SCSI adapter at one end of the chain when all devices are internal. Alternatively, the adapter can be in the middle of the chain when both internal and external devices are used. Each SCSI chain can support seven different devices (apart from the adapter card). If more than seven SCSI devices need to be added to a system, up to seven SCSI adapter cards can be used (although most PC systems would not have enough slots for such a configuration). A new SCSI standard has recently been adopted that allows up to 14 devices per chain, but this kind of system is still expensive and relatively rare.
Each SCSI device on a chain has a SCSI ID number, from zero to seven. By convention, the controller card is set to use number seven, and a bootable SCSI hard drive (if one is to be used) is set to use SCSI ID zero (although some UNIX workstation systems insist that the primary drive not be ID zero, just to be different). The other numbers between zero and seven are available for any other SCSI devices, although each ID can be used by only one device on each chain. If two devices have the same SCSI ID number, problems will occur when the operating system tries to communicate with the device. In most cases, the system will still boot, but parallel streams of information or a complete failure of the SCSI chain can occur when the identical SCSI IDs are accessed. Each SCSI chain has a number from zero through seven as well, so if you have two SCSI adapter cards, each device will have a chain number and a SCSI ID number that uniquely identifies the device to the operating system.
Most SCSI devices have all the electronics needed to control themselves attached to the device, making it easier for devices to talk to each other without having fancy drivers in the operating system. These built-in electronics are also why SCSI devices tend to cost more than IDE systems, which rely on the operating system or controller card to provide drivers for communicating with the devices.
One of the major advantages of a SCSI system, especially in the context of a Linux or UNIX operating system, is that you don't have to do anything special to configure the system when you add a new SCSI device. Once you add a new SCSI device to the system and ensure it has a unique SCSI ID on its chain, the SCSI controller card recognizes the device automatically (the device's on-board electronics identify the type of device to the card when the card starts up). The operating system may still need a special driver to talk to some devices, but Linux has built-in drivers for most typical SCSI devices (like hard drives, tape backup units, CD-ROMs, and printers). You just need to turn on the appropriate driver by adding it to the operating system kernel.
SCSI devices must be terminated at each end of the chain to ensure that any electrical signals along the chain are properly handled. SCSI terminators are usually passive, consisting of a set of resistors that provide an electrical indication that the chain ends at that point. Some SCSI chains use an active terminating resistor, which is an electrically powered resistor that ensures the termination is properly performed. Active termination is seldom encountered in PC systems≈it is usually required only on large, industrial installations that have very long SCSI chains. Without proper termination, electrical signals along the SCSI chain may not be properly transmitted, resulting in lost data.
Each SCSI chain should only have two terminators, one at each end. Most SCSI controller cards have a set of switches or a block of removable resistors that act to terminate one end. Most SCSI devices also have a switch or a bank of resistors that allow that device to terminate the chain. Some devices are clever enough to sense that they are the last SCSI device in a chain and terminate without any intervention from you. Only the device at the end of the chain must be terminated. If a device in the middle of the chain is terminated, the controller card won't recognize devices further along the chain.
SCSI devices can communicate with each other quickly over the chain, removing the need for the operating system to intervene in some cases. For example, a tape drive can dump information straight to another SCSI device without involving the operating system too much. This capability helps increase the effective speed of the SCSI system, and makes SCSI devices particularly flexible under Linux.
Supported SCSI Devices
There are a lot of SCSI devices available, ranging from the traditional devices (hard disks, tape drives, scanners, plotters, printers) to some more esoteric devices (telescope motor drive controllers, video cameras, light and sound systems). You can't assume that because Linux supports SCSI any SCSI device will work. All the traditional SCSI devices are supported, however, and the rest can have a driver written for them.
Most versions of the Linux operating system have a hardware compatibility file in the distribution set that lists all devices that have been tested and are known to work properly with the SCSI system. Before you purchase a new SCSI device, check this compatibility file carefully. Some SCSI controller cards are not supported by Linux, although all the major brands are. Again, the compatibility file can help you determine the adapter cards that are supported. If you are converting an existing PC-based SCSI system to Linux, check each device with the compatibility list before you begin installation to prevent frustration later.
Some SCSI devices (like plotters) that aren't very common are shipped with their own kernel patches for DOS, OS/2, and UNIX. A few even provide Linux drivers now. When a Linux driver is provided, make sure the patches correspond to the version of the Linux kernel you are using. If they will work with your version of Linux, link the driver into the kernel, and then rebuild the kernel before making the device available. If a SCSI device doesn't have a Linux kernel patch and isn't supported as part of the basic distribution driver set, check with the manufacturer of the device or Linux distribution sites and user groups for a suitable driver or alternative.
SCSI Device Drivers
All devices on a Linux system must have a device driver so the kernel can communicate with the device. SCSI devices are no different. Linux is usually distributed with a complete set of SCSI device drivers that only need to be configured properly and linked to the kernel to make the device accessible.
SCSI disk drives are always block devices and should always use major device number eight because this number is the convention the kernel expects this device number). Linux doesn't support any raw SCSI devices (despite its similarity to BSD UNIX, which does support raw SCSI devices). A raw device is accessed in a different manner than a normal device; data an be sent to it without any special handling. The standard naming convention for SCSI hard drives is /dev/sdletter for the entire disk device (such as /dev/sda and /dev/sdb) and /dev/sdletter partition for the partitions on that device (such as /dev/sda1 and /dev/sda2).
Linux allocated 16 minor device numbers to each SCSI disk device, with minor device number 0 representing the whole disk drive, minor numbers between 1 and 4 representing the four primary partitions, and minor numbers 5 through 15 representing any extended partitions. With Linux, SCSI disk minor device numbers are assigned dynamically starting with the lowest SCSI ID numbers. Figure 7.1 shows a listing extract from the /dev directory of the Linux system supplied on this book's CD-ROM. As you can see, all the SCSI hard drives have the major device number set to 8 and the minor device numbers vary from 0 to 15. The entire hard disk /dev/sda has major number 8 and minor number 0. The four primary partitions have minor numbers 1 through 4 (/dev/sda1 through /dev/sda4). Any extended partitions are numbered from 5 through 15 (/dev/sda5, /dev/sda6, and so on).
The SCSI hard disk device drivers have major number 8 and minor numbers 0 through 15 for each drive.
Because Linux talks directly to the SCSI interface, Linux presents a few problems when partitioning SCSI disks. Each disk drive is viewed as the SCSI host sees it, with block numbers from zero up to the highest block number. All blocks are assumed to be free of errors. As a result, there is no easy way to get at the disk geometry. For comparison, DOS requires a head-cylinder-sector mapping, which is not as efficient but does allow direct manipulation. To partition the drive, you will have to either use the entire disk for Linux (in which case the installation takes care of the partitioning) or use DOS or Linux's fdisk program to create partitions for other operating systems first. For systems that support both SCSI and IDE hard drives, you may have to reconfigure the system's BIOS to recognize the SCSI drive as the primary (boot) device.
SCSI CD-ROM drives with a block size of 512 or 2048 bytes (which covers practically every consumer model that works with a PC) will work with Linux, but any other block size will not. Most CD-ROM drives and CD-ROM discs have either 512 or 2048 byte blocks, so this limitation shouldn't cause a problem. Linux CD-ROM drives must also support the ISO 9660 format for disk layout, although again practically every name-brand PC CD-ROM drive supports this format.
SCSI CD-ROMs use the major device number 11 and minor device numbers are allocated dynamically, with the first CD-ROM drive found being minor zero, the second minor one, and so on. The naming convention used with Linux is /dev/sr(digit), such as /dev/sr0 and /dev/sr1 for the first and second CD-ROM drive installed. Figure 7.2 shows the device drivers for a CD-ROM supplied with most Linux systems. Because a PC rarely has more than two CD-ROM drives attached, only two device drivers are usually included. As you can see from the figure, the /dev/cdrom device driver has been linked to /dev/sr0 (which is the first SCSI CD-ROM drive).
Usually only two device drivers are supplied for SCSI CD-ROM drives, as few systems will have more than two CD-ROM drives.
After setting the CD-ROM SCSI address properly (the system should recognize the device when the SCSI card boots), you must mount the CD-ROM device. Chapter 18, "Filesystems and Disks," discusses mounting in more detail. You can perform the mount manually, or embed the proper command in the startup sequence so the drive is always available. The general command to mount a CD-ROM device is
mount /dev/sr0 /mount_point
where mount_point is a directory that can be used. You must create the directory beforehand for the mount to work, and the directory must be empty. For convenience, you should create a directory called /cdrom that is always the mount point. (Most versions of Linux create this directory automatically if a CD-ROM was used to install the software.)
If your CD-ROM doesn't mount properly with this command, it may be because of the disk type. The correct syntax to mount an ISO 9660 (also called High-Sierra) CD-ROM is
mount -t iso9660 /dev/sr0 /mount_point
For this command to work correctly, you must have the kernel set to support the ISO 9660 filesystem. If you haven't done this, rebuild the kernel with this option added. (See Chapter 25, "Modifying the Kernel.")
Linux attempts to lock the CD-ROM drive door when a disk is mounted in order to prevent filesystem corruption due to a media change. Not all CD-ROM drives support door locking, but if you find yourself unable to eject a CD-ROM, it is probably because the disk is mounted (it doesn't have to be in use). Chapter 9, "CD-ROM Drives," discusses CD-ROM drives in more detail.
Linux supports several SCSI tape drives. Check the hardware configuration guide before purchasing one, though, to ensure compatibility. The most popular SCSI tape models, including the Archive Viper QIC drives, Exabyte 8mm drives, and Wangtek 5150S and DAT tape drives, are all known to work well.
SCSI tape drives use character device major number nine and the minor numbers are assigned dynamically. Usually, rewinding tape devices are numbered from zero, so the first tape drive is /dev/rst0 (character mode, major number nine, minor number zero), the second device is /dev/rst1 (character mode, major number nine, minor number one), and so on. Non-rewinding devices have the high bit set in the minor number so that the first non-rewinding tape device is /dev/nrst0 (character mode, major device nine, minor device 128).
The standard naming convention for SCSI tape drives is /dev/nrstdigit for non-rewinding devices (such as /dev/nrst0, /dev/nrst1, etc) and /dev/rstdigit for rewinding devices (such as /dev/rst0 and /dev/rst1).
Generally, Linux supports tape devices that use either fixed or variable length blocks, as long as the block length is smaller than the driver buffer length (which is set to 32K in most Linux distribution sources, but can be changed by reconfiguring the kernel). Tape drive parameters like block size, buffering process, and tape density are set by the mt program where needed.
A common problem with SCSI tape drives occurs when you are trying to read tapes from other systems (or another system can't read a tape made in Linux). This problem occurs because of different block sizes used by the tape system. On a SCSI tape device using a fixed block size, you must set the block size of the tape driver to match the hardware block size used when the tape was written (or to variable). You change this setting with the mt command:
mt setblk <size>
Replace size with the block size, such as 20. If you want a variable block length, set size to zero. Some Linux versions don't have a version of mt that lets you change block sizes (usually the GNU version). If that's the case, get the BSD version of mt, which does support this feature.
There are many more SCSI devices available, such as scanners, printers, removable cartridge drives, and so on. The Linux generic SCSI device driver handles these devices. The generic SCSI driver provides an interface for sending commands to all SCSI devices.
SCSI generic devices use character mode and major number 21. The minor numbers are assigned dynamically from zero for the first device. Generic devices have the names /dev/sg0, /dev/sg1, /dev/sg2, and so on.
Troubleshooting SCSI Devices
Many common problems with SCSI devices are quite easy to solve. Finding the cause of the problem is often the most difficult step, and reading the diagnostic message displayed by the operating system when it boots or attempts to use a SCSI device can usually help with this step. Table 7.1 lists the most common problems with SCSI devices, their probable causes, and possible solutions.
|SCSI devices show up at all possible SCSI IDs.||You have configured the device with the same SCSI address as the controller (which is typically set at SCSI ID seven).||Change the jumper settings to another SCSI ID.|
|A SCSI device reports using all possible LUNs.||The device probably has bad firmware.||The file drivers/scsi/scsi.c contains a list of bad devices under the variable blacklist. Try adding the device to this list and see whether it affects the behavior. If not, contact the device manufacturer.|
|Your SCSI system times out.||Delay in sending signals to the device.||Make sure the interrupts of the controller card are enabled correctly and there are no IRQ, DMA, or address conflicts with other boards in your system.|
|You get sense errors from error-free devices.||You have bad cables or improper termination on the chain.||Make sure the SCSI chain is terminated at both ends using external or on-board terminators. Don't terminate in the middle of the chain, as this can cause problems, too. You can probably use passive termination. For long chains with several devices, try active termination for better behavior.|
|The tape drive is not recognized at boot time.||Either the SCSI chain didn't recognize the tape drive or the device driver is not installed.||Try booting with a tape in the drive.|
|A networking kernel does not work with new SCSI devices.||The autoprobe routines fo>||>|
Только зарегистрированные пользователи могут оценивать и комментировать статьи.