Linux SCSI Tape Fix

Reading tapes from other Unix systems on your Linux machine

Had problems reading tapes from other Unix machines on your Linux box?
I certainly did.  It turned out to be a pretty simple fix, once I figured out what the problem was.  It's all documented in the man page for the SCSI tape drives ("man st") but it took me, at least, many times reading through that before I could really identify the problem.

The problem is...
that many other Unix boxes set their tape drive to "variable block size" mode.  Linux apparently doesn't, by default.  So the fix that worked for me was to write a little program that set the tape drive into variable block size mode.  I call this program from my /etc/rc.local file, so the tape drive is set up correctly whenever I start  my Linux system.  With this simple fix, I find I can read tapes from other Unix boxes with no problem.

The solution is...
here in this gzipp'ed tar file.  This is really only a tiny program -- it's figuring out what's wrong in the first place that's difficult!  Just download the file and type the following:

1) gzip --de tapefix.tar.gz
2) tar xvf tapefix.tar
3) make

There are two programs included.
One, called 'query', just reads some status information from your tape drive. You use it by giving a single argument, the name of the SCSI tape device.  For example:

./query /dev/st0

for the first SCSI tape device.  (If you don't have any file like "/dev/st0", then read the man page for st again -- you'll have to "mknod" the st devices first thing.)

For our purposes, the thing of interest is the "current block size".  If is is set to anything except zero, then you are NOT working in variable block size mode.  (If it is already set to zero then you are already in variable block size mode, and if you are having problems with reading tapes, then it must be some other problem than that).

The other program, called "setvarblock", just sets the tape device supplied as the only command line argument to variable block size mode.  For example:

./setvarblock /dev/st0

will do it for the first SCSI tape device.

An Alternative
I find the 'query' program useful for diagnosing this problem, and the 'setvarblock' program is useful for seeing how to manipulate the tape device.  But you don't have to go this route -- an option to the standard 'mt' command can set the block size to zero as well.  Just do, for example:

mt -f /dev/st0 setblk 0

I don't know if you can query the tape device this way (it doesn't seem to work on my system), but if you don't want to download the programs above this is a good alternative for at least setting the block size to variable.

There aren't a lot, besides the fact that this solution might not work for you, even though it works for me.  I generally do NOT run these programs as root.  I expect having write permissions to the tape device is sufficient.

Sometimes my tape drive seems to stop working, and when I do a "query", the block size has been set to some other value.  Rerunning the "setvarblock" program fixes it.  Your experiences may be different.

David W. Pierce
Scripps Institution of Oceanography
Last Updated 2000-12-15