Home / Alt manpages / mt-gnu(1)

  • mt-gnu(1)
  • User command
  • linux

Safely check and position a tape with GNU mt

You will identify the GNU mt command, select a tape device explicitly, inspect its status, and position it for a later archive operation. The guide uses GNU cpio 2.15, installed here as package cpio 2.15+dfsg-1ubuntu2.1. Allow about fifteen minutes, plus the time needed to confirm the correct drive and tape.

You need a Linux shell and access to a tape drive represented by a character device. Most examples are ordinary commands. Reading or moving a drive may still need permission on the device, so use sudo only when the local device permissions require it. This guide does not create an archive or change a service.

1. Confirm which mt you have

The mt and mt-gnu manpages describe the same GNU implementation on this machine. Check the executable and its version before relying on examples:

$ command -v mt
/usr/bin/mt
$ mt --version
mt (GNU cpio) 2.15
Copyright (C) 2024 Free Software Foundation, Inc.

The version line is the useful checkpoint. If another implementation is first in your PATH, read that implementation's manual before using GNU-specific options such as --rsh-command.

2. Choose the device before touching the tape

GNU mt accepts a device with -f or --file. This option takes precedence over the TAPE environment variable. Use a real device path supplied by your host's tape documentation or administrator; do not guess between rewinding and non-rewinding device names.

$ TAPE=/dev/nst0
$ mt --file="$TAPE" status

The assignment sets a shell variable and does not export it. The explicit --file argument makes this command's target visible during review. A typical successful status report includes drive-specific state, density or block information, and file and block positions. Exact lines depend on the drive and kernel.

Checkpoint: verify the path without moving the tape:

$ ls -l "$TAPE"
$ test -c "$TAPE" && echo "character device"
character device

If the path is absent or is not a character device, stop and correct the device choice. If status reports permission denied, retrying with sudo mt --file="$TAPE" status may be appropriate. Elevated privileges do not make an incorrect device safe.

3. Read status before positioning

status is the safest useful operation because it asks the drive for information without requesting a movement. Run it with the same device selection that later commands will use:

$ mt --file="$TAPE" status

Do not script against a fixed status format. The manpage promises status information, but the fields are supplied by the tape unit. Record the output when investigating a backup or restore problem, then compare it with the expected tape position and drive documentation.

4. Move to a known file boundary

Tape movement is state-changing and can interrupt another process using the drive. Confirm that no backup, restore, or monitoring job has the device open before proceeding. The following command rewinds the selected tape:

$ mt --file="$TAPE" rewind
$ printf 'mt exit status: %s\n' "$?"
mt exit status: 0

Exit status 0 means the operation succeeded. Status 1 means the operation or device name was invalid; status 2 means the operation failed. The command has no general undo for a movement, so the recovery is to issue another deliberate movement after checking the current position.

From the beginning, fsf 1 spaces forward over one file and positions the tape on the first block of the next file:

$ mt --file="$TAPE" fsf 1
$ mt --file="$TAPE" status

Counts default to 1 when an operation accepts a count. Supplying the count explicitly makes a script easier to audit. asf 3 is an absolute move to file number 3: GNU mt implements it as rewind followed by forward spacing three files. That rewind is easy to miss, so do not use asf when another process may depend on the current position.

5. Reach the end only when appending

eom spaces to the end of the recorded media so that files can be appended. It is not a harmless inspection command and may take time on a large tape. Use it only after confirming that the existing archive may receive new data:

$ mt --file="$TAPE" eom
$ mt --file="$TAPE" status

Do not confuse eom with rewind, and do not run it as a pre-flight check on a tape that another job is using. The command does not itself append an archive; a later writer would do that. If the tape is write-protected or the drive cannot locate the end, inspect the returned status and drive diagnostics before trying again.

6. Unload or erase only after a deliberate check

offline and its alias rewoffl rewind the tape and, where supported, unload it. This is a drive operation, not a read-only status check:

$ mt --file="$TAPE" offline

Use it only when no process needs the tape and you are ready for the media to be unloaded. The practical recovery is to reinsert or reload the tape according to the drive's instructions, then run status again.

Warning

erase performs a long erase. Passing a count of 0 requests a short erase, and some devices do not support that mode. Erasure destroys recorded data and cannot be undone by mt. Do not copy this command into an automation script unless the tape has been explicitly approved for destruction.

7. Diagnose failures without guessing

Keep the command's exit status immediately after the operation:

$ mt --file="$TAPE" status
$ rc=$?
$ printf 'mt exit status: %s\n' "$rc"
mt exit status: 0

A non-zero result does not identify the cause by itself. Check the device path, permissions, whether another process owns the drive, and whether the tape is loaded. Then repeat the read-only checks. If you are using a remote device, GNU mt accepts a name starting with HOSTNAME:, optionally prefixed with user@; its documented default transport is /usr/bin/ssh or /usr/bin/rsh as applicable. Treat remote operation as a separate access and trust decision, and verify the remote host before sending a movement command.

Done means

  • You confirmed that mt is GNU cpio 2.15 or checked the version actually installed.
  • You selected the intended character device explicitly with --file and checked its permissions.
  • You ran status before and after any deliberate movement.
  • You understand that rewind, eom and offline change the drive position.
  • You did not use erase unless the tape's contents were approved for irreversible destruction.