Storage‎ > ‎Storage-tape‎ > ‎

Linux mt - control magnetic tape drive operation

Thank you for visiting this page, this page has been update in another link Linux mt control magnetic tape drive operation
       mt - control magnetic tape drive operation

SYNOPSIS
       mt [-h] [-f device] operation [count] [arguments...]

DESCRIPTION
       This  manual  page  documents  the tape control program mt.  mt performs the given operation, which must be one of the tape operations listed below, on a tape drive. The commands can also be listed by running the program with the -h option. The version of mt is printed with the -v or --version option. The path of the tape device on which to operate can be given with the -f or -t option.  If neither of
       those options is given, and the environment variable TAPE is set, it is used.   Otherwise,  a  default  device  defined  in  the  file /usr/include/sys/mtio.h is used.

       Some  operations optionally take an argument or repeat count, which can be given after the operation name and defaults to 1. The postfix k , M , or G can be used to give counts in units of 1024, 1024 * 1024, or 1024 * 1024 * 1024, respectively.

Usage:
# mt -h
usage: mt [-v] [--version] [-h] [ -f device ] command [ count ]
commands: weof, wset, eof, fsf, fsfm, bsf, bsfm, fsr, bsr, fss, bss, rewind,
          offline, rewoffl, eject, retension, eod, seod, seek, tell, status,
          erase, setblk, lock, unlock, load, compression, setdensity,
          drvbuffer, stwrthreshold, stoptions, stsetoptions, stclearoptions,
          defblksize, defdensity, defdrvbuffer, defcompression, stsetcln,
          sttimeout, stlongtimeout, densities, setpartition, mkpartition,
          partseek, asf, stshowopt.

Time for examples yet? not really, I'd like to have some introduction about tape devices, skip it if you know it.
Basically, there are two types of scsi tape devices created by SCSI tape driver, st and nst devices
       Devices are typically created by:

           mknod -m 666 /dev/st0 c 9 0
           mknod -m 666 /dev/st0l c 9 32
           mknod -m 666 /dev/st0m c 9 64
           mknod -m 666 /dev/st0a c 9 96
           mknod -m 666 /dev/nst0 c 9 128
           mknod -m 666 /dev/nst0l c 9 160
           mknod -m 666 /dev/nst0m c 9 192
           mknod -m 666 /dev/nst0a c 9 224
Here is the description from st driver manual

       The  st  driver provides the interface to a variety of SCSI tape devices.  Currently, the driver takes control of all detected devices
of type “sequential-access”.  The st driver uses major device number 9.

       Each device uses eight minor device numbers.  The lowermost five bits in the minor numbers are assigned sequentially in the  order  of detection.   In  the  2.6 kernel, the bits above the eight lowermost bits are concatenated to the five lowermost bits to form the tape
       number.  The minor numbers can be grouped into two sets of four numbers: the principal (auto-rewind) minor device numbers, n, and  the “no-rewind”  device  numbers, (n + 128).  Devices opened using the principal device number will be sent a REWIND command when they are
       closed.  Devices opened using the “no-rewind” device number will not.  (Note that using an auto-rewind device for positioning the tape with,  for instance, mt does not lead to the desired result: the tape is rewound after the mt command and the next command starts from the beginning of the tape).

Keep it simple:
/dev/st0 is an auto rewind tape device, tape will be rewinded when the device closed, thus, it's good for single write per tape volume or single file for multiple tape volumes.
/dev/nst0 is a non auto rewind tape device, single or multiple writes can be writeten to this tape.
Here are some examples:
#mt -f /dev/fctd51 rewind
#tar -cf /dev/fctd51 /usr/pgsql-9.1/lib
tar: Removing leading `/' from member names
#mt -f /dev/fctd51 tell
At block 823.
#mt -f /dev/fctd51 status
SCSI 2 tape drive:
File number=1, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x58 (no translation).
Soft error count since last status=0
General status bits on (81010000):
 EOF ONLINE IM_REP_EN
#mt -f /dev/fctd51 rewind
#tar -tvf /dev/fctd51
drwxr-xr-x root/root         0 2013-05-10 16:29 usr/pgsql-9.1/lib/
-rwxr-xr-x root/root      7768 2013-04-02 09:26 usr/pgsql-9.1/lib/pg_upgrade_support.so
...
-rwxr-xr-x root/root      9616 2013-04-02 09:25 usr/pgsql-9.1/lib/utf8_and_cyrillic.so
#mt -f /dev/fctd51 status
SCSI 2 tape drive:
File number=0, block number=822, partition=0.
Tape block size 0 bytes. Density code 0x58 (no translation).
Soft error count since last status=0
General status bits on (1010000):
 ONLINE IM_REP_EN
#mt -f /dev/fctd51 tell
At block 822.
#mt -f /dev/fcnst51 fsf 1
/dev/fcnst51: No such file or directory
#mt -f /dev/fctd51 fsf 1
#mt -f /dev/fctd51 status
SCSI 2 tape drive:
File number=1, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x58 (no translation).
Soft error count since last status=0
General status bits on (81010000):
 EOF ONLINE IM_REP_EN
#mt -f /dev/fctd51 tell
At block 823.

As you can see seek/tell works with block addressing, while fsf/fsr/bsf etc.. work with file mark addressing. Nothing will go wrong on same machine, but if you are doing tape operation in a cluster environment. file marker addressing doesn't reflect tape real position, for example, if you move a tape to the second file, but the other node won't know by file marker addressing, so you'd need to enable global block addressing(I'll discuss this in stinit article).

Another set ot commands, show you how earse works with positioning.

#mt -f /dev/fctd51 seek 500
#mt -f /dev/fctd51 erase
/dev/fctd51: Input/output error
#mt -f /dev/fctd51 rewind
#tar tvf /dev/fctd51
drwxr-xr-x root/root         0 2013-05-10 16:29 usr/pgsql-9.1/lib/
-rwxr-xr-x root/root      7768 2013-04-02 09:26 usr/pgsql-9.1/lib/pg_upgrade_support.so
drwxr-xr-x root/root         0 2013-05-10 16:29 usr/pgsql-9.1/lib/pgxs/
drwxr-xr-x root/root         0 2013-05-10 16:29 usr/pgsql-9.1/lib/pgxs/config/
-rwxr-xr-x root/root     13901 2013-04-02 09:23 usr/pgsql-9.1/lib/pgxs/config/install-sh
...
#mt -f /dev/fctd51 rewind
#mt -f /dev/fctd51 erase
#tar tvf /dev/fctd51
tar: /dev/fctd51: Cannot read: Input/output error
tar: At beginning of tape, quitting now
tar: Error is not recoverable: exiting now
#mt -f /dev/fctd51 status
SCSI 2 tape drive:
File number=0, block number=-1, partition=0.
Tape block size 0 bytes. Density code 0x58 (no translation).
Soft error count since last status=0
General status bits on (1010000):
 ONLINE IM_REP_EN
#mt -f /dev/fctd51 seek 500
/dev/fctd51: Input/output error

Another one
#mt -f /dev/fctd51 rewind
#tar -cf /dev/fctd51 /usr/pgsql-9.1/lib
tar: Removing leading `/' from member names
#mt -f /dev/fctd51 rewind
#mt -f /dev/fctd51 eof
#mt -f /dev/fctd51 status
SCSI 2 tape drive:
File number=1, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x58 (no translation).
Soft error count since last status=0
General status bits on (81010000):
 EOF ONLINE IM_REP_EN
#mt -f /dev/fctd51 status
SCSI 2 tape drive:
File number=1, block number=0, partition=0.
Tape block size 0 bytes. Density code 0x58 (no translation).
Soft error count since last status=0
General status bits on (81010000):
 EOF ONLINE IM_REP_EN
#mt -f /dev/fctd51 tell
At block 1.

One more
mt -f /dev/fctd51 eof
#tar -cf /dev/fctd51 /usr/pgsql-9.1/bin
tar: Removing leading `/' from member names
#mt -f /dev/fctd51 tell
At block 760.
mt -f /dev/fctd51 eof
#mt -f /dev/fctd51 tell
At block 761.

I'll discuss more about setoptions in another aritcle together with stinit, stay tunned.


Comments