Библиотека сайта rus-linux.net
Linux System Administrator's Survival Guide lsg12.htm
A tape drive is one of the most important devices you can own because it provides you with an easy way to back up your work. Tape drives have dropped in price to the point where anyone can afford them, especially the floppy tape-driven units that are becoming widespread.
Installing a tape drive is usually not difficult, but you will need a device driver for it. Many manufacturers of tape drives don't bother with Linux (or UNIX) when it comes to drivers, instead opting to concentrate on the lucrative DOS market. The DOS drivers cannot be used with Linux.
Instead, carefully check the tape unit before you purchase it, if you intend to use it for Linux. In general, SCSI tape devices are supported, as are most tape drives that use the floppy interface. When this chapter was written, no drivers were yet available (although they were being developed) for tape drives that use the parallel port. This chapter looks at the types of tape drives you can use with your Linux system. It also explains how to use ftape, the most popular QIC tape unit control software.
SCSI Tape Drives
Except for the SCSI drives that use special tape encoding, practically all SCSI tape drives (of any size and capacity of tape) work with Linux. Installing a SCSI tape drive is the same as installing any other SCSI device; you must set a unique SCSI ID for the drive and plug the drive into the SCSI chain. Several SCSI tape device drivers are available for Linux, all of which have slightly different target machines or markets. Select a device driver from those provided on your distribution media or the FTP or BBS sites and link it into the kernel.
The SCSI tape driver usually has a major device number of nine and a minor number of zero. The devices are usually called /dev/nrst0 (for a non-rewind device) and /dev/rst0 (for a rewind device). Check the /dev directory to see whether entries for these devices already have been created. The command
lists all the SCSI tape devices. If no devices are present, you must make them with the commands
mknod -m 666 /dev/nrst0 c 9 9 mknod -m 666 /dev/rst0 c 9 0
These commands create device files for the rewind (rst) and non-rewind (nrst) drivers with the major number nine and the minor number zero. The file permissions are set to 666 (see Chapter 17, "System Names and Access Permissions").
Once the device drivers have been created, you can begin using the tape drive. Specific tape parameters such as the length of blocks, buffers, tape density, and so on, are usually set with the mt program or through the tar command. There are two versions of the mt command generally distributed with versions of Linux, and the usage of these commands differs notably. Check your man pages or on-line help to find the proper syntax to set the block size and other parameters. For example, usually you can set the tape drives block size with the command
mt setblk 20
which sets the block size to 20. If you want to use variable length blocks on your tape drive (make sure the drive supports them), use the command
mt setblk 0
If you get error messages with the version of mt included with your Linux system, the version is probably the GNU version. This version does not allow you to set such parameters, so you should get the BSD-derived mt version instead.
<NOTE>If your SCSI tape drive isn't recognized when Linux boots (and the tape device has been properly configured), reboot the machine with a tape in the tape drive. The activity of tensioning the tape usually lets Linux know that the tape device is on the SCSI chain.<NOTE>
You can verify that the Linux kernel has found your SCSI tape drive properly by examining the boot messages. (Use the dmesg command to replay the boot messages.) You see lines similar to the following if the SCSI tape drive is recognized:
aha274x: target 4 now synchronous at 4.4Mb/s Vendor: TANDBERG Model: TDC 3800 Rev: =05: Type: Sequential-Access ANSI SCSI revision: 02 Detected scsi tape st0 at scsi0, id 4, lun 0 scsi : detected 1 SCSI tape 1 SCSI cdrom 1 SCSI disk total.
The ftape Program
The ftape program is a tape device interface meant for QIC-117, QIC-40, and QIC-80 drives only. Both QIC-40 and QIC-80 tape drives connect through the floppy drive controller cable, so if your tape drive is not connected throught the floppy drive cable, you probably cannot use ftape.(Sometimes the floppy cable is routed to another hardware board mounted in the PC expansion chassis and then to the tape drive. Some of these drives work with ftape and others do not.)In general, you cannot use ftape with tape drives that connect to the parallel port. You cannot use the ftape program with SCSI or QIC-02 tape drivers or some of the newer compression-based small cartridge drives either. If you're not sure whether the ftape program will work with your tape drive, experiment. All you will use up is time.
One caveat with current versions of ftape is that you cannot format a tape under Linux. Instead, you must either purchase preformatted tapes or boot into DOS (even if from a floppy disk) and run a utility program, usually supplied with the tape drive, to format the tape cartridges.
If you installed Linux from a setup routine on a CD-ROM, you probably were given the option of installing ftape at that time. The kernel may already be linked in for you. If you are using Linux version 0.99p114t or later, ftape is probably linked in. You can verify whether ftape is active on your system by examining the system boot messages (use dmesg to show the messages) for a line like the following:
ftape: allocated 3 buffers aligned at: 00220000
You see this message with later Linux kernels even if you have only a SCSI tape drive.
If the driver is not linked in, either extract the files from your distribution media or obtain the latest version of ftape from the FTP or BBS sites. If you can only get source code for the ftape program, you will also need a compiler. The software distribution package for ftape should include a complete installation file that you can follow. This section looks at the general process of installing ftape in a little detail.
The ftape device driver must be installed in the /dev directory and linked into the Linux kernel to be active. After you have obtained the full ftape distribution software, copy the files to a subdirectory for ftape. Check the /dev directory for an existing ftape device with the command
which lists all raw floppy tape devices as shown in Figure 12.1. If several are listed, you may not need to make new devices. For a normal tape installation, there are four non-rewind floppy tape devices called /dev/nrft0, /dev/nrft1, /dev/nrft2, and /dev/nrft3, as well as four rewind devices called /dev/rft0, /dev/rft1, /dev/rft2, and /dev/rft3.
QIC tape drives (and several other non-SCSI tape drives) have device drivers starting with rst and nrst.
If no floppy tape devices are currently installed, you must make them using the following commands:
mknod -m 666 /dev/nrft0 c 27 4 mknod -m 666 /dev/nrft1 c 27 5 mknod -m 666 /dev/nrft2 c 27 6 mknod -m 666 /dev/nrft3 c 27 7 mknod -m 666 /dev/rft0 c 27 0 mknod -m 666 /dev/rft1 c 27 1 mknod -m 666 /dev/rft2 c 27 2 mknod -m 666 /dev/rft3 c 27 3
The mknod command makes the proper device driver files (see Chapter 6, "Devices and Device Drivers"). This command creates all eight character mode devices (four rewind and four non-rewind) with file permissions of 666 (see Chapter 17 "System Names and Access Permissions"), major device numbers of 27, and minor device numbers ranging from zero through three.
If you want to set up a symbolic link to the device /dev/ftape, issue the command
ln /dev/rft0 /dev/ftape
The use of a symbolic link lets you use the device name /dev/ftape to access the tape drive instead of having to type the name of whichever tape driver is needed. In other words, you are aliasing ftape to the proper driver. You also can link the non-rewind device to /dev/nftape using the command
ln /dev/nrft0 /dev/nftape
To install the device driver into the kernel, you must change to the source directory for the Linux kernel files (usually /usr/src/Linux) and issue the make command to rebuild the kernel:
cd /usr/src/Linux make config
At one point in the make routine, you are asked whether you want to include QIC-117 tape support. Answer yes, and when the make routine asks for the value of NR_FTAPE_BUFFERS, answer 3. You do not have to install the QIC-02 support to use ftape, so answer no to that question (if it gets asked).
Finally, to rebuild the kernel properly, issue the following three commands:
make dep make clean make
Once the kernel has been rebuilt, copy it to the startup directory that holds your boot kernel (make a copy of the old kernel for safety's sake) and reboot your machine.
If your copy of the ftape program is provided only as source, you will have to compile the program. Use the makefile program included with the source to do the compiling. Most versions of the Linux distribution software include the compiled version of ftape, so you probably will not have to bother compiling the program.
To test the tape device, place a formatted tape in the drive and issue the command
mt -f /dev/rft0 rewind
If you get an error message about the device not being found, your device driver is not linked into the kernel or the device driver file is not properly set up. If you get a status message about the tape already being rewound or no message at all, the tape drive has been recognized.
<NOTE>Some versions of ftape and the Linux kernel do not allow you to use the tape drive and floppy drive at the same time. If you try, the Linux kernel freezes. Reboot the machine and avoid using both devices at the same time.<NOTE>
Using the Tape Drive
You can use the tape drive to backup and restore files using the standard tar commands, as well as cpio. For more information on using these commands, see Chapter 22, "Backup, Backup, Backup!" As a quick guide, use the following instructions for making and restoring backups of your filesystems.
To create a backup of the complete filesystem on tape, use the command
tar cvf /dev/ftape /
for ftape tape devices, or
tar cvf /dev/rst0 /
for SCSI devices. These commands assume that the device exists in the /dev directory and is linked into the kernel. The c option creates the archive file; the v option tells tar to echo its actions to the screen for you to see, and the f option tells tar which device (/dev/ftape) to use for the file. The trailing slash shows the directory structure to backup (in this case, the entire filesystem). If you decide to back up the entire filesystem, you may want to unmount devices like CD-ROM drives first to prevent their contents from being saved, too. Figure 12.2 shows a tar command used to backup the ./mail directory to a tape device using the linked device driver /dev/tape. Each file that is placed on the tape is displayed on-screen because of the verbose (v) option.
Using tar to back up a small directory to the tape device.
tar xvf /dev/ftape
or use /dev/rst0 for SCSI devices. In this case, the x option tells tar to extract the contents of the media; the v option tells tar to echo all messages to the screen, and the f option specifies the tar device (in this case /dev/ftape). Because no single files or directories are specified, tar extracts the entire contents of the tape and places them in the current directory position.
You can display the contents of a tar archive with the command
tar tvf /dev/ftape
(/dev/rst0 for SCSI tape drives), where t tells tar to show the contents, v is for a full display, and f is the device indicator. There are many more options and capabilities to tar, so see Chapter 22 for more information.
More tape devices are being added to the Linux supported products list, including parallel-port and board-driven tape drives. If you already own one of these products, watch for a specific kernel driver for it. If you are planning to purchase a tape drive, check for Linux drivers first.
When you have a tape drive, you can be conscientious about making tape backups, and thus protecting your files and data. Losing an important file is very annoying, especially when a few minutes of your time could have saved the information for you. Tape drives are one of the easiest and inexpensive methods of making reliable backups. Every system should have one!
Только зарегистрированные пользователи могут оценивать и комментировать статьи.