Home / Alt manpages / mt-gnu(1)

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

Check and Position a Tape Safely with GNU mt

GNU mt can rewind or erase a tape that another backup job still has open, so picking the right device matters more than it looks. This covers identifying the command, selecting a device explicitly, reading status, and positioning the tape for a later archive step. It uses GNU cpio 2.15, packaged here as cpio 2.15+dfsg-1ubuntu2.1. Allow about fifteen minutes, plus time 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 here are ordinary commands. Reading or moving a drive may still need permission on the device, so use sudo only when 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 trusting any example:

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

That version line is the useful checkpoint. If another implementation sits earlier in your PATH, read its manual before relying on GNU-specific options such as --rsh-command.

2. Choose the device before touching the tape

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

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

That assignment sets a shell variable without exporting it. The explicit --file argument keeps the 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 missing 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, but elevated privileges do not make a wrong device safe.

3. Read status before positioning anything

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

$ mt --file="$TAPE" status

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

4. Move to a known file boundary

Warning

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

$ mt --file="$TAPE" rewind
$ printf 'mt exit status: %s\n' "$?"
mt exit status: 0
  • Exit status 0. The operation succeeded.
  • Exit status 1. The operation or device name was invalid.
  • Exit status 2. The operation failed.

There is no general undo for a movement; recovery means issuing another deliberate movement after checking the current position.

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

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

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

5. Reach the end only when appending

eom spaces to the end of the recorded media so files can be appended. It is not a harmless inspection command, and it may take time on a large tape. Use it only after confirming 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 another job is using. eom does not itself append anything; a later writer does 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 status check:

$ mt --file="$TAPE" offline

Use it only when nothing needs the tape and you are ready for the media to be unloaded. Recovery is to reinsert or reload the tape per the drive's instructions, then run status again.

Warning

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

7. Diagnose failures without guessing

Keep the 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.

Tip

For 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 any movement command.

Done means

  • Version confirmed. You know mt is GNU cpio 2.15, or checked the version actually installed.
  • Right device selected. The intended character device was chosen explicitly with --file, and its permissions checked.
  • Status checked either side. status was run before and after any deliberate movement.
  • Movement understood. You know rewind, eom and offline all change the drive position.
  • Erase treated as final. erase was not used unless the tape's contents were explicitly approved for irreversible destruction.