LinuxCommandLibrary

mt

Control magnetic tape drives

TLDR

Check the status of a tape drive

$ mt -f [/dev/nstX] status
copy

Rewind the tape to beginning
$ mt -f [/dev/nstX] rewind
copy

Move forward a given files, then position the tape on first block of next file
$ mt -f [/dev/nstX] fsf [count]
copy

Rewind the tape, then position the tape at beginning of the given file
$ mt -f [/dev/nstX] asf [count]
copy

Position the tape at the end of valid data
$ mt -f [/dev/nstX] eod
copy

Rewind the tape and unload/eject it
$ mt -f [/dev/nstX] eject
copy

Write EOF (End-of-file) mark at the current position
$ mt -f [/dev/nstX] eof
copy

SYNOPSIS

mt [-f device] operation [count]

PARAMETERS

device
    The path to the tape device file (e.g., /dev/st0, /dev/nst0). If omitted, mt typically uses the environment variable TAPE or a system default.

operation
    The mandatory action to perform on the tape drive.

count
    An optional integer argument for operations that can be repeated (e.g., fsf, bsf) to specify the number of times to perform the operation.

--help
    Displays help information and exits.

--version
    Displays version information and exits.

rewind
    Rewinds the tape to the beginning of the tape (BOT).

offline, rewoffl
    Rewinds the tape and takes the drive offline, making it ready for media change.

eject
    Ejects the tape from the drive, if supported by the hardware.

fsf count
    Spaces forward count filemarks (tape marks). Use count=1 to skip the current file.

bsf count
    Spaces backward count filemarks. Leaves the tape positioned at the beginning of the file skipped over.

fsr count
    Spaces forward count records (blocks). Useful for navigating within a single file.

bsr count
    Spaces backward count records. Useful for navigating within a single file.

retension
    Winds the tape to the end, then rewinds it, which helps to improve tape tension and reliability, especially for older tapes.

status
    Displays the current status of the tape drive, including information like file number, block number, and tape flags.

erase
    Erases the entire tape by writing zeros over its length. This can be a very time-consuming operation.

weof count
    Writes count end-of-file marks (filemarks) to the tape. A filemark separates files on the tape.

seek block
    Seeks to the specified block number on the tape. Requires hardware support and may not be available on all drives.

tell
    Reports the current logical block number on the tape. Useful in conjunction with the seek operation.

DESCRIPTION

The mt (magnetic tape) command is a utility used for controlling the operations of magnetic tape drives. It allows users to perform various actions such as rewinding, ejecting, erasing, and spacing the tape. While less common in modern desktop environments, mt remains crucial in enterprise backup systems, archival solutions, and environments relying on physical tape media for large-scale data storage.

It interacts directly with the tape device file (e.g., /dev/st0 or /dev/nst0), providing low-level control over tape positioning, end-of-file markers, and drive status. Its primary use cases involve preparing tapes for backup, verifying tape integrity, and navigating through archived data, making it an indispensable tool for tape library management.

CAVEATS

mt requires direct access to tape hardware, which might involve specific user permissions. Device names (e.g., /dev/st0, /dev/nst0) are crucial; /dev/nstN (no rewind on close) is generally preferred for backup applications to avoid accidental rewinds. Some operations like erase or retension can take a very long time, and errors often indicate hardware issues, incorrect tape insertion, or unsupported operations for the specific drive model.

TAPE DEVICES

Tape devices often come in two forms: a 'rewinding' device (e.g., /dev/st0) which automatically rewinds the tape to the beginning when the device is closed, and a 'no-rewind' device (e.g., /dev/nst0) which leaves the tape at its current position upon closing. Using the no-rewind variant is generally preferred for backup software to avoid accidental rewinds between operations or when multiple files are stored sequentially on a single tape.

RETURN STATUS

The mt command exits with a status of 0 on success, and a non-zero status on failure. A non-zero exit status usually indicates an error, which could be due to hardware issues, an incorrect device path, an unsupported operation for the specific drive, or permission problems.

HISTORY

mt has been a standard Unix utility since early versions, reflecting the historical importance of magnetic tapes as primary storage and backup media. Its fundamental functionality has remained largely consistent over decades, adapting to new tape technologies like QIC (Quarter-Inch Cartridge), DAT (Digital Audio Tape), and particularly LTO (Linear Tape-Open), which became dominant in enterprise and archival storage due to their high capacity, reliability, and cost-effectiveness. While hard drives and cloud storage have superseded tapes for many everyday applications, mt continues to be relevant for cold storage, long-term archival, and large-scale data transfer where physical media are still utilized.

SEE ALSO

tar(1), dd(1), cpio(1), st(4), lsscsi(8)

Copied to clipboard