Chapter 15. Managing tape devices


A tape device is a magnetic tape where data is stored and accessed sequentially. Data is written to this tape device with the help of a tape drive. There is no need to create a file system in order to store data on a tape device. Tape drives can be connected to a host computer with various interfaces like, SCSI, FC, USB, SATA, and other interfaces.

15.1. Types of tape devices

The following is a list of the different types of tape devices:

  • /dev/st0 is a rewinding tape device.
  • /dev/nst0 is a non-rewinding tape device. Use non-rewinding devices for daily backups.

There are several advantages to using tape devices. They are cost efficient and stable. Tape devices are also resilient against data corruption and are suitable for data retention.

15.2. Installing tape drive management tool

Install the mt-st package for tape drive operations. Use the mt utility to control magnetic tape drive operations, and the st utility for SCSI tape driver.

Procedure

  • Install the mt-st package:

    # dnf install mt-st
    Copy to Clipboard

15.3. Tape commands

The following are the common mt commands:

Table 15.1. mt commands
CommandDescription

mt -f /dev/st0 status

Displays the status of the tape device.

mt -f /dev/st0 erase

Erases the entire tape.

mt -f /dev/nst0 rewind

Rewinds the tape device.

mt -f /dev/nst0 fsf n

Switches the tape head to the forward record. Here, n is an optional file count. If a file count is specified, tape head skips n records.

mt -f /dev/nst0 bsfm n

Switches the tape head to the previous record.

mt -f /dev/nst0 eod

Switches the tape head to the end of the data.

15.4. Writing to rewinding tape devices

A rewind tape device rewinds the tape after every operation. To back up data, you can use the tar command. By default, in tape devices the block size is 10 KB (bs=10k). You can set the TAPE environment variable using the export TAPE=/dev/st0 attribute. Use the -f device option instead, to specify the tape device file. This option is useful when you use more than one tape device.

Prerequisites

  1. You have installed the mt-st package. For more information, see Installing tape drive management tool.
  2. Load the tape drive:

    # mt -f /dev/st0 load
    Copy to Clipboard

Procedure

  1. Check the tape head:

    # mt -f /dev/st0 status
    
    SCSI 2 tape drive:
    File number=-1, block number=-1, partition=0.
    Tape block size 0 bytes. Density code 0x0 (default).
    Soft error count since last status=0
    General status bits on (50000):
     DR_OPEN IM_REP_EN
    Copy to Clipboard

    Here:

    • the current file number is -1.
    • the block number defines the tape head. By default, it is set to -1.
    • the block size 0 indicates that the tape device does not have a fixed block size.
    • the Soft error count indicates the number of encountered errors after executing the mt status command.
    • the General status bits explains the stats of the tape device.
    • DR_OPEN indicates that the door is open and the tape device is empty. IM_REP_EN is the immediate report mode.
  2. If the tape device is not empty, overwrite it:

    # tar -czf /dev/st0 _/source/directory
    Copy to Clipboard

    This command overwrites the data on a tape device with the content of /source/directory.

  3. Back up the /source/directory to the tape device:

    # tar -czf /dev/st0 _/source/directory
    tar: Removing leading `/' from member names
    /source/directory
    /source/directory/man_db.conf
    /source/directory/DIR_COLORS
    /source/directory/rsyslog.conf
    [...]
    Copy to Clipboard
  4. View the status of the tape device:

    # mt -f /dev/st0 status
    Copy to Clipboard

Verification

  • View the list of all files on the tape device:

    # tar -tzf /dev/st0
    /source/directory/
    /source/directory/man_db.conf
    /source/directory/DIR_COLORS
    /source/directory/rsyslog.conf
    [...]
    Copy to Clipboard

15.5. Writing to non-rewinding tape devices

A non-rewinding tape device leaves the tape in its current status, after completing the execution of a certain command. For example, after a backup, you could append more data to a non-rewinding tape device. You can also use it to avoid any unexpected rewinds.

Prerequisites

  1. You have installed the mt-st package. For more information, see Installing tape drive management tool.
  2. Load the tape drive:

    # mt -f /dev/nst0 load
    Copy to Clipboard

Procedure

  1. Check the tape head of the non-rewinding tape device /dev/nst0:

    # mt -f /dev/nst0 status
    Copy to Clipboard
  2. Specify the pointer at the head or at the end of the tape:

    # mt -f /dev/nst0 rewind
    Copy to Clipboard
  3. Append the data on the tape device:

    # mt -f /dev/nst0 eod
    # tar -czf /dev/nst0 /source/directory/
    Copy to Clipboard
  4. Back up the /source/directory/ to the tape device:

    # tar -czf /dev/nst0 /source/directory/
    tar: Removing leading `/' from member names
    /source/directory/
    /source/directory/man_db.conf
    /source/directory/DIR_COLORS
    /source/directory/rsyslog.conf
    [...]
    Copy to Clipboard
  5. View the status of the tape device:

    # mt -f /dev/nst0 status
    Copy to Clipboard

Verification

  • View the list of all files on the tape device:

    # tar -tzf /dev/nst0
    /source/directory/
    /source/directory/man_db.conf
    /source/directory/DIR_COLORS
    /source/directory/rsyslog.conf
    [...]
    Copy to Clipboard

15.6. Switching tape head in tape devices

You can switch the tape head in the tape device by using the eod option.

Prerequisites

  1. You have installed the mt-st package. For more information, see Installing tape drive management tool.
  2. Data is written to the tape device. Fore more information, see Writing to rewinding tape devices or Writing to non-rewinding tape devices.

Procedure

  • To view the current position of the tape pointer:

    # mt -f /dev/nst0 tell
    Copy to Clipboard
  • To switch the tape head, while appending the data to the tape devices:

    # mt -f /dev/nst0 eod
    Copy to Clipboard
  • To go to the previous record:

    # mt -f /dev/nst0 bsfm 1
    Copy to Clipboard
  • To go to the forward record:

    # mt -f /dev/nst0 fsf 1
    Copy to Clipboard

15.7. Restoring data from tape devices

You can restore data from a tape device by using the tar command.

Prerequisites

  1. You have installed the mt-st package. For more information, see Installing tape drive management tool.
  2. Data is written to the tape device. For more information, see Writing to rewinding tape devices or Writing to non-rewinding tape devices.

Procedure

  • For rewinding tape devices /dev/st0:

    • Restore the /source/directory/:

      # tar -xzf /dev/st0 /source/directory/
      Copy to Clipboard
  • For non-rewinding tape devices /dev/nst0:

    • Rewind the tape device:

      # mt -f /dev/nst0 rewind
      Copy to Clipboard
    • Restore the etc directory:

      # tar -xzf /dev/nst0 /source/directory/
      Copy to Clipboard

15.8. Erasing data from tape devices

You can erase data from a tape device by using the erase option.

Prerequisites

  1. You have installed the mt-st package. For more information, see Installing tape drive management tool.
  2. Data is written to the tape device. For more information, see Writing to rewinding tape devices or Writing to non-rewinding tape devices.

Procedure

  1. Erase data from the tape device:

    # mt -f /dev/st0 erase
    Copy to Clipboard
  2. Unload the tape device:

    # mt -f /dev/st0 offline
    Copy to Clipboard
Back to top
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust. Explore our recent updates.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Theme

© 2025 Red Hat