How to install and test a tape drive using Linux

Version 1

    Note: it is suggested that these steps be attempted as Super User to ensure the correct rights are available. Use the command 'su' to login as Super User.

    Example:

    [ovrluser@localhost ovrluser]$su
    Password:

    [root@localhost ovrluser]#

    For the examples below we have changed to the root directory. The command to change to the root directory is 'cd /'

    [root@localhost ovrluser]# cd /
    [root@localhost /]#

    Step #1 - Check to see what is currently seen on the SCSI bus by using the following command.

    [root@localhost /]# cat /proc/scsi/scsi
    Attached devices:
    Host: scsi0 Channel: 00 Id: 00 Lun: 00
    Vendor: OPTORITE Model: CD-RW CW4802 Rev: 120E
    Type: CD-ROM ANSI SCSI revision: 02

    *Notes: looks like the only thing that can be seen on the SCSI bus is the IDE CD ROM. Linux talks to all IDE devices as if they were SCSI devices.

    Step #2 - Check to see what modules are loaded

    [root@localhost /]# /sbin/lsmod
    Module Size Used by Not tainted
    agpgart 44544 0 (unused)
    autofs 12148 0 (autoclean) (unused)
    3c59x 29360 1
    ipt_REJECT 3672 6 (autoclean)
    iptable_filter 2316 1 (autoclean)
    ip_tables 14488 2 [ipt_REJECT iptable_filter]
    sg 34572 0 (autoclean)
    sr_mod 16824 0 (autoclean)
    ide-scsi 11120 0
    scsi_mod 102616 3 [sg sr_mod ide-scsi]
    ide-cd 33436 0
    cdrom 31040 0 [sr_mod ide-cd]
    keybdev 2720 0 (unused)
    mousedev 5204 1
    hid 20772 0 (unused)
    input 5632 0 [keybdev mousedev hid]
    usb-ohci 20392 0 (unused)
    usbcore 73088 1 [hid usb-ohci]
    ext3 64704 2
    jbd 47828 2 [ext3]

    *Notes: Looks like the 'sg' module is loaded. This module is needed to talk to SCSI devices. However the SCSI card driver is missing. We are using an adaptec 2940U2W so the driver is 'aic7xxx'. If the driver is already loaded, try unloading 'sg' and re-loading 'sg'.

    Unload sg module:

    [root@localhost /]# /sbin/rmmod sg

    Load sg module:

    [root@localhost /]# /sbin/insmod sg
    Using /lib/modules/2.4.20-6/kernel/drivers/scsi/sg.o

    Load 'aic7xxx' driver

    [root@localhost /]# /sbin/modprobe aic7xxx

    *Notes: there can be a long pause between loading the SCSI card driver and the next OS prompt. See section 10 of the SCSI How-To doc, found here: http://www.linux.org/docs/ldp/howto/SCSI-Generic-HOWTO/index.html , for more info on drivers.

    Step #3 - Check for new devices

    [root@localhost /]# cat /proc/scsi/scsi
    Attached devices:
    Host: scsi0 Channel: 00 Id: 00 Lun: 00
    Vendor: OPTORITE Model: CD-RW CW4802 Rev: 120E
    Type: CD-ROM ANSI SCSI revision: 02
    Host: scsi2 Channel: 00 Id: 01 Lun: 00
    Vendor: SEAGATE Model: ULTRIUM06242-XXX Rev: 1603
    Type: Sequential-Access ANSI SCSI revision: 03
    Host: scsi2 Channel: 00 Id: 02 Lun: 00
    Vendor: SEAGATE Model: ULTRIUM06242-XXX Rev: 1603
    Type: Sequential-Access ANSI SCSI revision: 03
    Host: scsi2 Channel: 00 Id: 06 Lun: 00
    Vendor: OVERLAND Model: NEO Series Rev: 0425
    Type: Medium Changer ANSI SCSI revision: 02
    Host: scsi2 Channel: 00 Id: 11 Lun: 00
    Vendor: QUANTUM Model: SuperDLT1 Rev: 5050
    Type: Sequential-Access ANSI SCSI revision: 02
    Host: scsi2 Channel: 00 Id: 13 Lun: 00
    Vendor: OVERLAND Model: NEO Series Rev: 0425
    Type: Medium Changer ANSI SCSI revision: 02

    Step #4 - Check to ensure communication using 'mt' command
    Note: You must have a tape loaded into the tape drive to receive
    a positive response from the mt status command.

    [root@localhost /]# 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

    [root@localhost /]# mt -f /dev/st1 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

    [root@localhost /]# mt -f /dev/st2 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

    [root@localhost /]# mt -f /dev/st3 status
    /dev/st3: No such device or address

    [root@localhost /]# mt -f /dev/sg0 status
    /dev/sg0: Operation not permitted

    [root@localhost /]# mt -f /dev/nst0 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

    *Notes: You can see three tape drives listed above form the cat /proc/scsi/scsi command. Normally tape drives are call st (ie. st0). 'st' means SCSI Tape. Sometimes devices are called sg (ie sg0), they can also be called nst (ie nst0). 'nst' usually refers to a no rewind tape drive. The number after the identifier refers to the device number.

    st0 = 1st device listed in /proc/scsi/scsi
    st1 = 2nd device listed in /proc/scsi/scsi
    st2 = 3rd device listed in /proc/scsi/scsi
    st3 = 4th device listed in /proc/scsi/scsi
    etc...

    The above example shows the results of different queries.

    Step #5 - Use tar to create a small test backup

    Step 5a - Manually load a blank or reusable tape into the tape drive.

    Step 5b - Verify connection.

    [root@localhost /]# mt -f /dev/st0 status
    SCSI 2 tape drive:
    File number=0, block number=0, partition=0.
    Tape block size 512 bytes. Density code 0x0 (default).
    Soft error count since last status=0
    General status bits on (41010000):
    BOT ONLINE IM_REP_EN

    Step 5c - Rewind the tape to the beginning

    [root@localhost /]# mt -f /dev/st0 rewind

    Step 5d - Use 'tar' to backup to tape.

    [root@localhost /]# tar -cvf /dev/nst0 var/log
    var/log/
    var/log/messages
    var/log/lastlog
    var/log/secure
    var/log/maillog
    var/log/spooler
    var/log/wtmp
    var/log/vbox/
    var/log/httpd/
    var/log/squid/
    var/log/samba/
    var/log/cups/
    var/log/cups/error_log
    var/log/cups/access_log
    var/log/scrollkeeper.log
    var/log/gdm/
    var/log/gdm/:0.log
    var/log/gdm/:0.log.1
    var/log/gdm/:0.log.2
    var/log/gdm/:0.log.3
    var/log/gdm/:0.log.4
    var/log/canna/
    var/log/fax/
    var/log/news/
    var/log/news/OLD/
    var/log/news/news.notice
    var/log/news/news.crit
    var/log/news/news.err
    var/log/iptraf/
    var/log/iptraf/rvnamed.log
    var/log/mysqld.log
    var/log/mailman/
    var/log/mailman/error
    var/log/pgsql
    var/log/privoxy/
    var/log/sa/
    var/log/sa/sa22
    var/log/sa/sa23
    var/log/sa/sa24
    var/log/sa/sa26
    var/log/sa/sa27
    var/log/uucp/
    var/log/uucp/Log
    var/log/uucp/Stats
    var/log/uucp/Debug
    var/log/zebra/
    var/log/dmesg
    var/log/ksyms.0
    var/log/cron
    var/log/boot.log
    var/log/XFree86.1.log
    var/log/XFree86.0.log
    var/log/ksyms.1
    var/log/XFree86.0.log.old
    var/log/ksyms.2
    var/log/ksyms.3
    var/log/rpmpkgs
    var/log/ksyms.4
    var/log/ksyms.5
    var/log/ksyms.6

    *Notes - 'tar' means Tape ARchive. It is a UNIX command that has been around for a long time. the rest of the command line breaks down as follows:
    -c = create
    v = verbose mode
    f = target (in this case we want to send the data to /dev/st0
    var/log = the source data directory. This directory was chosen because it is usually pretty small.

    Step #6 - Rewind to the Beginning Of the Tape (BOT)

    [root@localhost /]# mt -f /dev/st0 rewind

    Step #7 - Verify data was written to tape

    [root@localhost /]# tar -tvf /dev/st0
    drwxr-xr-x root/root 0 2004-11-27 07:33:33 var/log/
    -rw------- root/root 342482 2004-11-27 09:50:06 var/log/messages
    -r-------- root/root 19136220 2004-11-27 09:47:57 var/log/lastlog
    -rw------- root/root 3119 2004-11-27 09:47:51 var/log/secure
    -rw------- root/root 4651 2004-11-27 06:42:18 var/log/maillog
    -rw------- root/root 0 2004-11-21 18:52:44 var/log/spooler
    -rw-rw-r-- root/utmp 304896 2004-11-27 09:47:57 var/log/wtmp
    drwxr-xr-x root/root 0 2003-02-03 16:13:36 var/log/vbox/
    drwx------ root/root 0 2003-02-25 02:07:04 var/log/httpd/
    drwxr-x--- squid/squid 0 2003-01-24 23:19:10 var/log/squid/
    drwx------ root/root 0 2003-02-24 23:05:55 var/log/samba/
    drwxr-xr-x lp/sys 0 2004-11-22 10:24:21 var/log/cups/
    -rw-r--r-- lp/sys 1967 2004-11-22 12:05:14 var/log/cups/error_log
    -rw-r--r-- lp/sys 77625 2004-11-22 12:04:59 var/log/cups/access_log
    -rw-r--r-- root/root 15699 2004-11-21 20:57:19 var/log/scrollkeeper.log
    drwxr-xr-x root/root 0 2004-11-27 07:33:33 var/log/gdm/
    -rw-r--r-- root/root 1247 2004-11-27 07:33:37 var/log/gdm/:0.log
    -rw-r--r-- root/root 1247 2004-11-27 05:28:13 var/log/gdm/:0.log.1
    -rw-r--r-- root/root 4367 2004-11-26 14:25:58 var/log/gdm/:0.log.2
    -rw-r--r-- root/root 2183 2004-11-26 11:11:11 var/log/gdm/:0.log.3
    -rw-r--r-- root/root 1247 2004-11-26 10:30:50 var/log/gdm/:0.log.4
    drwxr-xr-x bin/bin 0 2003-02-04 01:32:08 var/log/canna/
    drwxr-xr-x root/root 0 2003-01-24 15:39:27 var/log/fax/
    drwxr-xr-x news/news 0 2004-11-21 20:24:57 var/log/news/
    drwxr-xr-x news/news 0 2003-01-26 07:05:58 var/log/news/OLD/
    -rw-rw-r-- news/news 0 2004-11-21 20:24:57 var/log/news/news.notice
    -rw-rw-r-- news/news 0 2004-11-21 20:24:57 var/log/news/news.crit
    -rw-rw-r-- news/news 0 2004-11-21 20:24:57 var/log/news/news.err
    drwx------ root/root 0 2004-11-21 20:25:01 var/log/iptraf/
    -rw-r--r-- root/root 0 2003-01-24 19:32:41 var/log/iptraf/rvnamed.log
    -rw-r--r-- root/root 0 2004-11-21 20:42:09 var/log/mysqld.log
    drwxrwsr-x root/mailman 0 2004-11-21 22:55:08 var/log/mailman/
    -rw-rw-r-- mailman/mailman 0 2004-11-21 22:55:08 var/log/mailman/error
    -rwx------ postgres/postgres 0 2004-11-21 20:50:48 var/log/pgsql
    drwxr-xr-x privoxy/privoxy 0 2003-02-12 04:53:27 var/log/privoxy/
    drwxr-xr-x root/root 0 2004-11-27 05:30:00 var/log/sa/
    -rw-r--r-- root/root 21525 2004-11-22 14:20:00 var/log/sa/sa22
    -rw-r--r-- root/root 43789 2004-11-23 14:00:01 var/log/sa/sa23
    -rw-r--r-- root/root 43173 2004-11-24 12:40:00 var/log/sa/sa24
    -rw-r--r-- root/root 22493 2004-11-26 14:20:00 var/log/sa/sa26
    -rw-r--r-- root/root 26365 2004-11-27 10:10:00 var/log/sa/sa27
    drwxr-xr-x uucp/uucp 0 2004-11-21 22:31:11 var/log/uucp/
    -rw-r--r-- uucp/uucp 0 2004-11-21 22:31:11 var/log/uucp/Log
    -rw-r--r-- uucp/uucp 0 2004-11-21 22:31:11 var/log/uucp/Stats
    -rw------- uucp/uucp 0 2004-11-21 22:31:11 var/log/uucp/Debug
    drwxr-x--- root/root 0 2003-02-22 18:48:10 var/log/zebra/
    -rw-r--r-- root/root 5248 2004-11-27 07:32:43 var/log/dmesg
    -rw-r--r-- root/root 62518 2004-11-27 07:32:43 var/log/ksyms.0
    -rw------- root/root 84387 2004-11-27 10:10:03 var/log/cron
    -rw------- root/root 51135 2004-11-27 07:33:29 var/log/boot.log
    -rw-r--r-- root/root 33136 2004-11-21 22:55:19 var/log/XFree86.1.log
    -rw-r--r-- root/root 33265 2004-11-27 08:13:40 var/log/XFree86.0.log
    -rw-r--r-- root/root 62518 2004-11-27 05:27:20 var/log/ksyms.1
    -rw-r--r-- root/root 33265 2004-11-27 06:08:16 var/log/XFree86.0.log.old
    -rw-r--r-- root/root 62518 2004-11-26 11:43:39 var/log/ksyms.2
    -rw-r--r-- root/root 62518 2004-11-26 10:36:06 var/log/ksyms.3
    -rw-r--r-- root/root 39982 2004-11-27 06:37:03 var/log/rpmpkgs
    -rw-r--r-- root/root 62518 2004-11-26 10:29:41 var/log/ksyms.4
    -rw-r--r-- root/root 62518 2004-11-26 10:24:21 var/log/ksyms.5
    -rw-r--r-- root/root 62518 2004-11-24 05:19:34 var/log/ksyms.6

    *Notes - Use tar again to verify the contents on the tape.
    -t = list the contents of an archive
    v = verbose mode
    f = f = target (in this case we want to read data from /dev/st0

    Other commands to try:

    dump

    [root@localhost ovrluser]# /sbin/dump -0 -f /dev/st0 /usr/src
    DUMP: Date of this level 0 dump: Wed Dec 15 14:22:08 2004
    DUMP: Dumping /dev/hda2 (/ (dir usr/src)) to /dev/st0
    DUMP: Added inode 8 to exclude list (journal inode)
    DUMP: Added inode 7 to exclude list (resize inode)
    DUMP: Label: /
    DUMP: mapping (Pass I) [regular files]
    DUMP: mapping (Pass II) [directories]
    DUMP: estimated 209873 tape blocks.
    DUMP: Volume 1 started with block 1 at: Wed Dec 15 14:22:10 2004
    DUMP: dumping (Pass III) [directories]
    DUMP: dumping (Pass IV) [regular files]
    DUMP: Closing /dev/st0
    DUMP: Volume 1 completed at: Wed Dec 15 14:27:13 2004
    DUMP: Volume 1 233510 tape blocks (228.04MB)
    DUMP: Volume 1 took 0:05:03
    DUMP: Volume 1 transfer rate: 770 kB/s
    DUMP: 233510 tape blocks (228.04MB) on 1 volume(s)
    DUMP: finished in 287 seconds, throughput 813 kBytes/sec
    DUMP: Date of this level 0 dump: Wed Dec 15 14:22:08 2004
    DUMP: Date this dump completed: Wed Dec 15 14:27:13 2004
    DUMP: Average transfer rate: 770 kB/s
    DUMP: DUMP IS DONE
    [root@localhost ovrluser]#